@spectrum-web-components/slider 0.14.0 → 0.14.2

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.
Files changed (51) hide show
  1. package/package.json +4 -4
  2. package/sp-slider-handle.dev.js +1 -0
  3. package/sp-slider-handle.dev.js.map +1 -1
  4. package/sp-slider-handle.js +1 -1
  5. package/sp-slider-handle.js.map +2 -2
  6. package/sp-slider.dev.js +1 -0
  7. package/sp-slider.dev.js.map +1 -1
  8. package/sp-slider.js +1 -1
  9. package/sp-slider.js.map +2 -2
  10. package/src/HandleController.dev.js +71 -17
  11. package/src/HandleController.dev.js.map +1 -1
  12. package/src/HandleController.js +1 -1
  13. package/src/HandleController.js.map +2 -2
  14. package/src/Slider.dev.js +18 -7
  15. package/src/Slider.dev.js.map +2 -2
  16. package/src/Slider.js +17 -17
  17. package/src/Slider.js.map +3 -3
  18. package/src/SliderHandle.dev.js +22 -12
  19. package/src/SliderHandle.dev.js.map +2 -2
  20. package/src/SliderHandle.js +1 -1
  21. package/src/SliderHandle.js.map +2 -2
  22. package/src/index.dev.js +1 -0
  23. package/src/index.dev.js.map +1 -1
  24. package/src/index.js +1 -1
  25. package/src/index.js.map +1 -1
  26. package/src/slider.css.dev.js +1 -0
  27. package/src/slider.css.dev.js.map +1 -1
  28. package/src/slider.css.js +1 -1
  29. package/src/slider.css.js.map +2 -2
  30. package/src/spectrum-slider.css.dev.js +1 -0
  31. package/src/spectrum-slider.css.dev.js.map +1 -1
  32. package/src/spectrum-slider.css.js +1 -1
  33. package/src/spectrum-slider.css.js.map +2 -2
  34. package/stories/slider.stories.js +414 -111
  35. package/stories/slider.stories.js.map +2 -2
  36. package/sync/sp-slider.dev.js +1 -0
  37. package/sync/sp-slider.dev.js.map +1 -1
  38. package/sync/sp-slider.js +1 -1
  39. package/sync/sp-slider.js.map +1 -1
  40. package/test/benchmark/test-basic.js +5 -1
  41. package/test/benchmark/test-basic.js.map +1 -1
  42. package/test/slider-editable-sync.test.js +149 -1
  43. package/test/slider-editable-sync.test.js.map +1 -1
  44. package/test/slider-editable.test.js +197 -1
  45. package/test/slider-editable.test.js.map +2 -2
  46. package/test/slider-handle-upgrade.test.js +12 -2
  47. package/test/slider-handle-upgrade.test.js.map +1 -1
  48. package/test/slider.test-vrt.js +4 -1
  49. package/test/slider.test-vrt.js.map +1 -1
  50. package/test/slider.test.js +920 -43
  51. package/test/slider.test.js.map +2 -2
