@geoffcox/sterling-svelte 0.0.8 → 0.0.10
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/buttons/Button.svelte +152 -145
- package/display/Label.svelte +27 -0
- package/display/Label.svelte.d.ts +20 -0
- package/display/Progress.svelte +141 -133
- package/index.d.ts +3 -1
- package/index.js +3 -1
- package/inputs/Checkbox.svelte +129 -117
- package/inputs/Input.svelte +108 -142
- package/inputs/Radio.svelte +129 -113
- package/inputs/Select.svelte +191 -199
- package/inputs/Slider.svelte +182 -209
- package/lists/List.svelte +143 -214
- package/package.json +5 -1
- package/surfaces/CloseX.svelte +5 -0
- package/surfaces/CloseX.svelte.d.ts +23 -0
- package/surfaces/Dialog.svelte +241 -0
- package/surfaces/Dialog.svelte.d.ts +34 -0
- package/theme/colors.js +2 -0
- package/theme/darkTheme.js +3 -3
package/inputs/Slider.svelte
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
<script>import {
|
|
2
|
-
import {
|
|
1
|
+
<script>import { createEventDispatcher } from "svelte";
|
|
2
|
+
import { round } from "lodash-es";
|
|
3
|
+
import { v4 as uuid } from "uuid";
|
|
4
|
+
import Label from "../display/Label.svelte";
|
|
3
5
|
export let value = 0;
|
|
4
6
|
export let min = 0;
|
|
5
7
|
export let max = 100;
|
|
@@ -7,6 +9,7 @@ export let step = void 0;
|
|
|
7
9
|
export let precision = 0;
|
|
8
10
|
export let vertical = false;
|
|
9
11
|
export let disabled = false;
|
|
12
|
+
const inputId = uuid();
|
|
10
13
|
let sliderRef;
|
|
11
14
|
const dispatch = createEventDispatcher();
|
|
12
15
|
const raiseChange = (newValue) => {
|
|
@@ -121,240 +124,210 @@ const onKeyDown = (event) => {
|
|
|
121
124
|
<!-- @component
|
|
122
125
|
Slider lets the user chose a value within a min/max range by dragging a thumb button.
|
|
123
126
|
-->
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
</div>
|
|
162
|
-
</label>
|
|
163
|
-
{:else}
|
|
164
|
-
<div
|
|
165
|
-
class="sterling-slider"
|
|
166
|
-
class:disabled
|
|
167
|
-
class:horizontal={!vertical}
|
|
168
|
-
class:vertical
|
|
169
|
-
role="slider"
|
|
170
|
-
aria-valuemin={0}
|
|
171
|
-
aria-valuenow={value}
|
|
172
|
-
aria-valuemax={max}
|
|
173
|
-
tabindex={!disabled ? 0 : undefined}
|
|
174
|
-
{...$$restProps}
|
|
175
|
-
on:keydown={onKeyDown}
|
|
176
|
-
on:pointerdown={onPointerDown}
|
|
177
|
-
on:pointermove={onPointerMove}
|
|
178
|
-
on:pointerup={onPointerUp}
|
|
179
|
-
>
|
|
180
|
-
<div
|
|
181
|
-
class="container"
|
|
182
|
-
bind:this={sliderRef}
|
|
183
|
-
bind:clientWidth={sliderWidth}
|
|
184
|
-
bind:clientHeight={sliderHeight}
|
|
185
|
-
>
|
|
186
|
-
<div class="track" />
|
|
187
|
-
<div class="fill" style={vertical ? `height: ${valueOffset}px` : `width: ${valueOffset}px`} />
|
|
188
|
-
<div class="thumb" style={vertical ? `bottom: ${valueOffset}px` : `left: ${valueOffset}px`} />
|
|
189
|
-
</div>
|
|
190
|
-
</div>
|
|
191
|
-
{/if}
|
|
127
|
+
<div class="sterling-slider" class:vertical>
|
|
128
|
+
{#if $$slots.label}
|
|
129
|
+
<div class="label">
|
|
130
|
+
<Label {disabled} for={inputId}>
|
|
131
|
+
<slot name="label" />
|
|
132
|
+
</Label>
|
|
133
|
+
</div>
|
|
134
|
+
{/if}
|
|
135
|
+
<div
|
|
136
|
+
class="slider"
|
|
137
|
+
class:disabled
|
|
138
|
+
class:horizontal={!vertical}
|
|
139
|
+
class:vertical
|
|
140
|
+
id={inputId}
|
|
141
|
+
role="slider"
|
|
142
|
+
aria-valuemin={0}
|
|
143
|
+
aria-valuenow={value}
|
|
144
|
+
aria-valuemax={max}
|
|
145
|
+
tabindex={!disabled ? 0 : undefined}
|
|
146
|
+
{...$$restProps}
|
|
147
|
+
on:keydown={onKeyDown}
|
|
148
|
+
on:pointerdown={onPointerDown}
|
|
149
|
+
on:pointermove={onPointerMove}
|
|
150
|
+
on:pointerup={onPointerUp}
|
|
151
|
+
>
|
|
152
|
+
<div
|
|
153
|
+
class="container"
|
|
154
|
+
bind:this={sliderRef}
|
|
155
|
+
bind:clientWidth={sliderWidth}
|
|
156
|
+
bind:clientHeight={sliderHeight}
|
|
157
|
+
>
|
|
158
|
+
<div class="track" />
|
|
159
|
+
<div class="fill" style={vertical ? `height: ${valueOffset}px` : `width: ${valueOffset}px`} />
|
|
160
|
+
<div class="thumb" style={vertical ? `bottom: ${valueOffset}px` : `left: ${valueOffset}px`} />
|
|
161
|
+
</div>
|
|
162
|
+
</div>
|
|
163
|
+
</div>
|
|
192
164
|
|
|
193
165
|
<style>
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
.sterling-slider-label.vertical {
|
|
201
|
-
justify-items: center;
|
|
202
|
-
height: 100%;
|
|
203
|
-
}
|
|
166
|
+
.sterling-slider {
|
|
167
|
+
display: grid;
|
|
168
|
+
grid-template-columns: 1fr;
|
|
169
|
+
grid-template-rows: auto 1fr;
|
|
170
|
+
}
|
|
204
171
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
172
|
+
.sterling-slider.vertical {
|
|
173
|
+
justify-items: center;
|
|
174
|
+
height: 100%;
|
|
175
|
+
}
|
|
210
176
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
177
|
+
.label {
|
|
178
|
+
font-size: 0.7em;
|
|
179
|
+
}
|
|
214
180
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
181
|
+
.slider {
|
|
182
|
+
box-sizing: border-box;
|
|
183
|
+
outline: none;
|
|
184
|
+
padding: 0;
|
|
185
|
+
overflow: visible;
|
|
186
|
+
display: grid;
|
|
187
|
+
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
188
|
+
}
|
|
223
189
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
190
|
+
.container {
|
|
191
|
+
position: relative;
|
|
192
|
+
}
|
|
227
193
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
194
|
+
.track {
|
|
195
|
+
position: absolute;
|
|
196
|
+
background: var(--Display__background-color);
|
|
197
|
+
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
198
|
+
}
|
|
231
199
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
200
|
+
.fill {
|
|
201
|
+
background: var(--Display__color);
|
|
202
|
+
position: absolute;
|
|
203
|
+
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
204
|
+
}
|
|
236
205
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
206
|
+
.thumb {
|
|
207
|
+
background-color: var(--Button__background-color);
|
|
208
|
+
border-color: var(--Button__border-color);
|
|
209
|
+
border-radius: 10000px;
|
|
210
|
+
border-style: var(--Button__border-style);
|
|
211
|
+
border-width: var(--Button__border-width);
|
|
212
|
+
box-sizing: border-box;
|
|
213
|
+
color: var(--Button__color);
|
|
214
|
+
cursor: pointer;
|
|
215
|
+
display: block;
|
|
216
|
+
font: inherit;
|
|
217
|
+
height: 1.5em;
|
|
218
|
+
overflow: hidden;
|
|
219
|
+
padding: 0;
|
|
220
|
+
text-decoration: none;
|
|
221
|
+
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
222
|
+
white-space: nowrap;
|
|
223
|
+
position: absolute;
|
|
224
|
+
width: 1.5em;
|
|
225
|
+
}
|
|
241
226
|
|
|
242
|
-
|
|
243
|
-
background-color: var(--Button__background-color);
|
|
244
|
-
border-color: var(--Button__border-color);
|
|
245
|
-
border-radius: 10000px;
|
|
246
|
-
border-style: var(--Button__border-style);
|
|
247
|
-
border-width: var(--Button__border-width);
|
|
248
|
-
box-sizing: border-box;
|
|
249
|
-
color: var(--Button__color);
|
|
250
|
-
cursor: pointer;
|
|
251
|
-
display: block;
|
|
252
|
-
font: inherit;
|
|
253
|
-
height: 1.5em;
|
|
254
|
-
overflow: hidden;
|
|
255
|
-
padding: 0;
|
|
256
|
-
text-decoration: none;
|
|
257
|
-
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
258
|
-
white-space: nowrap;
|
|
259
|
-
position: absolute;
|
|
260
|
-
width: 1.5em;
|
|
261
|
-
}
|
|
227
|
+
/* ----- horizontal ----- */
|
|
262
228
|
|
|
263
|
-
|
|
229
|
+
.slider.horizontal {
|
|
230
|
+
height: 2em;
|
|
231
|
+
}
|
|
264
232
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
233
|
+
.slider.horizontal .container {
|
|
234
|
+
margin: 0 0.75em;
|
|
235
|
+
}
|
|
268
236
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
237
|
+
.slider.horizontal .track {
|
|
238
|
+
left: 0;
|
|
239
|
+
right: 0;
|
|
240
|
+
top: 50%;
|
|
241
|
+
height: 3px;
|
|
242
|
+
transform: translate(0, -50%);
|
|
243
|
+
}
|
|
272
244
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
transform: translate(0, -50%);
|
|
279
|
-
}
|
|
245
|
+
.slider.horizontal .fill {
|
|
246
|
+
height: 3px;
|
|
247
|
+
top: 50%;
|
|
248
|
+
transform: translate(0, -50%);
|
|
249
|
+
}
|
|
280
250
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
}
|
|
251
|
+
.slider.horizontal .thumb {
|
|
252
|
+
top: 50%;
|
|
253
|
+
transform: translate(-50%, -50%);
|
|
254
|
+
}
|
|
286
255
|
|
|
287
|
-
|
|
288
|
-
top: 50%;
|
|
289
|
-
transform: translate(-50%, -50%);
|
|
290
|
-
}
|
|
256
|
+
/* ----- vertical ----- */
|
|
291
257
|
|
|
292
|
-
|
|
258
|
+
.slider.vertical {
|
|
259
|
+
width: 2em;
|
|
260
|
+
}
|
|
261
|
+
.slider.vertical .container {
|
|
262
|
+
margin: 0.75em 0;
|
|
263
|
+
}
|
|
293
264
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
265
|
+
.slider.vertical .track {
|
|
266
|
+
bottom: 0;
|
|
267
|
+
left: 50%;
|
|
268
|
+
top: 0;
|
|
269
|
+
transform: translate(-50%, 0);
|
|
270
|
+
width: 3px;
|
|
271
|
+
}
|
|
300
272
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
}
|
|
273
|
+
.slider.vertical .fill {
|
|
274
|
+
bottom: 0;
|
|
275
|
+
left: 50%;
|
|
276
|
+
transform: translate(-50%, 0);
|
|
277
|
+
width: 3px;
|
|
278
|
+
}
|
|
308
279
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
width: 3px;
|
|
314
|
-
}
|
|
280
|
+
.slider.vertical .thumb {
|
|
281
|
+
left: 50%;
|
|
282
|
+
transform: translate(-50%, 50%);
|
|
283
|
+
}
|
|
315
284
|
|
|
316
|
-
|
|
317
|
-
left: 50%;
|
|
318
|
-
transform: translate(-50%, 50%);
|
|
319
|
-
}
|
|
285
|
+
/* ----- hover ----- */
|
|
320
286
|
|
|
321
|
-
|
|
287
|
+
.thumb:hover {
|
|
288
|
+
background-color: var(--Button__background-color--hover);
|
|
289
|
+
border-color: var(--Button__border-color--hover);
|
|
290
|
+
color: var(--Button__color--hover);
|
|
291
|
+
}
|
|
322
292
|
|
|
323
|
-
|
|
324
|
-
background-color: var(--Button__background-color--hover);
|
|
325
|
-
border-color: var(--Button__border-color--hover);
|
|
326
|
-
color: var(--Button__color--hover);
|
|
327
|
-
}
|
|
293
|
+
/* ----- active ----- */
|
|
328
294
|
|
|
329
|
-
|
|
295
|
+
.thumb:active {
|
|
296
|
+
background-color: var(--Button__background-color--active);
|
|
297
|
+
border-color: var(--Button__border-color--active);
|
|
298
|
+
color: var(--Button__color--active);
|
|
299
|
+
}
|
|
330
300
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
301
|
+
/* ----- focus ----- */
|
|
302
|
+
.slider:focus-visible {
|
|
303
|
+
outline-color: var(--Common__outline-color);
|
|
304
|
+
outline-offset: var(--Common__outline-offset);
|
|
305
|
+
outline-style: var(--Common__outline-style);
|
|
306
|
+
outline-width: var(--Common__outline-width);
|
|
307
|
+
}
|
|
308
|
+
/* ----- disabled ----- */
|
|
336
309
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
outline-offset: var(--Common__outline-offset);
|
|
341
|
-
outline-style: var(--Common__outline-style);
|
|
342
|
-
outline-width: var(--Common__outline-width);
|
|
343
|
-
}
|
|
344
|
-
/* ----- disabled ----- */
|
|
310
|
+
.slider.disabled .track {
|
|
311
|
+
background: var(--Common__background-color--disabled);
|
|
312
|
+
}
|
|
345
313
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
314
|
+
.slider.disabled .fill {
|
|
315
|
+
background: var(--Common__color--disabled);
|
|
316
|
+
}
|
|
349
317
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
318
|
+
.slider.disabled .thumb {
|
|
319
|
+
background-color: var(--Common__background-color--disabled);
|
|
320
|
+
border-color: var(--Common__border-color--disabled);
|
|
321
|
+
color: var(--Common__color--disabled);
|
|
322
|
+
cursor: not-allowed;
|
|
323
|
+
}
|
|
353
324
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
325
|
+
@media (prefers-reduced-motion) {
|
|
326
|
+
.slider,
|
|
327
|
+
.track,
|
|
328
|
+
.fill,
|
|
329
|
+
.thumb {
|
|
330
|
+
transition: none;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
360
333
|
</style>
|