@spectrum-web-components/slider 0.12.13 → 0.12.15-devmode.7
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/README.md +16 -0
- package/custom-elements.json +40 -0
- package/package.json +41 -16
- package/sp-slider-handle.dev.js +3 -0
- package/sp-slider-handle.dev.js.map +7 -0
- package/sp-slider-handle.js +3 -14
- package/sp-slider-handle.js.map +7 -1
- package/sp-slider.dev.js +4 -0
- package/sp-slider.dev.js.map +7 -0
- package/sp-slider.js +4 -15
- package/sp-slider.js.map +7 -1
- package/src/HandleController.dev.js +434 -0
- package/src/HandleController.dev.js.map +7 -0
- package/src/HandleController.js +402 -451
- package/src/HandleController.js.map +7 -1
- package/src/Slider.d.ts +8 -0
- package/src/Slider.dev.js +367 -0
- package/src/Slider.dev.js.map +7 -0
- package/src/Slider.js +282 -289
- package/src/Slider.js.map +7 -1
- package/src/SliderHandle.dev.js +184 -0
- package/src/SliderHandle.dev.js.map +7 -0
- package/src/SliderHandle.js +171 -179
- package/src/SliderHandle.js.map +7 -1
- package/src/index.dev.js +4 -0
- package/src/index.dev.js.map +7 -0
- package/src/index.js +4 -15
- package/src/index.js.map +7 -1
- package/src/slider.css.dev.js +234 -0
- package/src/slider.css.dev.js.map +7 -0
- package/src/slider.css.js +3 -14
- package/src/slider.css.js.map +7 -1
- package/src/spectrum-slider.css.dev.js +216 -0
- package/src/spectrum-slider.css.dev.js.map +7 -0
- package/src/spectrum-slider.css.js +3 -14
- package/src/spectrum-slider.css.js.map +7 -1
- package/stories/slider.stories.js +257 -267
- package/stories/slider.stories.js.map +7 -1
- package/sync/sp-slider.dev.js +3 -0
- package/sync/sp-slider.dev.js.map +7 -0
- package/sync/sp-slider.js +3 -14
- package/sync/sp-slider.js.map +7 -1
- package/test/benchmark/test-basic.js +5 -16
- package/test/benchmark/test-basic.js.map +7 -1
- package/test/slider-editable-sync.test.js +132 -144
- package/test/slider-editable-sync.test.js.map +7 -1
- package/test/slider-editable.test.js +151 -144
- package/test/slider-editable.test.js.map +7 -1
- package/test/slider-handle-upgrade.test.js +10 -21
- package/test/slider-handle-upgrade.test.js.map +7 -1
- package/test/slider.test-vrt.js +4 -15
- package/test/slider.test-vrt.js.map +7 -1
- package/test/slider.test.js +686 -700
- package/test/slider.test.js.map +7 -1
|
@@ -1,100 +1,87 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
import { html } from '@spectrum-web-components/base';
|
|
13
|
-
import '../sp-slider.js';
|
|
14
|
-
import '../sp-slider-handle.js';
|
|
15
|
-
import { variants } from '../';
|
|
16
|
-
import { spreadProps } from '../../../test/lit-helpers.js';
|
|
1
|
+
import { html } from "@spectrum-web-components/base";
|
|
2
|
+
import "@spectrum-web-components/slider/sp-slider.js";
|
|
3
|
+
import "@spectrum-web-components/slider/sp-slider-handle.js";
|
|
4
|
+
import {
|
|
5
|
+
variants
|
|
6
|
+
} from "@spectrum-web-components/slider";
|
|
7
|
+
import { spreadProps } from "../../../test/lit-helpers.js";
|
|
17
8
|
export default {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
},
|
|
35
|
-
tickStep: {
|
|
36
|
-
name: 'Tick Step',
|
|
37
|
-
description: 'Tick spacing on slider.',
|
|
38
|
-
table: {
|
|
39
|
-
type: { summary: 'number' },
|
|
40
|
-
defaultValue: { summary: 0.1 },
|
|
41
|
-
},
|
|
42
|
-
control: {
|
|
43
|
-
type: 'number',
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
labelVisibility: {
|
|
47
|
-
name: 'Label Visibility',
|
|
48
|
-
description: 'The labels visibily available in the UI',
|
|
49
|
-
table: {
|
|
50
|
-
type: { summary: '"text" | "value" | "none" | undefined' },
|
|
51
|
-
defaultValue: { summary: undefined },
|
|
52
|
-
},
|
|
53
|
-
control: {
|
|
54
|
-
type: 'text',
|
|
55
|
-
},
|
|
56
|
-
},
|
|
9
|
+
component: "sp-slider",
|
|
10
|
+
title: "Slider",
|
|
11
|
+
argTypes: {
|
|
12
|
+
onInput: { action: "input" },
|
|
13
|
+
onChange: { action: "change" },
|
|
14
|
+
variant: {
|
|
15
|
+
name: "Variant",
|
|
16
|
+
description: "Determines the style of slider.",
|
|
17
|
+
table: {
|
|
18
|
+
type: { summary: "string" },
|
|
19
|
+
defaultValue: { summary: void 0 }
|
|
20
|
+
},
|
|
21
|
+
control: {
|
|
22
|
+
type: "inline-radio",
|
|
23
|
+
options: [void 0, ...variants]
|
|
24
|
+
}
|
|
57
25
|
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
26
|
+
tickStep: {
|
|
27
|
+
name: "Tick Step",
|
|
28
|
+
description: "Tick spacing on slider.",
|
|
29
|
+
table: {
|
|
30
|
+
type: { summary: "number" },
|
|
31
|
+
defaultValue: { summary: 0.1 }
|
|
32
|
+
},
|
|
33
|
+
control: {
|
|
34
|
+
type: "number"
|
|
35
|
+
}
|
|
62
36
|
},
|
|
37
|
+
labelVisibility: {
|
|
38
|
+
name: "Label Visibility",
|
|
39
|
+
description: "The labels visibily available in the UI",
|
|
40
|
+
table: {
|
|
41
|
+
type: { summary: '"text" | "value" | "none" | undefined' },
|
|
42
|
+
defaultValue: { summary: void 0 }
|
|
43
|
+
},
|
|
44
|
+
control: {
|
|
45
|
+
type: "text"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
args: {
|
|
50
|
+
variant: void 0,
|
|
51
|
+
tickStep: 0.1,
|
|
52
|
+
labelVisibility: void 0
|
|
53
|
+
}
|
|
63
54
|
};
|
|
64
55
|
const handleEvent = ({ onInput, onChange }) => (event) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
56
|
+
const { value } = event.target;
|
|
57
|
+
if (onInput && event.type === "input") {
|
|
58
|
+
onInput(value.toString());
|
|
59
|
+
} else if (onChange && event.type === "change") {
|
|
60
|
+
onChange(value.toString());
|
|
61
|
+
}
|
|
72
62
|
};
|
|
73
63
|
const handleHandleEvent = ({ onInput, onChange }) => (event) => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
else if (onChange && event.type === 'change') {
|
|
91
|
-
onChange(value);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
64
|
+
const target = event.target;
|
|
65
|
+
if (target.value != null) {
|
|
66
|
+
if (typeof target.value === "object") {
|
|
67
|
+
const value = JSON.stringify(target.value, null, 2);
|
|
68
|
+
if (onInput && event.type === "input") {
|
|
69
|
+
onInput(value);
|
|
70
|
+
} else if (onChange && event.type === "change") {
|
|
71
|
+
onChange(value);
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
const value = `${target.name}: ${target.value}`;
|
|
75
|
+
if (onInput && event.type === "input") {
|
|
76
|
+
onInput(value);
|
|
77
|
+
} else if (onChange && event.type === "change") {
|
|
78
|
+
onChange(value);
|
|
79
|
+
}
|
|
94
80
|
}
|
|
81
|
+
}
|
|
95
82
|
};
|
|
96
83
|
export const Default = (args = {}) => {
|
|
97
|
-
|
|
84
|
+
return html`
|
|
98
85
|
<div style="width: 500px; margin: 12px 20px;">
|
|
99
86
|
<sp-slider
|
|
100
87
|
max="1"
|
|
@@ -103,7 +90,7 @@ export const Default = (args = {}) => {
|
|
|
103
90
|
step="0.01"
|
|
104
91
|
@input=${handleEvent(args)}
|
|
105
92
|
@change=${handleEvent(args)}
|
|
106
|
-
.formatOptions=${{ style:
|
|
93
|
+
.formatOptions=${{ style: "percent" }}
|
|
107
94
|
...=${spreadProps(args)}
|
|
108
95
|
>
|
|
109
96
|
Opacity
|
|
@@ -112,7 +99,7 @@ export const Default = (args = {}) => {
|
|
|
112
99
|
`;
|
|
113
100
|
};
|
|
114
101
|
export const noVisibleTextLabel = (args = {}) => {
|
|
115
|
-
|
|
102
|
+
return html`
|
|
116
103
|
<div style="width: 500px; margin: 12px 20px;">
|
|
117
104
|
<sp-slider
|
|
118
105
|
max="1"
|
|
@@ -121,7 +108,7 @@ export const noVisibleTextLabel = (args = {}) => {
|
|
|
121
108
|
step="0.01"
|
|
122
109
|
@input=${handleEvent(args)}
|
|
123
110
|
@change=${handleEvent(args)}
|
|
124
|
-
.formatOptions=${{ style:
|
|
111
|
+
.formatOptions=${{ style: "percent" }}
|
|
125
112
|
...=${spreadProps(args)}
|
|
126
113
|
>
|
|
127
114
|
Opacity
|
|
@@ -130,10 +117,10 @@ export const noVisibleTextLabel = (args = {}) => {
|
|
|
130
117
|
`;
|
|
131
118
|
};
|
|
132
119
|
noVisibleTextLabel.args = {
|
|
133
|
-
|
|
120
|
+
labelVisibility: "value"
|
|
134
121
|
};
|
|
135
122
|
export const noVisibleValueLabel = (args = {}) => {
|
|
136
|
-
|
|
123
|
+
return html`
|
|
137
124
|
<div style="width: 500px; margin: 12px 20px;">
|
|
138
125
|
<sp-slider
|
|
139
126
|
max="1"
|
|
@@ -142,7 +129,7 @@ export const noVisibleValueLabel = (args = {}) => {
|
|
|
142
129
|
step="0.01"
|
|
143
130
|
@input=${handleEvent(args)}
|
|
144
131
|
@change=${handleEvent(args)}
|
|
145
|
-
.formatOptions=${{ style:
|
|
132
|
+
.formatOptions=${{ style: "percent" }}
|
|
146
133
|
...=${spreadProps(args)}
|
|
147
134
|
>
|
|
148
135
|
Opacity
|
|
@@ -151,10 +138,10 @@ export const noVisibleValueLabel = (args = {}) => {
|
|
|
151
138
|
`;
|
|
152
139
|
};
|
|
153
140
|
noVisibleValueLabel.args = {
|
|
154
|
-
|
|
141
|
+
labelVisibility: "text"
|
|
155
142
|
};
|
|
156
143
|
export const noVisibleLabels = (args = {}) => {
|
|
157
|
-
|
|
144
|
+
return html`
|
|
158
145
|
<div style="width: 500px; margin: 12px 20px;">
|
|
159
146
|
<sp-slider
|
|
160
147
|
max="1"
|
|
@@ -163,7 +150,7 @@ export const noVisibleLabels = (args = {}) => {
|
|
|
163
150
|
step="0.01"
|
|
164
151
|
@input=${handleEvent(args)}
|
|
165
152
|
@change=${handleEvent(args)}
|
|
166
|
-
.formatOptions=${{ style:
|
|
153
|
+
.formatOptions=${{ style: "percent" }}
|
|
167
154
|
...=${spreadProps(args)}
|
|
168
155
|
>
|
|
169
156
|
Opacity
|
|
@@ -172,10 +159,10 @@ export const noVisibleLabels = (args = {}) => {
|
|
|
172
159
|
`;
|
|
173
160
|
};
|
|
174
161
|
noVisibleLabels.args = {
|
|
175
|
-
|
|
162
|
+
labelVisibility: "none"
|
|
176
163
|
};
|
|
177
164
|
export const px = (args = {}) => {
|
|
178
|
-
|
|
165
|
+
return html`
|
|
179
166
|
<div style="width: 500px; margin: 12px 20px;">
|
|
180
167
|
<sp-slider
|
|
181
168
|
max="360"
|
|
@@ -185,9 +172,9 @@ export const px = (args = {}) => {
|
|
|
185
172
|
@input=${handleEvent(args)}
|
|
186
173
|
@change=${handleEvent(args)}
|
|
187
174
|
.formatOptions=${{
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
175
|
+
style: "unit",
|
|
176
|
+
unit: "px"
|
|
177
|
+
}}
|
|
191
178
|
...=${spreadProps(args)}
|
|
192
179
|
>
|
|
193
180
|
Angle
|
|
@@ -196,28 +183,28 @@ export const px = (args = {}) => {
|
|
|
196
183
|
`;
|
|
197
184
|
};
|
|
198
185
|
class NumberFieldDefined extends HTMLElement {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
186
|
+
constructor() {
|
|
187
|
+
super();
|
|
188
|
+
this.numberFieldLoaderPromise = Promise.resolve(false);
|
|
189
|
+
this.numberFieldLoaderPromise = new Promise((res) => {
|
|
190
|
+
customElements.whenDefined("sp-number-field").then(() => {
|
|
191
|
+
res(true);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
get updateComplete() {
|
|
196
|
+
return this.numberFieldLoaderPromise;
|
|
197
|
+
}
|
|
211
198
|
}
|
|
212
|
-
customElements.define(
|
|
199
|
+
customElements.define("number-field-defined", NumberFieldDefined);
|
|
213
200
|
const editableDecorator = (story) => {
|
|
214
|
-
|
|
201
|
+
return html`
|
|
215
202
|
${story()}
|
|
216
203
|
<number-field-defined></number-field-defined>
|
|
217
204
|
`;
|
|
218
205
|
};
|
|
219
206
|
export const editable = (args = {}) => {
|
|
220
|
-
|
|
207
|
+
return html`
|
|
221
208
|
<div style="width: 500px; margin: 12px 20px;">
|
|
222
209
|
<sp-slider
|
|
223
210
|
editable
|
|
@@ -228,10 +215,10 @@ export const editable = (args = {}) => {
|
|
|
228
215
|
@input=${handleEvent(args)}
|
|
229
216
|
@change=${handleEvent(args)}
|
|
230
217
|
.formatOptions=${{
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
218
|
+
style: "unit",
|
|
219
|
+
unit: "degree",
|
|
220
|
+
unitDisplay: "narrow"
|
|
221
|
+
}}
|
|
235
222
|
...=${spreadProps(args)}
|
|
236
223
|
>
|
|
237
224
|
Angle
|
|
@@ -241,7 +228,7 @@ export const editable = (args = {}) => {
|
|
|
241
228
|
};
|
|
242
229
|
editable.decorators = [editableDecorator];
|
|
243
230
|
export const editableDisabled = (args = {}) => {
|
|
244
|
-
|
|
231
|
+
return html`
|
|
245
232
|
<div style="width: 500px; margin: 12px 20px;">
|
|
246
233
|
<sp-slider
|
|
247
234
|
editable
|
|
@@ -253,10 +240,10 @@ export const editableDisabled = (args = {}) => {
|
|
|
253
240
|
@input=${handleEvent(args)}
|
|
254
241
|
@change=${handleEvent(args)}
|
|
255
242
|
.formatOptions=${{
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
243
|
+
style: "unit",
|
|
244
|
+
unit: "degree",
|
|
245
|
+
unitDisplay: "narrow"
|
|
246
|
+
}}
|
|
260
247
|
...=${spreadProps(args)}
|
|
261
248
|
>
|
|
262
249
|
Angle
|
|
@@ -266,7 +253,7 @@ export const editableDisabled = (args = {}) => {
|
|
|
266
253
|
};
|
|
267
254
|
editable.decorators = [editableDecorator];
|
|
268
255
|
export const editableCustom = (args = {}) => {
|
|
269
|
-
|
|
256
|
+
return html`
|
|
270
257
|
<div
|
|
271
258
|
style="width: 500px; margin: 12px 20px; --spectrum-slider-editable-number-field-width: 150px;"
|
|
272
259
|
>
|
|
@@ -278,7 +265,7 @@ export const editableCustom = (args = {}) => {
|
|
|
278
265
|
step="0.25"
|
|
279
266
|
@input=${handleEvent(args)}
|
|
280
267
|
@change=${handleEvent(args)}
|
|
281
|
-
.formatOptions=${{ style:
|
|
268
|
+
.formatOptions=${{ style: "unit", unit: "hour" }}
|
|
282
269
|
...=${spreadProps(args)}
|
|
283
270
|
>
|
|
284
271
|
Hours
|
|
@@ -288,7 +275,7 @@ export const editableCustom = (args = {}) => {
|
|
|
288
275
|
};
|
|
289
276
|
editableCustom.decorators = [editableDecorator];
|
|
290
277
|
export const hideStepper = (args = {}) => {
|
|
291
|
-
|
|
278
|
+
return html`
|
|
292
279
|
<div style="width: 500px; margin: 12px 20px;">
|
|
293
280
|
<sp-slider
|
|
294
281
|
editable
|
|
@@ -299,7 +286,7 @@ export const hideStepper = (args = {}) => {
|
|
|
299
286
|
step="0.01"
|
|
300
287
|
@input=${handleEvent(args)}
|
|
301
288
|
@change=${handleEvent(args)}
|
|
302
|
-
.formatOptions=${{ style:
|
|
289
|
+
.formatOptions=${{ style: "percent" }}
|
|
303
290
|
...=${spreadProps(args)}
|
|
304
291
|
>
|
|
305
292
|
Opacity
|
|
@@ -309,7 +296,7 @@ export const hideStepper = (args = {}) => {
|
|
|
309
296
|
};
|
|
310
297
|
hideStepper.decorators = [editableDecorator];
|
|
311
298
|
export const Gradient = (args = {}) => {
|
|
312
|
-
|
|
299
|
+
return html`
|
|
313
300
|
<div
|
|
314
301
|
style="
|
|
315
302
|
width: 500px;
|
|
@@ -332,10 +319,10 @@ export const Gradient = (args = {}) => {
|
|
|
332
319
|
`;
|
|
333
320
|
};
|
|
334
321
|
Gradient.args = {
|
|
335
|
-
|
|
322
|
+
variant: void 0
|
|
336
323
|
};
|
|
337
324
|
export const tick = (args = {}) => {
|
|
338
|
-
|
|
325
|
+
return html`
|
|
339
326
|
<sp-slider
|
|
340
327
|
label="Slider Label"
|
|
341
328
|
variant="tick"
|
|
@@ -346,11 +333,11 @@ export const tick = (args = {}) => {
|
|
|
346
333
|
`;
|
|
347
334
|
};
|
|
348
335
|
tick.args = {
|
|
349
|
-
|
|
350
|
-
|
|
336
|
+
variant: "tick",
|
|
337
|
+
tickStep: 5
|
|
351
338
|
};
|
|
352
339
|
export const tickLabels = (args = {}) => {
|
|
353
|
-
|
|
340
|
+
return html`
|
|
354
341
|
<sp-slider
|
|
355
342
|
label="Slider Label"
|
|
356
343
|
tick-labels
|
|
@@ -362,11 +349,11 @@ export const tickLabels = (args = {}) => {
|
|
|
362
349
|
`;
|
|
363
350
|
};
|
|
364
351
|
tickLabels.args = {
|
|
365
|
-
|
|
366
|
-
|
|
352
|
+
variant: "tick",
|
|
353
|
+
tickStep: 5
|
|
367
354
|
};
|
|
368
355
|
export const Disabled = (args = {}) => {
|
|
369
|
-
|
|
356
|
+
return html`
|
|
370
357
|
<div style="width: 500px; margin: 12px 20px;">
|
|
371
358
|
<sp-slider
|
|
372
359
|
disabled
|
|
@@ -380,8 +367,43 @@ export const Disabled = (args = {}) => {
|
|
|
380
367
|
</div>
|
|
381
368
|
`;
|
|
382
369
|
};
|
|
370
|
+
export const Quiet = (args = {}) => {
|
|
371
|
+
return html`
|
|
372
|
+
<div style="width: 500px; margin: 12px 20px;">
|
|
373
|
+
<sp-slider
|
|
374
|
+
editable
|
|
375
|
+
hide-stepper
|
|
376
|
+
quiet
|
|
377
|
+
value="5"
|
|
378
|
+
step="0.5"
|
|
379
|
+
min="0"
|
|
380
|
+
max="20"
|
|
381
|
+
label="Intensity"
|
|
382
|
+
...=${spreadProps(args)}
|
|
383
|
+
></sp-slider>
|
|
384
|
+
</div>
|
|
385
|
+
`;
|
|
386
|
+
};
|
|
387
|
+
export const Indeterminate = (args = {}) => {
|
|
388
|
+
return html`
|
|
389
|
+
<div style="width: 500px; margin: 12px 20px;">
|
|
390
|
+
<sp-slider
|
|
391
|
+
editable
|
|
392
|
+
indeterminate
|
|
393
|
+
value="5"
|
|
394
|
+
step="0.5"
|
|
395
|
+
min="0"
|
|
396
|
+
max="20"
|
|
397
|
+
label="Intensity"
|
|
398
|
+
@input=${handleEvent(args)}
|
|
399
|
+
@change=${handleEvent(args)}
|
|
400
|
+
...=${spreadProps(args)}
|
|
401
|
+
></sp-slider>
|
|
402
|
+
</div>
|
|
403
|
+
`;
|
|
404
|
+
};
|
|
383
405
|
export const ExplicitHandle = (args = {}) => {
|
|
384
|
-
|
|
406
|
+
return html`
|
|
385
407
|
<div style="width: 500px; margin: 12px 20px;">
|
|
386
408
|
<sp-slider
|
|
387
409
|
step="0.5"
|
|
@@ -398,7 +420,7 @@ export const ExplicitHandle = (args = {}) => {
|
|
|
398
420
|
`;
|
|
399
421
|
};
|
|
400
422
|
export const TwoHandles = (args = {}) => {
|
|
401
|
-
|
|
423
|
+
return html`
|
|
402
424
|
<div style="width: 500px; margin: 12px 20px;">
|
|
403
425
|
<sp-slider
|
|
404
426
|
value="5"
|
|
@@ -425,11 +447,11 @@ export const TwoHandles = (args = {}) => {
|
|
|
425
447
|
`;
|
|
426
448
|
};
|
|
427
449
|
TwoHandles.args = {
|
|
428
|
-
|
|
429
|
-
|
|
450
|
+
variant: "range",
|
|
451
|
+
tickStep: 10
|
|
430
452
|
};
|
|
431
453
|
export const TwoHandlesPt = (args = {}) => {
|
|
432
|
-
|
|
454
|
+
return html`
|
|
433
455
|
<div style="width: 500px; margin: 12px 20px;">
|
|
434
456
|
<sp-slider
|
|
435
457
|
value="5"
|
|
@@ -439,9 +461,9 @@ export const TwoHandlesPt = (args = {}) => {
|
|
|
439
461
|
@input=${handleHandleEvent(args)}
|
|
440
462
|
@change=${handleHandleEvent(args)}
|
|
441
463
|
.formatOptions=${{
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
464
|
+
style: "unit",
|
|
465
|
+
unit: "pt"
|
|
466
|
+
}}
|
|
445
467
|
...=${spreadProps(args)}
|
|
446
468
|
>
|
|
447
469
|
Output Levels
|
|
@@ -460,11 +482,11 @@ export const TwoHandlesPt = (args = {}) => {
|
|
|
460
482
|
`;
|
|
461
483
|
};
|
|
462
484
|
TwoHandlesPt.args = {
|
|
463
|
-
|
|
464
|
-
|
|
485
|
+
variant: "range",
|
|
486
|
+
tickStep: 10
|
|
465
487
|
};
|
|
466
488
|
export const ThreeHandlesPc = (args = {}) => {
|
|
467
|
-
|
|
489
|
+
return html`
|
|
468
490
|
<div style="width: 500px; margin: 12px 20px;">
|
|
469
491
|
<sp-slider
|
|
470
492
|
value="5"
|
|
@@ -474,9 +496,9 @@ export const ThreeHandlesPc = (args = {}) => {
|
|
|
474
496
|
@input=${handleHandleEvent(args)}
|
|
475
497
|
@change=${handleHandleEvent(args)}
|
|
476
498
|
.formatOptions=${{
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
499
|
+
style: "unit",
|
|
500
|
+
unit: "pc"
|
|
501
|
+
}}
|
|
480
502
|
...=${spreadProps(args)}
|
|
481
503
|
>
|
|
482
504
|
Output Levels
|
|
@@ -488,7 +510,7 @@ export const ThreeHandlesPc = (args = {}) => {
|
|
|
488
510
|
`;
|
|
489
511
|
};
|
|
490
512
|
export const ThreeHandlesOrdered = (args = {}) => {
|
|
491
|
-
|
|
513
|
+
return html`
|
|
492
514
|
<div style="width: 500px; margin: 12px 20px;">
|
|
493
515
|
<sp-slider
|
|
494
516
|
step="1"
|
|
@@ -523,122 +545,90 @@ export const ThreeHandlesOrdered = (args = {}) => {
|
|
|
523
545
|
`;
|
|
524
546
|
};
|
|
525
547
|
ThreeHandlesOrdered.args = {
|
|
526
|
-
|
|
527
|
-
};
|
|
528
|
-
// This is a very complex example from an actual application.
|
|
529
|
-
//
|
|
530
|
-
// The first and last handles go from 0 to 255 in a linear fashion.
|
|
531
|
-
// The last and first handles are ordered so that the last handle
|
|
532
|
-
// must be greater than or equal to the first handle.
|
|
533
|
-
//
|
|
534
|
-
// The middle handle's range goes from 9.99 to 0.01, counting down.
|
|
535
|
-
// the middle handle's limits are set by the outer handles such that
|
|
536
|
-
// the position of the left handle is the staring value (9.99) for the
|
|
537
|
-
// middle handle. And the position of the right handle is the end
|
|
538
|
-
// value (0.01). That means that the middle handle will move
|
|
539
|
-
// proportionally as you move the outer handles.
|
|
540
|
-
//
|
|
541
|
-
// The two other interesting features of the middle handle are that
|
|
542
|
-
// it counts down, and that it does so exponentially for the first
|
|
543
|
-
// half of its range.
|
|
544
|
-
//
|
|
545
|
-
// Because the specification for the <input> tag in HTML says that the
|
|
546
|
-
// min should be less than the max, we do a double normalization to make
|
|
547
|
-
// this work. The middle handle is considered to go between 0 and 1,
|
|
548
|
-
// where 0 is the left handle's position and 1 is the right handle's
|
|
549
|
-
// position. We then do the appropriate calculation to convert that
|
|
550
|
-
// value into one between 9.99 and 0.01 for display to the user.
|
|
551
|
-
//
|
|
552
|
-
// One iteresting thing to note is that the normalization function
|
|
553
|
-
// can also be used to enforce clamping.
|
|
554
|
-
//
|
|
548
|
+
tickStep: 10
|
|
549
|
+
};
|
|
555
550
|
export const ThreeHandlesComplex = (args = {}) => {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
onChange(value);
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
else {
|
|
574
|
-
const value = `${target.name}: ${target.value}`;
|
|
575
|
-
if (onInput && event.type === 'input') {
|
|
576
|
-
onInput(value);
|
|
577
|
-
}
|
|
578
|
-
else if (onChange && event.type === 'change') {
|
|
579
|
-
onChange(value);
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
values[target.name] = target.value;
|
|
583
|
-
}
|
|
584
|
-
};
|
|
585
|
-
const grayNormalization = {
|
|
586
|
-
toNormalized(value) {
|
|
587
|
-
const normalizedBlack = values.black / 255;
|
|
588
|
-
const normalizedWhite = values.white / 255;
|
|
589
|
-
const clamped = Math.max(Math.min(value, 1), 0);
|
|
590
|
-
return (clamped * (normalizedWhite - normalizedBlack) + normalizedBlack);
|
|
591
|
-
},
|
|
592
|
-
fromNormalized(value) {
|
|
593
|
-
const normalizedBlack = values.black / 255;
|
|
594
|
-
const normalizedWhite = values.white / 255;
|
|
595
|
-
const clamped = Math.max(Math.min(value, normalizedWhite), normalizedBlack);
|
|
596
|
-
return ((clamped - normalizedBlack) /
|
|
597
|
-
(normalizedWhite - normalizedBlack));
|
|
598
|
-
},
|
|
599
|
-
};
|
|
600
|
-
const blackNormalization = {
|
|
601
|
-
toNormalized(value) {
|
|
602
|
-
const clamped = Math.min(value, values.white);
|
|
603
|
-
return clamped / 255;
|
|
604
|
-
},
|
|
605
|
-
fromNormalized(value) {
|
|
606
|
-
const denormalized = value * 255;
|
|
607
|
-
return Math.min(denormalized, values.white);
|
|
608
|
-
},
|
|
609
|
-
};
|
|
610
|
-
const whiteNormalization = {
|
|
611
|
-
toNormalized(value) {
|
|
612
|
-
const clamped = Math.max(value, values.black);
|
|
613
|
-
return clamped / 255;
|
|
614
|
-
},
|
|
615
|
-
fromNormalized(value) {
|
|
616
|
-
const denormalized = value * 255;
|
|
617
|
-
return Math.max(denormalized, values.black);
|
|
618
|
-
},
|
|
619
|
-
};
|
|
620
|
-
const computeGray = (value) => {
|
|
621
|
-
let result = 1.0;
|
|
622
|
-
if (value > 0.5) {
|
|
623
|
-
result = Math.max(2 * (1 - value), 0.01);
|
|
551
|
+
const values = {
|
|
552
|
+
black: 50,
|
|
553
|
+
gray: 4.98,
|
|
554
|
+
white: 225
|
|
555
|
+
};
|
|
556
|
+
const handleEvent2 = ({ onInput, onChange }) => (event) => {
|
|
557
|
+
const target = event.target;
|
|
558
|
+
if (target.value != null) {
|
|
559
|
+
if (typeof target.value === "object") {
|
|
560
|
+
const value = JSON.stringify(target.value, null, 2);
|
|
561
|
+
if (onInput && event.type === "input") {
|
|
562
|
+
onInput(value);
|
|
563
|
+
} else if (onChange && event.type === "change") {
|
|
564
|
+
onChange(value);
|
|
624
565
|
}
|
|
625
|
-
|
|
626
|
-
|
|
566
|
+
} else {
|
|
567
|
+
const value = `${target.name}: ${target.value}`;
|
|
568
|
+
if (onInput && event.type === "input") {
|
|
569
|
+
onInput(value);
|
|
570
|
+
} else if (onChange && event.type === "change") {
|
|
571
|
+
onChange(value);
|
|
627
572
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
573
|
+
}
|
|
574
|
+
values[target.name] = target.value;
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
const grayNormalization = {
|
|
578
|
+
toNormalized(value) {
|
|
579
|
+
const normalizedBlack = values.black / 255;
|
|
580
|
+
const normalizedWhite = values.white / 255;
|
|
581
|
+
const clamped = Math.max(Math.min(value, 1), 0);
|
|
582
|
+
return clamped * (normalizedWhite - normalizedBlack) + normalizedBlack;
|
|
583
|
+
},
|
|
584
|
+
fromNormalized(value) {
|
|
585
|
+
const normalizedBlack = values.black / 255;
|
|
586
|
+
const normalizedWhite = values.white / 255;
|
|
587
|
+
const clamped = Math.max(Math.min(value, normalizedWhite), normalizedBlack);
|
|
588
|
+
return (clamped - normalizedBlack) / (normalizedWhite - normalizedBlack);
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
const blackNormalization = {
|
|
592
|
+
toNormalized(value) {
|
|
593
|
+
const clamped = Math.min(value, values.white);
|
|
594
|
+
return clamped / 255;
|
|
595
|
+
},
|
|
596
|
+
fromNormalized(value) {
|
|
597
|
+
const denormalized = value * 255;
|
|
598
|
+
return Math.min(denormalized, values.white);
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
const whiteNormalization = {
|
|
602
|
+
toNormalized(value) {
|
|
603
|
+
const clamped = Math.max(value, values.black);
|
|
604
|
+
return clamped / 255;
|
|
605
|
+
},
|
|
606
|
+
fromNormalized(value) {
|
|
607
|
+
const denormalized = value * 255;
|
|
608
|
+
return Math.max(denormalized, values.black);
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
const computeGray = (value) => {
|
|
612
|
+
let result = 1;
|
|
613
|
+
if (value > 0.5) {
|
|
614
|
+
result = Math.max(2 * (1 - value), 0.01);
|
|
615
|
+
} else if (value < 0.5) {
|
|
616
|
+
result = ((1 - 2 * value) * (Math.sqrt(9.99) - 1) + 1) ** 2;
|
|
617
|
+
}
|
|
618
|
+
const formatOptions = {
|
|
619
|
+
maximumFractionDigits: 2,
|
|
620
|
+
minimumFractionDigits: 2
|
|
633
621
|
};
|
|
634
|
-
return
|
|
622
|
+
return new Intl.NumberFormat(navigator.language, formatOptions).format(result);
|
|
623
|
+
};
|
|
624
|
+
return html`
|
|
635
625
|
<div style="width: 500px; margin: 12px 20px;">
|
|
636
626
|
<sp-slider
|
|
637
627
|
step="1"
|
|
638
628
|
min="0"
|
|
639
629
|
max="255"
|
|
640
|
-
@input=${
|
|
641
|
-
@change=${
|
|
630
|
+
@input=${handleEvent2}
|
|
631
|
+
@change=${handleEvent2}
|
|
642
632
|
...=${spreadProps(args)}
|
|
643
633
|
>
|
|
644
634
|
Output Levels
|
|
@@ -669,14 +659,14 @@ export const ThreeHandlesComplex = (args = {}) => {
|
|
|
669
659
|
`;
|
|
670
660
|
};
|
|
671
661
|
ThreeHandlesOrdered.args = {
|
|
672
|
-
|
|
662
|
+
tickStep: 10
|
|
673
663
|
};
|
|
674
664
|
export const focusTabDemo = (args = {}) => {
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
665
|
+
const value = 50;
|
|
666
|
+
const min = 0;
|
|
667
|
+
const max = 100;
|
|
668
|
+
const step = 1;
|
|
669
|
+
return html`
|
|
680
670
|
<div style="width: 500px; margin: 12px 20px 20px;">
|
|
681
671
|
<sp-slider
|
|
682
672
|
value="${value}"
|
|
@@ -712,4 +702,4 @@ export const focusTabDemo = (args = {}) => {
|
|
|
712
702
|
</div>
|
|
713
703
|
`;
|
|
714
704
|
};
|
|
715
|
-
//# sourceMappingURL=slider.stories.js.map
|
|
705
|
+
//# sourceMappingURL=slider.stories.js.map
|