@@ -1,82 +1,211 @@
1
- import{html as i}from"@spectrum-web-components/base";import"@spectrum-web-components/slider/sp-slider.js";import"@spectrum-web-components/slider/sp-slider-handle.js";import{variants as y}from"@spectrum-web-components/slider";import{spreadProps as t}from"../../../test/lit-helpers.js";export default{component:"sp-slider",title:"Slider",argTypes:{onInput:{action:"input"},onChange:{action:"change"},variant:{name:"Variant",description:"Determines the style of slider.",table:{type:{summary:"string"},defaultValue:{summary:void 0}},control:{type:"inline-radio",options:[void 0,...y]}},tickStep:{name:"Tick Step",description:"Tick spacing on slider.",table:{type:{summary:"number"},defaultValue:{summary:.1}},control:{type:"number"}},labelVisibility:{name:"Label Visibility",description:"The labels visibily available in the UI",table:{type:{summary:'"text" | "value" | "none" | undefined'},defaultValue:{summary:void 0}},control:{type:"text"}}},args:{variant:void 0,tickStep:.1,labelVisibility:void 0}};const s=({onInput:e,onChange:l})=>r=>{const{value:d}=r.target;e&&r.type==="input"?e(d.toString()):l&&r.type==="change"&&l(d.toString())},o=({onInput:e,onChange:l})=>r=>{const d=r.target;if(d.value!=null)if(typeof d.value=="object"){const u=JSON.stringify(d.value,null,2);e&&r.type==="input"?e(u):l&&r.type==="change"&&l(u)}else{const u=`${d.name}: ${d.value}`;e&&r.type==="input"?e(u):l&&r.type==="change"&&l(u)}};export const Default=(e={})=>i`
1
+ "use strict";
2
+ import { html } from "@spectrum-web-components/base";
3
+ import "@spectrum-web-components/slider/sp-slider.js";
4
+ import "@spectrum-web-components/slider/sp-slider-handle.js";
5
+ import {
6
+ variants
7
+ } from "@spectrum-web-components/slider";
8
+ import { spreadProps } from "../../../test/lit-helpers.js";
9
+ export default {
10
+ component: "sp-slider",
11
+ title: "Slider",
12
+ argTypes: {
13
+ onInput: { action: "input" },
14
+ onChange: { action: "change" },
15
+ variant: {
16
+ name: "Variant",
17
+ description: "Determines the style of slider.",
18
+ table: {
19
+ type: { summary: "string" },
20
+ defaultValue: { summary: void 0 }
21
+ },
22
+ control: {
23
+ type: "inline-radio",
24
+ options: [void 0, ...variants]
25
+ }
26
+ },
27
+ tickStep: {
28
+ name: "Tick Step",
29
+ description: "Tick spacing on slider.",
30
+ table: {
31
+ type: { summary: "number" },
32
+ defaultValue: { summary: 0.1 }
33
+ },
34
+ control: {
35
+ type: "number"
36
+ }
37
+ },
38
+ labelVisibility: {
39
+ name: "Label Visibility",
40
+ description: "The labels visibily available in the UI",
41
+ table: {
42
+ type: { summary: '"text" | "value" | "none" | undefined' },
43
+ defaultValue: { summary: void 0 }
44
+ },
45
+ control: {
46
+ type: "text"
47
+ }
48
+ }
49
+ },
50
+ args: {
51
+ variant: void 0,
52
+ tickStep: 0.1,
53
+ labelVisibility: void 0
54
+ }
55
+ };
56
+ const handleEvent = ({ onInput, onChange }) => (event) => {
57
+ const { value } = event.target;
58
+ if (onInput && event.type === "input") {
59
+ onInput(value.toString());
60
+ } else if (onChange && event.type === "change") {
61
+ onChange(value.toString());
62
+ }
63
+ };
64
+ const handleHandleEvent = ({ onInput, onChange }) => (event) => {
65
+ const target = event.target;
66
+ if (target.value != null) {
67
+ if (typeof target.value === "object") {
68
+ const value = JSON.stringify(target.value, null, 2);
69
+ if (onInput && event.type === "input") {
70
+ onInput(value);
71
+ } else if (onChange && event.type === "change") {
72
+ onChange(value);
73
+ }
74
+ } else {
75
+ const value = `${target.name}: ${target.value}`;
76
+ if (onInput && event.type === "input") {
77
+ onInput(value);
78
+ } else if (onChange && event.type === "change") {
79
+ onChange(value);
80
+ }
81
+ }
82
+ }
83
+ };
84
+ export const Default = (args = {}) => {
85
+ return html`
2
86
  <div style="width: 500px; margin: 12px 20px;">
3
87
  <sp-slider
4
88
  max="1"
5
89
  min="0"
6
90
  value=".5"
7
91
  step="0.01"
8
- @input=${s(e)}
9
- @change=${s(e)}
10
- .formatOptions=${{style:"percent"}}
11
- ...=${t(e)}
92
+ @input=${handleEvent(args)}
93
+ @change=${handleEvent(args)}
94
+ .formatOptions=${{ style: "percent" }}
95
+ ...=${spreadProps(args)}
12
96
  >
13
97
  Opacity
14
98
  </sp-slider>
15
99
  </div>
16
- `,noVisibleTextLabel=(e={})=>i`
100
+ `;
101
+ };
102
+ export const noVisibleTextLabel = (args = {}) => {
103
+ return html`
17
104
  <div style="width: 500px; margin: 12px 20px;">
18
105
  <sp-slider
19
106
  max="1"
20
107
  min="0"
21
108
  value=".5"
22
109
  step="0.01"
