-
Notifications
You must be signed in to change notification settings - Fork 5
/
Checkbox.js
137 lines (108 loc) · 2.96 KB
/
Checkbox.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import './CheckboxIcon.js';
import CustomElement from '../core/CustomElement.js';
import InputMixin from '../mixins/InputMixin.js';
import RippleMixin from '../mixins/RippleMixin.js';
import StateMixin from '../mixins/StateMixin.js';
import ThemableMixin from '../mixins/ThemableMixin.js';
import TouchTargetMixin from '../mixins/TouchTargetMixin.js';
export default CustomElement
.extend()
.mixin(ThemableMixin)
.mixin(StateMixin)
.mixin(RippleMixin)
.mixin(InputMixin)
.mixin(TouchTargetMixin)
.set({
stateLayer: true,
type: 'checkbox',
})
.observe({
icon: { value: 'check' },
indeterminateIcon: { value: 'check_indeterminate_small' },
})
.expressions({
_determinateIcon({ indeterminate, indeterminateIcon, icon }) {
return (indeterminate ? indeterminateIcon : icon);
},
_iconSelectedState({ checked, indeterminate }) {
return checked || indeterminate;
},
})
.html`
<div id=checkbox errored={erroredState} selected={checked}>
<mdw-checkbox-icon id=icon errored={erroredState} disabled={disabledState}
icon={_determinateIcon} selected={_iconSelectedState}>
</mdw-checkbox-icon>
</div>
<slot id=slot></slot>
`
.recompose(({ refs: { checkbox, state, rippleContainer } }) => {
checkbox.append(state, rippleContainer);
})
.css`
/* https://m3.material.io/components/checkbox/specs */
:host {
--mdw-ink: var(--mdw-color__on-primary);
--mdw-bg: var(--mdw-color__primary);
display: inline-grid;
align-items: baseline;
gap: 12px;
grid-auto-flow: column;
justify-content: flex-start;
cursor: pointer;
transition: none 100ms cubic-bezier(0.4, 0.0, 1, 1);
}
:host(:disabled) {
cursor: not-allowed;
opacity: 0.38;
}
:host([internals-disabled]) {
cursor: not-allowed;
opacity: 0.38;
}
:host(:empty) {
vertical-align: -11.5%;
line-height: 18px;
}
#control {
grid-column: 1/1;
cursor: inherit;
}
#state,
#ripple-container {
/* stylelint-disable-next-line liberty/use-logical-spec */
top: 50%;
/* stylelint-disable-next-line liberty/use-logical-spec */
left: 50%;
block-size: 40px;
inline-size: 40px;
transform: translateX(-50%) translateY(-50%);
border-radius: 50%;
}
#checkbox {
position: relative;
display: inline-flex;
grid-column: 1 / 1;
pointer-events: none;
transform: translateY(11.5%);
color: rgb(var(--mdw-color__on-surface));
}
#checkbox[selected] {
color: rgb(var(--mdw-bg));
}
#checkbox[disabled] {
color: rgb(var(--mdw-color__on-surface));
}
#checkbox[errored] {
color: rgb(var(--mdw-color__error));
}
:host(:empty) #checkbox {
transform: none;
}
#icon {
--mdw-ink: inherit;
--mdw-bg: inherit;
--disabled-opacity: 1;
}
`
.autoRegister('mdw-checkbox');