@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.
@@ -1,5 +1,7 @@
1
- <script>import { round } from "lodash-es";
2
- import { createEventDispatcher } from "svelte";
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
- {#if $$slots.label}
125
- <label class="sterling-slider-label" class:vertical>
126
- <div class="label-content" class:disabled>
127
- <slot name="label" />
128
- </div>
129
- <div
130
- class="sterling-slider labeled"
131
- class:disabled
132
- class:horizontal={!vertical}
133
- class:vertical
134
- role="slider"
135
- aria-valuemin={0}
136
- aria-valuenow={value}
137
- aria-valuemax={max}
138
- tabindex={!disabled ? 0 : undefined}
139
- {...$$restProps}
140
- on:keydown={onKeyDown}
141
- on:pointerdown={onPointerDown}
142
- on:pointermove={onPointerMove}
143
- on:pointerup={onPointerUp}
144
- >
145
- <div
146
- class="container"
147
- bind:this={sliderRef}
148
- bind:clientWidth={sliderWidth}
149
- bind:clientHeight={sliderHeight}
150
- >
151
- <div class="track" />
152
- <div
153
- class="fill"
154
- style={vertical ? `height: ${valueOffset}px` : `width: ${valueOffset}px`}
155
- />
156
- <div
157
- class="thumb"
158
- style={vertical ? `bottom: ${valueOffset}px` : `left: ${valueOffset}px`}
159
- />
160
- </div>
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
- .sterling-slider-label {
195
- display: grid;
196
- grid-template-columns: 1fr;
197
- grid-template-rows: auto 1fr;
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
- .label-content {
206
- font-size: 0.7em;
207
- color: var(--Display__color--subtle);
208
- transition: background-color 250ms, color 250ms, border-color 250ms;
209
- }
172
+ .sterling-slider.vertical {
173
+ justify-items: center;
174
+ height: 100%;
175
+ }
210
176
 
211
- .label-content.disabled {
212
- color: var(--Display__color--disabled);
213
- }
177
+ .label {
178
+ font-size: 0.7em;
179
+ }
214
180
 
215
- .sterling-slider {
216
- box-sizing: border-box;
217
- outline: none;
218
- padding: 0;
219
- overflow: visible;
220
- display: grid;
221
- height: 100%;
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
- .sterling-slider.labeled {
225
- height: unset;
226
- }
190
+ .container {
191
+ position: relative;
192
+ }
227
193
 
228
- .container {
229
- position: relative;
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
- .track {
233
- position: absolute;
234
- background: var(--Display__background-color);
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
- .fill {
238
- background: var(--Display__color);
239
- position: absolute;
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
- .thumb {
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
- /* ----- horizontal ----- */
229
+ .slider.horizontal {
230
+ height: 2em;
231
+ }
264
232
 
265
- .sterling-slider.horizontal {
266
- height: 2em;
267
- }
233
+ .slider.horizontal .container {
234
+ margin: 0 0.75em;
235
+ }
268
236
 
269
- .sterling-slider.horizontal .container {
270
- margin: 0 0.75em;
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
- .sterling-slider.horizontal .track {
274
- left: 0;
275
- right: 0;
276
- top: 50%;
277
- height: 3px;
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
- .sterling-slider.horizontal .fill {
282
- height: 3px;
283
- top: 50%;
284
- transform: translate(0, -50%);
285
- }
251
+ .slider.horizontal .thumb {
252
+ top: 50%;
253
+ transform: translate(-50%, -50%);
254
+ }
286
255
 
287
- .sterling-slider.horizontal .thumb {
288
- top: 50%;
289
- transform: translate(-50%, -50%);
290
- }
256
+ /* ----- vertical ----- */
291
257
 
292
- /* ----- vertical ----- */
258
+ .slider.vertical {
259
+ width: 2em;
260
+ }
261
+ .slider.vertical .container {
262
+ margin: 0.75em 0;
263
+ }
293
264
 
294
- .sterling-slider.vertical {
295
- width: 2em;
296
- }
297
- .sterling-slider.vertical .container {
298
- margin: 0.75em 0;
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
- .sterling-slider.vertical .track {
302
- bottom: 0;
303
- left: 50%;
304
- top: 0;
305
- transform: translate(-50%, 0);
306
- width: 3px;
307
- }
273
+ .slider.vertical .fill {
274
+ bottom: 0;
275
+ left: 50%;
276
+ transform: translate(-50%, 0);
277
+ width: 3px;
278
+ }
308
279
 
309
- .sterling-slider.vertical .fill {
310
- bottom: 0;
311
- left: 50%;
312
- transform: translate(-50%, 0);
313
- width: 3px;
314
- }
280
+ .slider.vertical .thumb {
281
+ left: 50%;
282
+ transform: translate(-50%, 50%);
283
+ }
315
284
 
316
- .sterling-slider.vertical .thumb {
317
- left: 50%;
318
- transform: translate(-50%, 50%);
319
- }
285
+ /* ----- hover ----- */
320
286
 
321
- /* ----- hover ----- */
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
- .thumb:hover {
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
- /* ----- active ----- */
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
- .thumb:active {
332
- background-color: var(--Button__background-color--active);
333
- border-color: var(--Button__border-color--active);
334
- color: var(--Button__color--active);
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
- /* ----- focus ----- */
338
- .sterling-slider:focus-visible {
339
- outline-color: var(--Common__outline-color);
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
- .sterling-slider.disabled .track {
347
- background: var(--Common__background-color--disabled);
348
- }
314
+ .slider.disabled .fill {
315
+ background: var(--Common__color--disabled);
316
+ }
349
317
 
350
- .sterling-slider.disabled .fill {
351
- background: var(--Common__color--disabled);
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
- .sterling-slider.disabled .thumb {
355
- background-color: var(--Common__background-color--disabled);
356
- border-color: var(--Common__border-color--disabled);
357
- color: var(--Common__color--disabled);
358
- cursor: not-allowed;
359
- }
325
+ @media (prefers-reduced-motion) {
326
+ .slider,
327
+ .track,
328
+ .fill,
329
+ .thumb {
330
+ transition: none;
331
+ }
332
+ }
360
333
  </style>