23
- @input=${s(e)}
24
- @change=${s(e)}
25
- .formatOptions=${{style:"percent"}}
26
- ...=${t(e)}
110
+ @input=${handleEvent(args)}
111
+ @change=${handleEvent(args)}
112
+ .formatOptions=${{ style: "percent" }}
113
+ ...=${spreadProps(args)}
27
114
  >
28
115
  Opacity
29
116
  </sp-slider>
30
117
  </div>
31
- `;noVisibleTextLabel.args={labelVisibility:"value"};export const noVisibleValueLabel=(e={})=>i`
118
+ `;
119
+ };
120
+ noVisibleTextLabel.args = {
121
+ labelVisibility: "value"
122
+ };
123
+ export const noVisibleValueLabel = (args = {}) => {
124
+ return html`
32
125
  <div style="width: 500px; margin: 12px 20px;">
33
126
  <sp-slider
34
127
  max="1"
35
128
  min="0"
36
129
  value=".5"
37
130
  step="0.01"
38
- @input=${s(e)}
39
- @change=${s(e)}
40
- .formatOptions=${{style:"percent"}}
41
- ...=${t(e)}
131
+ @input=${handleEvent(args)}
132
+ @change=${handleEvent(args)}
133
+ .formatOptions=${{ style: "percent" }}
134
+ ...=${spreadProps(args)}
42
135
  >
43
136
  Opacity
44
137
  </sp-slider>
45
138
  </div>
46
- `;noVisibleValueLabel.args={labelVisibility:"text"};export const noVisibleLabels=(e={})=>i`
139
+ `;
140
+ };
141
+ noVisibleValueLabel.args = {
142
+ labelVisibility: "text"
143
+ };
144
+ export const noVisibleLabels = (args = {}) => {
145
+ return html`
47
146
  <div style="width: 500px; margin: 12px 20px;">
48
147
  <sp-slider
49
148
  max="1"
50
149
  min="0"
51
150
  value=".5"
52
151
  step="0.01"
53
- @input=${s(e)}
54
- @change=${s(e)}
55
- .formatOptions=${{style:"percent"}}
56
- ...=${t(e)}
152
+ @input=${handleEvent(args)}
153
+ @change=${handleEvent(args)}
154
+ .formatOptions=${{ style: "percent" }}
155
+ ...=${spreadProps(args)}
57
156
  >
58
157
  Opacity
59
158
  </sp-slider>
60
159
  </div>
61
- `;noVisibleLabels.args={labelVisibility:"none"};export const px=(e={})=>i`
160
+ `;
161
+ };
162
+ noVisibleLabels.args = {
163
+ labelVisibility: "none"
164
+ };
165
+ export const px = (args = {}) => {
166
+ return html`
62
167
  <div style="width: 500px; margin: 12px 20px;">
63
168
  <sp-slider
64
169
  max="360"
65
170
  min="0"
66
171
  value="90"
67
172
  step="1"
68
- @input=${s(e)}
69
- @change=${s(e)}
70
- .formatOptions=${{style:"unit",unit:"px"}}
71
- ...=${t(e)}
173
+ @input=${handleEvent(args)}
174
+ @change=${handleEvent(args)}
175
+ .formatOptions=${{
176
+ style: "unit",
177
+ unit: "px"
178
+ }}
179
+ ...=${spreadProps(args)}
72
180
  >
73
181
  Angle
74
182
  </sp-slider>
75
183
  </div>
76
- `;class $ extends HTMLElement{constructor(){super();this.numberFieldLoaderPromise=Promise.resolve(!1);this.numberFieldLoaderPromise=new Promise(l=>{customElements.whenDefined("sp-number-field").then(()=>{l(!0)})})}get updateComplete(){return this.numberFieldLoaderPromise}}customElements.define("number-field-defined",$);const x=e=>i`
77
- ${e()}
184
+ `;
185
+ };
186
+ class NumberFieldDefined extends HTMLElement {
187
+ constructor() {
188
+ super();
189
+ this.numberFieldLoaderPromise = Promise.resolve(false);
190
+ this.numberFieldLoaderPromise = new Promise((res) => {
191
+ customElements.whenDefined("sp-number-field").then(() => {
192
+ res(true);
193
+ });
194
+ });
195
+ }
196
+ get updateComplete() {
197
+ return this.numberFieldLoaderPromise;
198
+ }
199
+ }
200
+ customElements.define("number-field-defined", NumberFieldDefined);
201
+ const editableDecorator = (story) => {
202
+ return html`
203
+ ${story()}
78
204
  <number-field-defined></number-field-defined>
