@decidables/decidables-elements 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +54 -0
- package/gulpfile.js +25 -0
- package/lib/decidablesElements.esm.js +4889 -0
- package/lib/decidablesElements.esm.js.map +1 -0
- package/lib/decidablesElements.esm.min.js +13 -0
- package/lib/decidablesElements.esm.min.js.map +1 -0
- package/lib/decidablesElements.umd.js +4907 -0
- package/lib/decidablesElements.umd.js.map +1 -0
- package/lib/decidablesElements.umd.min.js +13 -0
- package/lib/decidablesElements.umd.min.js.map +1 -0
- package/package.json +46 -0
- package/src/button.js +93 -0
- package/src/converter-array.js +15 -0
- package/src/converter-set.js +15 -0
- package/src/decidables-element.js +264 -0
- package/src/index.js +11 -0
- package/src/slider.js +333 -0
- package/src/spinner.js +149 -0
- package/src/switch.js +179 -0
- package/src/toggle-option.js +163 -0
- package/src/toggle.js +58 -0
- package/test/button.test.js +29 -0
- package/test/converter-array.test.js +14 -0
- package/test/converter-set.test.js +15 -0
- package/test/coverage/lcov-report/base.css +224 -0
- package/test/coverage/lcov-report/block-navigation.js +87 -0
- package/test/coverage/lcov-report/button.js.html +364 -0
- package/test/coverage/lcov-report/converter-array.js.html +130 -0
- package/test/coverage/lcov-report/converter-set.js.html +130 -0
- package/test/coverage/lcov-report/decidables-element.js.html +877 -0
- package/test/coverage/lcov-report/favicon.png +0 -0
- package/test/coverage/lcov-report/index.html +236 -0
- package/test/coverage/lcov-report/prettify.css +1 -0
- package/test/coverage/lcov-report/prettify.js +2 -0
- package/test/coverage/lcov-report/slider.js.html +1084 -0
- package/test/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/test/coverage/lcov-report/sorter.js +196 -0
- package/test/coverage/lcov-report/spinner.js.html +532 -0
- package/test/coverage/lcov-report/switch.js.html +622 -0
- package/test/coverage/lcov-report/toggle-option.js.html +574 -0
- package/test/coverage/lcov-report/toggle.js.html +259 -0
- package/test/coverage/lcov.info +1480 -0
- package/test/decidables-element.test.js +10 -0
- package/test/slider.test.js +64 -0
- package/test/spinner.test.js +55 -0
- package/test/switch.test.js +71 -0
- package/test/toggle-option.test.js +62 -0
- package/test/toggle.test.js +98 -0
package/src/slider.js
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
|
|
2
|
+
import {ifDefined} from 'lit/directives/if-defined.js'; /* eslint-disable-line import/extensions */
|
|
3
|
+
import {html, css, unsafeCSS} from 'lit';
|
|
4
|
+
|
|
5
|
+
import DecidablesElement from './decidables-element';
|
|
6
|
+
|
|
7
|
+
export default class DecidablesSlider extends DecidablesElement {
|
|
8
|
+
static get properties() {
|
|
9
|
+
return {
|
|
10
|
+
disabled: {
|
|
11
|
+
attribute: 'disabled',
|
|
12
|
+
type: Boolean,
|
|
13
|
+
reflect: true,
|
|
14
|
+
},
|
|
15
|
+
max: {
|
|
16
|
+
attribute: 'max',
|
|
17
|
+
type: Number,
|
|
18
|
+
reflect: true,
|
|
19
|
+
},
|
|
20
|
+
min: {
|
|
21
|
+
attribute: 'min',
|
|
22
|
+
type: Number,
|
|
23
|
+
reflect: true,
|
|
24
|
+
},
|
|
25
|
+
step: {
|
|
26
|
+
attribute: 'step',
|
|
27
|
+
type: Number,
|
|
28
|
+
reflect: true,
|
|
29
|
+
},
|
|
30
|
+
value: {
|
|
31
|
+
attribute: 'value',
|
|
32
|
+
type: Number,
|
|
33
|
+
reflect: true,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
constructor() {
|
|
39
|
+
super();
|
|
40
|
+
|
|
41
|
+
// Attributes
|
|
42
|
+
this.disabled = false;
|
|
43
|
+
this.max = undefined;
|
|
44
|
+
this.min = undefined;
|
|
45
|
+
this.step = undefined;
|
|
46
|
+
this.value = undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
changed(event) {
|
|
50
|
+
this.value = event.target.value;
|
|
51
|
+
this.dispatchEvent(new CustomEvent('change', {
|
|
52
|
+
detail: {
|
|
53
|
+
value: this.value,
|
|
54
|
+
},
|
|
55
|
+
bubbles: true,
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
inputted(event) {
|
|
60
|
+
this.value = event.target.value;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static get styles() {
|
|
64
|
+
return [
|
|
65
|
+
super.styles,
|
|
66
|
+
css`
|
|
67
|
+
:host {
|
|
68
|
+
---shadow-2-rotate: var(--shadow-2-rotate, ${unsafeCSS(this.cssBoxShadow(2, true, false))});
|
|
69
|
+
---shadow-4-rotate: var(--shadow-4-rotate, ${unsafeCSS(this.cssBoxShadow(4, true, false))});
|
|
70
|
+
---shadow-8-rotate: var(--shadow-8-rotate, ${unsafeCSS(this.cssBoxShadow(8, true, false))});
|
|
71
|
+
|
|
72
|
+
display: flex;
|
|
73
|
+
|
|
74
|
+
flex-direction: column;
|
|
75
|
+
|
|
76
|
+
align-items: center;
|
|
77
|
+
justify-content: center;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
label {
|
|
81
|
+
margin: 0.25rem 0.25rem 0;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.range {
|
|
85
|
+
display: inline-block;
|
|
86
|
+
|
|
87
|
+
width: 3.5rem;
|
|
88
|
+
height: 4.75rem;
|
|
89
|
+
margin: 0 0.25rem 0.25rem;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
decidables-spinner {
|
|
93
|
+
--decidables-spinner-input-width: 3.5rem;
|
|
94
|
+
|
|
95
|
+
margin: 0 0.25rem 0.25rem;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* Adapted from http://danielstern.ca/range.css/#/ */
|
|
99
|
+
/* Overall */
|
|
100
|
+
input[type=range] {
|
|
101
|
+
width: 4.75rem;
|
|
102
|
+
height: 3.5rem;
|
|
103
|
+
padding: 0;
|
|
104
|
+
margin: 0;
|
|
105
|
+
|
|
106
|
+
background-color: unset;
|
|
107
|
+
|
|
108
|
+
transform: rotate(-90deg);
|
|
109
|
+
transform-origin: 2.375rem 2.375rem;
|
|
110
|
+
|
|
111
|
+
/* stylelint-disable-next-line property-no-vendor-prefix */
|
|
112
|
+
-webkit-appearance: none;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
input[type=range]:enabled {
|
|
116
|
+
cursor: ns-resize;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
input[type=range]:focus {
|
|
120
|
+
outline: none;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
124
|
+
input[type=range]::-ms-tooltip {
|
|
125
|
+
display: none;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/* Track */
|
|
129
|
+
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
130
|
+
input[type=range]::-webkit-slider-runnable-track {
|
|
131
|
+
width: 100%;
|
|
132
|
+
height: 4px;
|
|
133
|
+
|
|
134
|
+
background: var(---color-element-disabled);
|
|
135
|
+
border: 0;
|
|
136
|
+
border-radius: 2px;
|
|
137
|
+
box-shadow: none;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
input[type=range]:focus::-webkit-slider-runnable-track {
|
|
141
|
+
background: var(---color-element-disabled);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
145
|
+
input[type=range]::-moz-range-track {
|
|
146
|
+
width: 100%;
|
|
147
|
+
height: 4px;
|
|
148
|
+
|
|
149
|
+
background: var(---color-element-disabled);
|
|
150
|
+
border: 0;
|
|
151
|
+
border-radius: 2px;
|
|
152
|
+
box-shadow: none;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
156
|
+
input[type=range]::-ms-track {
|
|
157
|
+
width: 100%;
|
|
158
|
+
height: 4px;
|
|
159
|
+
|
|
160
|
+
color: transparent;
|
|
161
|
+
|
|
162
|
+
background: transparent;
|
|
163
|
+
border-color: transparent;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
167
|
+
input[type=range]::-ms-fill-lower {
|
|
168
|
+
background: #cccccc;
|
|
169
|
+
/* background: var(---color-element-disabled); */
|
|
170
|
+
border: 0;
|
|
171
|
+
border-radius: 2px;
|
|
172
|
+
box-shadow: none;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
176
|
+
input[type=range]::-ms-fill-upper {
|
|
177
|
+
background: #cccccc;
|
|
178
|
+
/* background: var(---color-element-disabled); */
|
|
179
|
+
border: 0;
|
|
180
|
+
border-radius: 2px;
|
|
181
|
+
box-shadow: none;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
185
|
+
input[type=range]:focus::-ms-fill-lower {
|
|
186
|
+
background: var(---color-element-disabled);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
190
|
+
input[type=range]:focus::-ms-fill-upper {
|
|
191
|
+
background: var(---color-element-disabled);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/* Thumb */
|
|
195
|
+
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
196
|
+
input[type=range]::-webkit-slider-thumb {
|
|
197
|
+
width: 10px;
|
|
198
|
+
height: 20px;
|
|
199
|
+
margin-top: -8px;
|
|
200
|
+
|
|
201
|
+
border: 0;
|
|
202
|
+
border-radius: 4px;
|
|
203
|
+
|
|
204
|
+
/* stylelint-disable-next-line property-no-vendor-prefix */
|
|
205
|
+
-webkit-appearance: none;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
input[type=range]:disabled::-webkit-slider-thumb {
|
|
209
|
+
background: var(---color-element-disabled);
|
|
210
|
+
box-shadow: none;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
input[type=range]:enabled::-webkit-slider-thumb {
|
|
214
|
+
background: var(---color-element-enabled);
|
|
215
|
+
box-shadow: var(---shadow-2-rotate);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
input[type=range]:enabled:hover::-webkit-slider-thumb {
|
|
219
|
+
box-shadow: var(---shadow-4-rotate);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
input[type=range]:enabled:active::-webkit-slider-thumb {
|
|
223
|
+
box-shadow: var(---shadow-8-rotate);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
:host(.keyboard) input[type=range]:enabled:focus::-webkit-slider-thumb {
|
|
227
|
+
box-shadow: var(---shadow-4-rotate);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
:host(.keyboard) input[type=range]:focus:active::-webkit-slider-thumb {
|
|
231
|
+
box-shadow: var(---shadow-8-rotate);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
235
|
+
input[type=range]::-moz-range-thumb {
|
|
236
|
+
width: 10px;
|
|
237
|
+
height: 20px;
|
|
238
|
+
|
|
239
|
+
border: 0;
|
|
240
|
+
border-radius: 4px;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
244
|
+
input[type=range]:disabled::-moz-range-thumb {
|
|
245
|
+
background: var(---color-element-disabled);
|
|
246
|
+
box-shadow: none;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
250
|
+
input[type=range]:enabled::-moz-range-thumb {
|
|
251
|
+
background: var(---color-element-enabled);
|
|
252
|
+
box-shadow: var(---shadow-2-rotate);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
256
|
+
input[type=range]:enabled:hover::-moz-range-thumb {
|
|
257
|
+
box-shadow: var(---shadow-4-rotate);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
261
|
+
input[type=range]:enabled:active::-moz-range-thumb {
|
|
262
|
+
box-shadow: var(---shadow-8-rotate);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
:host(.keyboard) input[type=range]:enabled:focus::-moz-range-thumb {
|
|
266
|
+
box-shadow: var(---shadow-4-rotate);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
:host(.keyboard) input[type=range]:enabled:focus:active::-moz-range-thumb {
|
|
270
|
+
box-shadow: var(---shadow-8-rotate);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
274
|
+
input[type=range]::-ms-thumb {
|
|
275
|
+
width: 10px;
|
|
276
|
+
height: 20px;
|
|
277
|
+
margin-top: 0;
|
|
278
|
+
|
|
279
|
+
background: #999999;
|
|
280
|
+
/* background: var(---color-element-enabled); */
|
|
281
|
+
border: 0;
|
|
282
|
+
border-radius: 4px;
|
|
283
|
+
box-shadow: var(---shadow-2-rotate);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
287
|
+
input[type=range]:disabled::-ms-thumb {
|
|
288
|
+
background: var(---color-element-disabled);
|
|
289
|
+
box-shadow: none;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
293
|
+
input[type=range]:enabled::-ms-thumb {
|
|
294
|
+
background: var(---color-element-enabled);
|
|
295
|
+
box-shadow: var(---shadow-2-rotate);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
299
|
+
input[type=range]:enabled:hover::-ms-thumb {
|
|
300
|
+
box-shadow: var(---shadow-4-rotate);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
304
|
+
input[type=range]:enabled:active::-ms-thumb {
|
|
305
|
+
box-shadow: var(---shadow-8-rotate);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
309
|
+
:host(.keyboard) input[type=range]:enabled:focus::-ms-thumb {
|
|
310
|
+
box-shadow: var(---shadow-4-rotate);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
:host(.keyboard) input[type=range]:enabled:focus:active::-ms-thumb {
|
|
314
|
+
box-shadow: var(---shadow-8-rotate);
|
|
315
|
+
}
|
|
316
|
+
`,
|
|
317
|
+
];
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
render() {
|
|
321
|
+
return html`
|
|
322
|
+
<label for=${`${this.uniqueId}-slider`}>
|
|
323
|
+
<slot></slot>
|
|
324
|
+
</label>
|
|
325
|
+
<div class="range">
|
|
326
|
+
<input type="range" id=${`${this.uniqueId}-slider`} min=${ifDefined(this.min)} max=${ifDefined(this.max)} step=${ifDefined(this.step)} .value=${this.value} @change=${this.changed.bind(this)} @input=${this.inputted.bind(this)}>
|
|
327
|
+
</div>
|
|
328
|
+
<decidables-spinner min=${ifDefined(this.min)} max=${ifDefined(this.max)} step=${ifDefined(this.step)} .value=${this.value} @input=${this.inputted.bind(this)}></decidables-spinner>
|
|
329
|
+
`;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
customElements.define('decidables-slider', DecidablesSlider);
|
package/src/spinner.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
|
|
2
|
+
import {ifDefined} from 'lit/directives/if-defined.js'; /* eslint-disable-line import/extensions */
|
|
3
|
+
import {html, css} from 'lit';
|
|
4
|
+
|
|
5
|
+
import DecidablesElement from './decidables-element';
|
|
6
|
+
|
|
7
|
+
export default class DecidablesSpinner extends DecidablesElement {
|
|
8
|
+
static get properties() {
|
|
9
|
+
return {
|
|
10
|
+
disabled: {
|
|
11
|
+
attribute: 'disabled',
|
|
12
|
+
type: Boolean,
|
|
13
|
+
reflect: true,
|
|
14
|
+
},
|
|
15
|
+
max: {
|
|
16
|
+
attribute: 'max',
|
|
17
|
+
type: Number,
|
|
18
|
+
reflect: true,
|
|
19
|
+
},
|
|
20
|
+
min: {
|
|
21
|
+
attribute: 'min',
|
|
22
|
+
type: Number,
|
|
23
|
+
reflect: true,
|
|
24
|
+
},
|
|
25
|
+
step: {
|
|
26
|
+
attribute: 'step',
|
|
27
|
+
type: Number,
|
|
28
|
+
reflect: true,
|
|
29
|
+
},
|
|
30
|
+
value: {
|
|
31
|
+
attribute: 'value',
|
|
32
|
+
type: Number,
|
|
33
|
+
reflect: true,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
constructor() {
|
|
39
|
+
super();
|
|
40
|
+
|
|
41
|
+
// Attributes
|
|
42
|
+
this.disabled = false;
|
|
43
|
+
this.max = undefined;
|
|
44
|
+
this.min = undefined;
|
|
45
|
+
this.step = undefined;
|
|
46
|
+
this.value = undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
inputted(event) {
|
|
50
|
+
this.value = event.target.value;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static get styles() {
|
|
54
|
+
return [
|
|
55
|
+
super.styles,
|
|
56
|
+
css`
|
|
57
|
+
:host {
|
|
58
|
+
---decidables-spinner-font-size: var(--decidables-spinner-font-size, 1.125rem);
|
|
59
|
+
---decidables-spinner-input-width: var(--decidables-spinner-input-width, 4rem);
|
|
60
|
+
---decidables-spinner-prefix: var(--decidables-spinner-prefix, "");
|
|
61
|
+
|
|
62
|
+
display: block;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
label {
|
|
66
|
+
position: relative;
|
|
67
|
+
display: flex;
|
|
68
|
+
|
|
69
|
+
flex-direction: column;
|
|
70
|
+
|
|
71
|
+
align-items: center;
|
|
72
|
+
|
|
73
|
+
margin: 0;
|
|
74
|
+
|
|
75
|
+
font-size: 0.75rem;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
label::before {
|
|
79
|
+
position: absolute;
|
|
80
|
+
bottom: 1px;
|
|
81
|
+
left: calc(50% - var(---decidables-spinner-input-width) / 2 + 0.25rem);
|
|
82
|
+
|
|
83
|
+
font-size: var(---decidables-spinner-font-size);
|
|
84
|
+
line-height: normal;
|
|
85
|
+
|
|
86
|
+
content: var(---decidables-spinner-prefix);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
input[type=number] {
|
|
90
|
+
width: var(---decidables-spinner-input-width);
|
|
91
|
+
|
|
92
|
+
font-family: var(---font-family-base);
|
|
93
|
+
font-size: var(---decidables-spinner-font-size);
|
|
94
|
+
color: inherit;
|
|
95
|
+
text-align: right;
|
|
96
|
+
|
|
97
|
+
background: none;
|
|
98
|
+
border: 0;
|
|
99
|
+
border-radius: 0;
|
|
100
|
+
outline: none;
|
|
101
|
+
box-shadow: var(---shadow-2);
|
|
102
|
+
|
|
103
|
+
-webkit-appearance: none; /* stylelint-disable-line property-no-vendor-prefix */
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
input[type=number]:hover {
|
|
107
|
+
box-shadow: var(---shadow-4);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
input[type=number]:focus,
|
|
111
|
+
input[type=number]:active {
|
|
112
|
+
box-shadow: var(---shadow-8);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
input[type=number]:disabled {
|
|
116
|
+
color: var(---color-text);
|
|
117
|
+
|
|
118
|
+
border: 0;
|
|
119
|
+
box-shadow: none;
|
|
120
|
+
|
|
121
|
+
/* HACK: Use correct text color in Safari */
|
|
122
|
+
-webkit-opacity: 1;
|
|
123
|
+
/* HACK: Hide spinners in disabled input for Firefox and Safari */
|
|
124
|
+
-moz-appearance: textfield; /* stylelint-disable-line property-no-vendor-prefix */
|
|
125
|
+
/* HACK: Use correct text color in Safari */
|
|
126
|
+
-webkit-text-fill-color: var(---color-text);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/* HACK: Hide spinners in disabled input for Firefox and Safari */
|
|
130
|
+
input[type=number]:disabled::-webkit-outer-spin-button,
|
|
131
|
+
input[type=number]:disabled::-webkit-inner-spin-button {
|
|
132
|
+
margin: 0;
|
|
133
|
+
-webkit-appearance: none; /* stylelint-disable-line property-no-vendor-prefix */
|
|
134
|
+
}
|
|
135
|
+
`,
|
|
136
|
+
];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
render() {
|
|
140
|
+
return html`
|
|
141
|
+
<label>
|
|
142
|
+
<slot></slot>
|
|
143
|
+
<input ?disabled=${this.disabled} type="number" min=${ifDefined(this.min)} max=${ifDefined(this.max)} step=${ifDefined(this.step)} .value=${this.value} @input=${this.inputted.bind(this)}>
|
|
144
|
+
</label>
|
|
145
|
+
`;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
customElements.define('decidables-spinner', DecidablesSpinner);
|
package/src/switch.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
|
|
2
|
+
import {html, css} from 'lit';
|
|
3
|
+
|
|
4
|
+
import DecidablesElement from './decidables-element';
|
|
5
|
+
|
|
6
|
+
export default class DecidablesSwitch extends DecidablesElement {
|
|
7
|
+
static get properties() {
|
|
8
|
+
return {
|
|
9
|
+
checked: {
|
|
10
|
+
attribute: 'checked',
|
|
11
|
+
type: Boolean,
|
|
12
|
+
reflect: true,
|
|
13
|
+
},
|
|
14
|
+
disabled: {
|
|
15
|
+
attribute: 'disabled',
|
|
16
|
+
type: Boolean,
|
|
17
|
+
reflect: true,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
constructor() {
|
|
23
|
+
super();
|
|
24
|
+
|
|
25
|
+
// Attributes
|
|
26
|
+
this.checked = false;
|
|
27
|
+
this.disabled = false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
changed(event) {
|
|
31
|
+
this.checked = event.target.checked;
|
|
32
|
+
this.dispatchEvent(new CustomEvent('change', {
|
|
33
|
+
detail: {
|
|
34
|
+
checked: this.checked,
|
|
35
|
+
},
|
|
36
|
+
bubbles: true,
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static get styles() {
|
|
41
|
+
return [
|
|
42
|
+
super.styles,
|
|
43
|
+
css`
|
|
44
|
+
:host {
|
|
45
|
+
display: flex;
|
|
46
|
+
|
|
47
|
+
flex-direction: column;
|
|
48
|
+
|
|
49
|
+
align-items: center;
|
|
50
|
+
justify-content: center;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* Adapted from https://codepen.io/guuslieben/pen/YyPRVP */
|
|
54
|
+
input[type=checkbox] {
|
|
55
|
+
/* visuallyhidden: https://github.com/h5bp/html5-boilerplate/blob/master/dist/doc/css.md */
|
|
56
|
+
position: absolute;
|
|
57
|
+
|
|
58
|
+
width: 1px;
|
|
59
|
+
height: 1px;
|
|
60
|
+
padding: 0;
|
|
61
|
+
margin: -1px;
|
|
62
|
+
overflow: hidden;
|
|
63
|
+
clip: rect(0 0 0 0);
|
|
64
|
+
|
|
65
|
+
white-space: nowrap;
|
|
66
|
+
|
|
67
|
+
border: 0;
|
|
68
|
+
clip-path: inset(100%); /* May cause a performance issue: https://github.com/h5bp/html5-boilerplate/issues/2021 */
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
input[type=checkbox] + label {
|
|
72
|
+
order: 1;
|
|
73
|
+
|
|
74
|
+
margin: 0 0.25rem 0.25rem;
|
|
75
|
+
|
|
76
|
+
font-weight: 400;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
input[type=checkbox] + label + label {
|
|
80
|
+
position: relative;
|
|
81
|
+
|
|
82
|
+
min-width: 24px;
|
|
83
|
+
padding: 0 0 36px;
|
|
84
|
+
margin: 0.25rem 0.25rem 0;
|
|
85
|
+
|
|
86
|
+
font-weight: 400;
|
|
87
|
+
|
|
88
|
+
outline: none;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
input[type=checkbox] + label + label::before,
|
|
92
|
+
input[type=checkbox] + label + label::after {
|
|
93
|
+
position: absolute;
|
|
94
|
+
|
|
95
|
+
left: 50%;
|
|
96
|
+
|
|
97
|
+
margin: 0;
|
|
98
|
+
|
|
99
|
+
content: "";
|
|
100
|
+
|
|
101
|
+
outline: 0;
|
|
102
|
+
|
|
103
|
+
transition: all var(---transition-duration) ease;
|
|
104
|
+
transform: translate(-50%, 0);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
input[type=checkbox] + label + label::before {
|
|
108
|
+
bottom: 1px;
|
|
109
|
+
|
|
110
|
+
width: 8px;
|
|
111
|
+
height: 34px;
|
|
112
|
+
|
|
113
|
+
background-color: var(---color-element-disabled);
|
|
114
|
+
border-radius: 4px;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
input[type=checkbox] + label + label::after {
|
|
118
|
+
bottom: 0;
|
|
119
|
+
|
|
120
|
+
width: 18px;
|
|
121
|
+
height: 18px;
|
|
122
|
+
|
|
123
|
+
background-color: var(---color-element-enabled);
|
|
124
|
+
border-radius: 50%;
|
|
125
|
+
box-shadow: var(---shadow-2);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
input[type=checkbox]:checked + label + label::after {
|
|
129
|
+
transform: translate(-50%, -100%);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
input[type=checkbox]:disabled + label + label::after {
|
|
133
|
+
background-color: var(---color-element-disabled);
|
|
134
|
+
box-shadow: none;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
input[type=checkbox]:enabled + label,
|
|
138
|
+
input[type=checkbox]:enabled + label + label {
|
|
139
|
+
cursor: pointer;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
input[type=checkbox]:enabled + label:hover + label::after,
|
|
143
|
+
input[type=checkbox]:enabled + label + label:hover::after {
|
|
144
|
+
box-shadow: var(---shadow-4);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
input[type=checkbox]:enabled + label:active + label::after,
|
|
148
|
+
input[type=checkbox]:enabled + label + label:active::after {
|
|
149
|
+
box-shadow: var(---shadow-8);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/* stylelint-disable-next-line selector-max-compound-selectors */
|
|
153
|
+
:host(.keyboard) input[type=checkbox]:enabled:focus + label + label::after {
|
|
154
|
+
box-shadow: var(---shadow-4);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/* stylelint-disable-next-line selector-max-compound-selectors */
|
|
158
|
+
:host(.keyboard) input[type=checkbox]:enabled:focus + label + label:active::after,
|
|
159
|
+
:host(.keyboard) input[type=checkbox]:enabled:focus:active + label + label::after {
|
|
160
|
+
box-shadow: var(---shadow-8);
|
|
161
|
+
}
|
|
162
|
+
`,
|
|
163
|
+
];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
render() {
|
|
167
|
+
return html`
|
|
168
|
+
<input type="checkbox" id=${`${this.uniqueId}-checkbox`} ?checked=${this.checked} ?disabled=${this.disabled} @change=${this.changed.bind(this)}>
|
|
169
|
+
<label for=${`${this.uniqueId}-checkbox`}>
|
|
170
|
+
<slot name="off-label"></slot>
|
|
171
|
+
</label>
|
|
172
|
+
<label for=${`${this.uniqueId}-checkbox`}>
|
|
173
|
+
<slot></slot>
|
|
174
|
+
</label>
|
|
175
|
+
`;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
customElements.define('decidables-switch', DecidablesSwitch);
|