-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton.js
88 lines (73 loc) · 2.4 KB
/
button.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import ShadowElement, {html, template, css, adoptedStyleSheets, define, reflectBooleanProperties, reflectStringProperties} from '@cfware/shadow-element';
import {immediateBlockEvent} from '@cfware/event-blocker';
import '@cfware-app/icon';
class CFWareButton extends ShadowElement {
_setTabIndex() {
if (this.noTab) {
this.setAttribute('tabindex', -1);
} else if (this.disabled) {
this.removeAttribute('tabindex');
} else {
this.setAttribute('tabindex', 0);
}
}
constructor() {
super();
const clickKeys = new Set(['Enter', ' ']);
this.addEventListener('keypress', event => {
if (clickKeys.has(event.key)) {
this.click();
}
});
this.addEventListener('click', event => {
if (this.disabled) {
immediateBlockEvent(event);
}
}, {capture: true});
this.setAttribute('role', 'button');
this._setTabIndex();
}
static [adoptedStyleSheets] = [
css`
:host {
display: inline-block;
position: relative;
background: var(--background, inherit);
color: var(--color, #000c);
cursor: pointer;
outline: 0;
padding: .5em 0;
width: 2em;
text-align: center;
line-height: 1;
}
:host([spacer]) {
visibility: hidden;
}
:host([disabled]), :host([disabled]) * {
cursor: default;
}
:host(:not([disabled]):hover) {
background: var(--hover-background, inherit);
color: var(--hover-color, #005d90);
}
:host(:not([disabled]):focus) {
background: var(--focus-background, #bbf4);
color: var(--focus-color, inherit);
}
:host([disabled]) cfware-icon {
opacity: 0.25;
}
cfware-icon {
cursor: pointer;
}
`
];
get [template]() {
this._setTabIndex();
return html`<cfware-icon icon=${this.icon} />`;
}
}
reflectBooleanProperties(CFWareButton, ['disabled', 'noTab']);
reflectStringProperties(CFWareButton, {icon: ''});
CFWareButton[define]('cfware-button');