79
- `;export const editable=(e={})=>i`
205
+ `;
206
+ };
207
+ export const editable = (args = {}) => {
208
+ return html`
80
209
  <div style="width: 500px; margin: 12px 20px;">
81
210
  <sp-slider
82
211
  editable
@@ -84,15 +213,23 @@ import{html as i}from"@spectrum-web-components/base";import"@spectrum-web-compon
84
213
  min="0"
85
214
  value="90"
86
215
  step="1"
87
- @input=${s(e)}
88
- @change=${s(e)}
89
- .formatOptions=${{style:"unit",unit:"degree",unitDisplay:"narrow"}}
90
- ...=${t(e)}
216
+ @input=${handleEvent(args)}
217
+ @change=${handleEvent(args)}
218
+ .formatOptions=${{
219
+ style: "unit",
220
+ unit: "degree",
221
+ unitDisplay: "narrow"
222
+ }}
223
+ ...=${spreadProps(args)}
91
224
  >
92
225
  Angle
93
226
  </sp-slider>
94
227
  </div>
95
- `;editable.decorators=[x];export const editableDisabled=(e={})=>i`
228
+ `;
229
+ };
230
+ editable.decorators = [editableDecorator];
231
+ export const editableDisabled = (args = {}) => {
232
+ return html`
96
233
  <div style="width: 500px; margin: 12px 20px;">
97
234
  <sp-slider
98
235
  editable
@@ -101,15 +238,23 @@ import{html as i}from"@spectrum-web-components/base";import"@spectrum-web-compon
101
238
  min="0"
102
239
  value="90"
103
240
  step="1"
104
- @input=${s(e)}
105
- @change=${s(e)}
106
- .formatOptions=${{style:"unit",unit:"degree",unitDisplay:"narrow"}}
107
- ...=${t(e)}
241
+ @input=${handleEvent(args)}
242
+ @change=${handleEvent(args)}
243
+ .formatOptions=${{
244
+ style: "unit",
245
+ unit: "degree",
246
+ unitDisplay: "narrow"
247
+ }}
248
+ ...=${spreadProps(args)}
108
249
  >
109
250
  Angle
110
251
  </sp-slider>
111
252
  </div>
112
- `;editable.decorators=[x];export const editableCustom=(e={})=>i`
253
+ `;
254
+ };
255
+ editable.decorators = [editableDecorator];
256
+ export const editableCustom = (args = {}) => {
257
+ return html`
113
258
  <div
114
259
  style="width: 500px; margin: 12px 20px; --spectrum-slider-editable-number-field-width: 150px;"
115
260
  >
@@ -119,15 +264,19 @@ import{html as i}from"@spectrum-web-components/base";import"@spectrum-web-compon
119
264
  min="0"
120
265
  value="12.75"
121
266
  step="0.25"
122
- @input=${s(e)}
123
- @change=${s(e)}
124
- .formatOptions=${{style:"unit",unit:"hour"}}
125
- ...=${t(e)}
267
+ @input=${handleEvent(args)}
268
+ @change=${handleEvent(args)}
269
+ .formatOptions=${{ style: "unit", unit: "hour" }}
270
+ ...=${spreadProps(args)}
126
271
  >
127
272
  Hours
128
273
  </sp-slider>
129
274
  </div>
130
- `;editableCustom.decorators=[x];export const hideStepper=(e={})=>i`
275
+ `;
276
+ };
277
+ editableCustom.decorators = [editableDecorator];
278
+ export const hideStepper = (args = {}) => {
279
+ return html`
131
280
  <div style="width: 500px; margin: 12px 20px;">
132
281
  <sp-slider
133
282
  editable
@@ -136,15 +285,19 @@ import{html as i}from"@spectrum-web-components/base";import"@spectrum-web-compon
136
285
  min="0"
137
286
  value=".5"
138
287
  step="0.01"
139
- @input=${s(e)}
140
- @change=${s(e)}
141
- .formatOptions=${{style:"percent"}}
142
- ...=${t(e)}
288
+ @input=${handleEvent(args)}
289
+ @change=${handleEvent(args)}
290
+ .formatOptions=${{ style: "percent" }}
291
+ ...=${spreadProps(args)}
143
292
  >
144
293
  Opacity
145
294
  </sp-slider>
146
295
  </div>
147
- `;hideStepper.decorators=[x];export const Gradient=(e={})=>i`
296
+ `;
297
+ };
298
+ hideStepper.decorators = [editableDecorator];
299
+ export const Gradient = (args = {}) => {
300
+ return html`
148
301
  <div
149
302
  style="
150
303
  width: 500px;
@@ -159,29 +312,49 @@ import{html as i}from"@spectrum-web-components/base";import"@spectrum-web-compon
159
312
  min="0"
160
313
  value="50"
161
314
  id="opacity-slider"
162
- @input=${s(e)}
163
- @change=${s(e)}
164
- ...=${t(e)}
315
+ @input=${handleEvent(args)}
316
+ @change=${handleEvent(args)}
317
+ ...=${spreadProps(args)}
165
318
  ></sp-slider>
166
319
  </div>
167
- `;Gradient.args={variant:void 0};export const tick=(e={})=>i`
320
+ `;
321
+ };
322
+ Gradient.args = {
323
+ variant: void 0
324
+ };
325
+ export const tick = (args = {}) => {
326
+ return html`
168
327
  <sp-slider
169
328
  label="Slider Label"
170
329
  variant="tick"
171
330
  min="0"
172
331
  max="92"
173
- ...=${t(e)}
332
+ ...=${spreadProps(args)}
174
333
  ></sp-slider>
175
- `;tick.args={variant:"tick",tickStep:5};export const tickLabels=(e={})=>i`
334
+ `;
335
+ };
336
+ tick.args = {
337
+ variant: "tick",
338
+ tickStep: 5
339
+ };
340
+ export const tickLabels = (args = {}) => {
341
+ return html`
176
342
  <sp-slider
177
343
  label="Slider Label"
178
344
  tick-labels
179
345
  variant="tick"
180
346
  min="50"
181
347
  max="75"
182
- ...=${t(e)}
348
+ ...=${spreadProps(args)}
183
349
  ></sp-slider>
184
- `;tickLabels.args={variant:"tick",tickStep:5};export const Disabled=(e={})=>i`
350
+ `;
351
+ };
352
+ tickLabels.args = {
353
+ variant: "tick",
354
+ tickStep: 5
355
+ };
356
+ export const Disabled = (args = {}) => {
357
+ return html`
185
358
  <div style="width: 500px; margin: 12px 20px;">
186
359
  <sp-slider
187
360
  disabled
@@ -190,10 +363,13 @@ import{html as i}from"@spectrum-web-components/base";import"@spectrum-web-compon
190
363
  min="0"
191
364
  max="20"
192
365
  label="Intensity"
193
- ...=${t(e)}
366
+ ...=${spreadProps(args)}
194
367
  ></sp-slider>
195
368
  </div>
196
- `,Quiet=(e={})=>i`
369
+ `;
370
+ };
371
+ export const Quiet = (args = {}) => {
372
+ return html`
197
373
  <div style="width: 500px; margin: 12px 20px;">
198
374
  <sp-slider
199
375
  editable
@@ -204,10 +380,13 @@ import{html as i}from"@spectrum-web-components/base";import"@spectrum-web-compon
204
380
  min="0"
205
381
  max="20"
206
382
  label="Intensity"
207
- ...=${t(e)}
383
+ ...=${spreadProps(args)}
208
384
  ></sp-slider>
209
385
  </div>
210
- `,Indeterminate=(e={})=>i`
386
+ `;
387
+ };
388
+ export const Indeterminate = (args = {}) => {
389
+ return html`
211
390
  <div style="width: 500px; margin: 12px 20px;">
212
391
  <sp-slider
213
392
  editable
@@ -217,35 +396,41 @@ import{html as i}from"@spectrum-web-components/base";import"@spectrum-web-compon
217
396
  min="0"
218
397
  max="20"
219
398
  label="Intensity"
220
- @input=${s(e)}
221
- @change=${s(e)}
222
- ...=${t(e)}
399
+ @input=${handleEvent(args)}
400
+ @change=${handleEvent(args)}
401
+ ...=${spreadProps(args)}
223
402
  ></sp-slider>
224
403
  </div>
225
- `,ExplicitHandle=(e={})=>i`
404
+ `;
405
+ };
406
+ export const ExplicitHandle = (args = {}) => {
407
+ return html`
226
408
  <div style="width: 500px; margin: 12px 20px;">
227
409
  <sp-slider
228
410
  step="0.5"
229
411
  min="0"
230
412
  max="20"
231
- @input=${o(e)}
232
- @change=${o(e)}
233
- ...=${t(e)}
413
+ @input=${handleHandleEvent(args)}
414
+ @change=${handleHandleEvent(args)}
415
+ ...=${spreadProps(args)}
234
416
  >
235
417
  Intensity
236
418
  <sp-slider-handle slot="handle" value="5"></sp-slider-handle>
237
419
  </sp-slider>
238
420
  </div>
239
- `,TwoHandles=(e={})=>i`
421
+ `;
422
+ };
423
+ export const TwoHandles = (args = {}) => {
424
+ return html`
240
425
  <div style="width: 500px; margin: 12px 20px;">
241
426
  <sp-slider
242
427
  value="5"
243
428
  step="1"
244
429
  min="0"
245
430
  max="255"
246
- @input=${o(e)}
247
- @change=${o(e)}
248
- ...=${t(e)}
431
+ @input=${handleHandleEvent(args)}
432
+ @change=${handleHandleEvent(args)}
433
+ ...=${spreadProps(args)}
249
434
  >
250
435
  Output Levels
251
436
  <sp-slider-handle
@@ -260,17 +445,27 @@ import{html as i}from"@spectrum-web-components/base";import"@spectrum-web-compon
260
445
  ></sp-slider-handle>
261
446
  </sp-slider>
262
447
  </div>
263
- `;TwoHandles.args={variant:"range",tickStep:10};export const TwoHandlesPt=(e={})=>i`
448
+ `;
449
+ };
450
+ TwoHandles.args = {
451
+ variant: "range",
452
+ tickStep: 10
453
+ };
454
+ export const TwoHandlesPt = (args = {}) => {
455
+ return html`
264
456
  <div style="width: 500px; margin: 12px 20px;">
265
457
  <sp-slider
266
458
  value="5"
267
459
  step="1"
268
460
  min="0"
269
461
  max="255"
270
- @input=${o(e)}
271
- @change=${o(e)}
272
- .formatOptions=${{style:"unit",unit:"pt"}}
273
- ...=${t(e)}
462
+ @input=${handleHandleEvent(args)}
463
+ @change=${handleHandleEvent(args)}
464
+ .formatOptions=${{
465
+ style: "unit",
466
+ unit: "pt"
467
+ }}
468
+ ...=${spreadProps(args)}
274
469
  >
275
470
  Output Levels
276
471
  <sp-slider-handle
@@ -285,17 +480,27 @@ import{html as i}from"@spectrum-web-components/base";import"@spectrum-web-compon
285
480
  ></sp-slider-handle>
286
481
  </sp-slider>
287
482
  </div>
288
- `;TwoHandlesPt.args={variant:"range",tickStep:10};export const ThreeHandlesPc=(e={})=>i`
483
+ `;
484
+ };
485
+ TwoHandlesPt.args = {
486
+ variant: "range",
487
+ tickStep: 10
488
+ };
489
+ export const ThreeHandlesPc = (args = {}) => {
490
+ return html`
289
491
  <div style="width: 500px; margin: 12px 20px;">
290
492
  <sp-slider
291
493
  value="5"
292
494
  step="1"
293
495
  min="0"
294
496
  max="255"
295
- @input=${o(e)}
296
- @change=${o(e)}
297
- .formatOptions=${{style:"unit",unit:"pc"}}
298
- ...=${t(e)}
497
+ @input=${handleHandleEvent(args)}
498
+ @change=${handleHandleEvent(args)}
499
+ .formatOptions=${{
500
+ style: "unit",
501
+ unit: "pc"
502
+ }}
503
+ ...=${spreadProps(args)}
299
504
  >
300
505
  Output Levels
301
506
  <sp-slider-handle slot="handle" value="5"></sp-slider-handle>
@@ -303,15 +508,18 @@ import{html as i}from"@spectrum-web-components/base";import"@spectrum-web-compon
303
508
  <sp-slider-handle slot="handle" value="250"></sp-slider-handle>
304
509
  </sp-slider>
305
510
  </div>
306
- `,ThreeHandlesOrdered=(e={})=>i`
511
+ `;
512
+ };
513
+ export const ThreeHandlesOrdered = (args = {}) => {
514
+ return html`
307
515
  <div style="width: 500px; margin: 12px 20px;">
308
516
  <sp-slider
309
517
  step="1"
310
518
  min="0"
311
519
  max="255"
312
- @input=${o(e)}
313
- @change=${o(e)}
314
- ...=${t(e)}
520
+ @input=${handleHandleEvent(args)}
521
+ @change=${handleHandleEvent(args)}
522
+ ...=${spreadProps(args)}
315
523
  >
316
524
  Output Levels
317
525
  <sp-slider-handle
@@ -335,22 +543,106 @@ import{html as i}from"@spectrum-web-components/base";import"@spectrum-web-compon
335
543
  ></sp-slider-handle>
336
544
  </sp-slider>
337
545
  </div>
338
- `;ThreeHandlesOrdered.args={tickStep:10};export const ThreeHandlesComplex=(e={})=>{const l={black:50,gray:4.98,white:225},r=({onInput:a,onChange:n})=>p=>{const m=p.target;if(m.value!=null){if(typeof m.value=="object"){const c=JSON.stringify(m.value,null,2);a&&p.type==="input"?a(c):n&&p.type==="change"&&n(c)}else{const c=`${m.name}: ${m.value}`;a&&p.type==="input"?a(c):n&&p.type==="change"&&n(c)}l[m.name]=m.value}},d={toNormalized(a){const n=l.black/255,p=l.white/255;return Math.max(Math.min(a,1),0)*(p-n)+n},fromNormalized(a){const n=l.black/255,p=l.white/255;return(Math.max(Math.min(a,p),n)-n)/(p-n)}},u={toNormalized(a){return Math.min(a,l.white)/255},fromNormalized(a){const n=a*255;return Math.min(n,l.white)}},h={toNormalized(a){return Math.max(a,l.black)/255},fromNormalized(a){const n=a*255;return Math.max(n,l.black)}},v=a=>{let n=1;a>.5?n=Math.max(2*(1-a),.01):a<.5&&(n=((1-2*a)*(Math.sqrt(9.99)-1)+1)**2);const p={maximumFractionDigits:2,minimumFractionDigits:2};return new Intl.NumberFormat(navigator.language,p).format(n)};return i`
546
+ `;
547
+ };
548
+ ThreeHandlesOrdered.args = {
549
+ tickStep: 10
550
+ };
551
+ export const ThreeHandlesComplex = (args = {}) => {
552
+ const values = {
553
+ black: 50,
554
+ gray: 4.98,
555
+ white: 225
556
+ };
557
+ const handleEvent2 = ({ onInput, onChange }) => (event) => {
558
+ const target = event.target;
559
+ if (target.value != null) {
560
+ if (typeof target.value === "object") {
561
+ const value = JSON.stringify(target.value, null, 2);
562
+ if (onInput && event.type === "input") {
563
+ onInput(value);
564
+ } else if (onChange && event.type === "change") {
565
+ onChange(value);
566
+ }
567
+ } else {
568
+ const value = `${target.name}: ${target.value}`;
569
+ if (onInput && event.type === "input") {
570
+ onInput(value);
571
+ } else if (onChange && event.type === "change") {
572
+ onChange(value);
573
+ }
574
+ }
575
+ values[target.name] = target.value;
576
+ }
577
+ };
578
+ const grayNormalization = {
579
+ toNormalized(value) {
580
+ const normalizedBlack = values.black / 255;
581
+ const normalizedWhite = values.white / 255;
582
+ const clamped = Math.max(Math.min(value, 1), 0);
583
+ return clamped * (normalizedWhite - normalizedBlack) + normalizedBlack;
584
+ },
585
+ fromNormalized(value) {
586
+ const normalizedBlack = values.black / 255;
587
+ const normalizedWhite = values.white / 255;
588
+ const clamped = Math.max(
589
+ Math.min(value, normalizedWhite),
590
+ normalizedBlack
591
+ );
592
+ return (clamped - normalizedBlack) / (normalizedWhite - normalizedBlack);
593
+ }
594
+ };
595
+ const blackNormalization = {
596
+ toNormalized(value) {
597
+ const clamped = Math.min(value, values.white);
598
+ return clamped / 255;
599
+ },
600
+ fromNormalized(value) {
601
+ const denormalized = value * 255;
602
+ return Math.min(denormalized, values.white);
603
+ }
604
+ };
605
+ const whiteNormalization = {
606
+ toNormalized(value) {
607
+ const clamped = Math.max(value, values.black);
608
+ return clamped / 255;
609
+ },
610
+ fromNormalized(value) {
611
+ const denormalized = value * 255;
612
+ return Math.max(denormalized, values.black);
613
+ }
614
+ };
615
+ const computeGray = (value) => {
616
+ let result = 1;
617
+ if (value > 0.5) {
618
+ result = Math.max(2 * (1 - value), 0.01);
619
+ } else if (value < 0.5) {
620
+ result = ((1 - 2 * value) * (Math.sqrt(9.99) - 1) + 1) ** 2;
621
+ }
622
+ const formatOptions = {
623
+ maximumFractionDigits: 2,
624
+ minimumFractionDigits: 2
625
+ };
626
+ return new Intl.NumberFormat(navigator.language, formatOptions).format(
627
+ result
628
+ );
629
+ };
630
+ return html`
339
631
  <div style="width: 500px; margin: 12px 20px;">
340
632
  <sp-slider
341
633
  step="1"
342
634
  min="0"
343
635
  max="255"
344
- @input=${r}
345
- @change=${r}
346
- ...=${t(e)}
636
+ @input=${handleEvent2}
637
+ @change=${handleEvent2}
638
+ ...=${spreadProps(args)}
347
639
  >
348
640
  Output Levels
349
641
  <sp-slider-handle
350
642
  slot="handle"
351
643
  name="black"
352
- value=${l.black}
353
- .normalization=${u}
644
+ value=${values.black}
645
+ .normalization=${blackNormalization}
354
646
  ></sp-slider-handle>
355
647
  <sp-slider-handle
356
648
  slot="handle"
@@ -359,50 +651,61 @@ import{html as i}from"@spectrum-web-components/base";import"@spectrum-web-compon
359
651
  min="0"
360
652
  max="1"
361
653
  step="0.005"
362
- .normalization=${d}
363
- .getAriaHandleText=${v}
654
+ .normalization=${grayNormalization}
655
+ .getAriaHandleText=${computeGray}
364
656
  ></sp-slider-handle>
365
657
  <sp-slider-handle
366
658
  slot="handle"
367
659
  name="white"
368
- value=${l.white}
369
- .normalization=${h}
660
+ value=${values.white}
661
+ .normalization=${whiteNormalization}
370
662
  ></sp-slider-handle>
371
663
  </sp-slider>
372
664
  </div>
373
- `};ThreeHandlesOrdered.args={tickStep:10};export const focusTabDemo=(e={})=>i`
665
+ `;
666
+ };
667
+ ThreeHandlesOrdered.args = {
668
+ tickStep: 10
669
+ };
670
+ export const focusTabDemo = (args = {}) => {
671
+ const value = 50;
672
+ const min = 0;
673
+ const max = 100;
674
+ const step = 1;
675
+ return html`
374
676
  <div style="width: 500px; margin: 12px 20px 20px;">
375
677
  <sp-slider
376
- value="${50}"
377
- step="${1}"
378
- min="${0}"
379
- max="${100}"
678
+ value="${value}"
679
+ step="${step}"
680
+ min="${min}"
681
+ max="${max}"
380
682
  label="Opacity"
381
683
  id="opacity-slider-opacity"
382
- ...=${t(e)}
684
+ ...=${spreadProps(args)}
383
685
  ></sp-slider>
384
686
  </div>
385
687
  <div style="width: 500px; margin: 20px;">
386
688
  <sp-slider
387
- value="${50}"
388
- step="${1}"
389
- min="${0}"
390
- max="${100}"
689
+ value="${value}"
690
+ step="${step}"
691
+ min="${min}"
692
+ max="${max}"
391
693
  label="Lightness"
392
694
  id="opacity-slider-lightness"
393
- ...=${t(e)}
695
+ ...=${spreadProps(args)}
394
696
  ></sp-slider>
395
697
  </div>
396
698
  <div style="width: 500px; margin: 20px 20px 12px;">
397
699
  <sp-slider
398
- value="${50}"
399
- step="${1}"
400
- min="${0}"
401
- max="${100}"
700
+ value="${value}"
701
+ step="${step}"
702
+ min="${min}"
703
+ max="${max}"
402
704
  label="Saturation"
403
705
  id="opacity-slider-saturation"
404
- ...=${t(e)}
706
+ ...=${spreadProps(args)}
405
707
  ></sp-slider>
406
708
  </div>
407
709
  `;
710
+ };
408
711
  //# sourceMappingURL=slider.stories.js.map