@geoffcox/sterling-svelte 0.0.17 → 0.0.19
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/Checkbox.svelte +11 -6
- package/Checkbox.svelte.d.ts +2 -1
- package/Dropdown.svelte +241 -0
- package/Dropdown.svelte.d.ts +58 -0
- package/Field.svelte +257 -0
- package/Field.svelte.d.ts +63 -0
- package/Field.types.d.ts +1 -0
- package/Field.types.js +1 -0
- package/Input.svelte +58 -72
- package/Input.svelte.d.ts +8 -3
- package/Label.svelte +5 -6
- package/Label.svelte.d.ts +0 -1
- package/List.svelte +47 -78
- package/List.svelte.d.ts +0 -6
- package/ListItem.svelte +0 -1
- package/Progress.svelte +20 -44
- package/Progress.svelte.d.ts +1 -3
- package/Progress.types.d.ts +1 -1
- package/Radio.svelte +19 -14
- package/Radio.svelte.d.ts +7 -2
- package/Select.svelte +30 -42
- package/Select.svelte.d.ts +1 -5
- package/Slider.svelte +83 -92
- package/Slider.svelte.d.ts +5 -6
- package/Switch.svelte +30 -22
- package/Switch.svelte.d.ts +4 -4
- package/TextArea.svelte +49 -90
- package/TextArea.svelte.d.ts +3 -6
- package/Tree.svelte +12 -40
- package/Tree.svelte.d.ts +0 -1
- package/index.d.ts +5 -2
- package/index.js +4 -2
- package/package.json +4 -2
- package/theme/colors.d.ts +53 -1
- package/theme/colors.js +53 -1
- package/theme/darkTheme.js +62 -55
- package/theme/lightTheme.js +65 -58
- package/Portal.svelte +0 -14
- package/Portal.svelte.d.ts +0 -21
package/Select.svelte
CHANGED
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
import { createEventDispatcher, onMount, tick } from "svelte";
|
|
3
3
|
import { v4 as uuid } from "uuid";
|
|
4
4
|
import { clickOutside } from "./actions/clickOutside";
|
|
5
|
-
import Label from "./Label.svelte";
|
|
6
5
|
import List from "./List.svelte";
|
|
7
|
-
const inputId = uuid();
|
|
8
6
|
const popupId = uuid();
|
|
7
|
+
export let composed = false;
|
|
9
8
|
export let disabled = false;
|
|
10
9
|
export let open = false;
|
|
11
10
|
export let selectedValue = void 0;
|
|
@@ -147,16 +146,13 @@ const onListSelect = (event) => {
|
|
|
147
146
|
};
|
|
148
147
|
</script>
|
|
149
148
|
|
|
150
|
-
<!--
|
|
151
|
-
@component
|
|
152
|
-
A single item that can be selected from a popup list of items.
|
|
153
|
-
-->
|
|
154
149
|
<div
|
|
155
150
|
bind:this={selectRef}
|
|
156
151
|
aria-controls={popupId}
|
|
157
152
|
aria-haspopup="listbox"
|
|
158
153
|
aria-expanded={open}
|
|
159
154
|
class="sterling-select"
|
|
155
|
+
class:composed
|
|
160
156
|
class:disabled
|
|
161
157
|
role="combobox"
|
|
162
158
|
tabindex="0"
|
|
@@ -186,26 +182,19 @@ A single item that can be selected from a popup list of items.
|
|
|
186
182
|
on:keydown={onSelectKeydown}
|
|
187
183
|
{...$$restProps}
|
|
188
184
|
>
|
|
189
|
-
|
|
190
|
-
<
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
</slot>
|
|
203
|
-
</div>
|
|
204
|
-
<div class="button">
|
|
205
|
-
<slot name="button" {open}>
|
|
206
|
-
<div class="chevron" />
|
|
207
|
-
</slot>
|
|
208
|
-
</div>
|
|
185
|
+
<div class="value">
|
|
186
|
+
<slot name="value" {disabled} {open} {selectedValue}>
|
|
187
|
+
{#if selectedValue}
|
|
188
|
+
{selectedValue}
|
|
189
|
+
{:else}
|
|
190
|
+
<span> </span>
|
|
191
|
+
{/if}
|
|
192
|
+
</slot>
|
|
193
|
+
</div>
|
|
194
|
+
<div class="button">
|
|
195
|
+
<slot name="button" {open}>
|
|
196
|
+
<div class="chevron" />
|
|
197
|
+
</slot>
|
|
209
198
|
</div>
|
|
210
199
|
<div
|
|
211
200
|
bind:this={popupRef}
|
|
@@ -232,6 +221,8 @@ A single item that can be selected from a popup list of items.
|
|
|
232
221
|
|
|
233
222
|
<style>
|
|
234
223
|
.sterling-select {
|
|
224
|
+
align-content: center;
|
|
225
|
+
align-items: center;
|
|
235
226
|
background-color: var(--stsv-Input__background-color);
|
|
236
227
|
border-color: var(--stsv-Input__border-color);
|
|
237
228
|
border-radius: var(--stsv-Input__border-radius);
|
|
@@ -239,6 +230,10 @@ A single item that can be selected from a popup list of items.
|
|
|
239
230
|
border-width: var(--stsv-Input__border-width);
|
|
240
231
|
color: var(--stsv-Input__color);
|
|
241
232
|
cursor: pointer;
|
|
233
|
+
display: grid;
|
|
234
|
+
grid-template-columns: 1fr auto;
|
|
235
|
+
grid-template-rows: auto;
|
|
236
|
+
outline: none;
|
|
242
237
|
padding: 0;
|
|
243
238
|
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
244
239
|
}
|
|
@@ -249,7 +244,7 @@ A single item that can be selected from a popup list of items.
|
|
|
249
244
|
color: var(--stsv-Input__color--hover);
|
|
250
245
|
}
|
|
251
246
|
|
|
252
|
-
.sterling-select:focus
|
|
247
|
+
.sterling-select:focus {
|
|
253
248
|
background-color: var(--stsv-Input__background-color--focus);
|
|
254
249
|
border-color: var(--stsv-Input__border-color--focus);
|
|
255
250
|
color: var(--stsv-Input__color--focus);
|
|
@@ -267,21 +262,13 @@ A single item that can be selected from a popup list of items.
|
|
|
267
262
|
outline: none;
|
|
268
263
|
}
|
|
269
264
|
|
|
270
|
-
.sterling-select
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
.input {
|
|
280
|
-
display: grid;
|
|
281
|
-
grid-template-columns: 1fr auto;
|
|
282
|
-
grid-template-rows: auto;
|
|
283
|
-
align-content: center;
|
|
284
|
-
align-items: center;
|
|
265
|
+
.sterling-select.composed,
|
|
266
|
+
.sterling-select.composed:hover,
|
|
267
|
+
.sterling-select.composed.focus,
|
|
268
|
+
.sterling-select.composed.disabled {
|
|
269
|
+
background: none;
|
|
270
|
+
border: none;
|
|
271
|
+
outline: none;
|
|
285
272
|
}
|
|
286
273
|
|
|
287
274
|
.value {
|
|
@@ -329,6 +316,7 @@ A single item that can be selected from a popup list of items.
|
|
|
329
316
|
box-sizing: border-box;
|
|
330
317
|
display: none;
|
|
331
318
|
overflow: visible;
|
|
319
|
+
outline: none;
|
|
332
320
|
position: absolute;
|
|
333
321
|
box-shadow: rgba(0, 0, 0, 0.4) 2px 2px 4px -1px;
|
|
334
322
|
width: fit-content;
|
package/Select.svelte.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { SvelteComponentTyped } from "svelte";
|
|
|
2
2
|
declare const __propDef: {
|
|
3
3
|
props: {
|
|
4
4
|
[x: string]: any;
|
|
5
|
+
composed?: boolean | undefined;
|
|
5
6
|
disabled?: boolean | undefined;
|
|
6
7
|
open?: boolean | undefined;
|
|
7
8
|
selectedValue?: string | undefined;
|
|
@@ -33,10 +34,6 @@ declare const __propDef: {
|
|
|
33
34
|
[evt: string]: CustomEvent<any>;
|
|
34
35
|
};
|
|
35
36
|
slots: {
|
|
36
|
-
label: {
|
|
37
|
-
disabled: boolean;
|
|
38
|
-
selectedValue: string | undefined;
|
|
39
|
-
};
|
|
40
37
|
value: {
|
|
41
38
|
disabled: boolean;
|
|
42
39
|
open: boolean;
|
|
@@ -51,7 +48,6 @@ declare const __propDef: {
|
|
|
51
48
|
export type SelectProps = typeof __propDef.props;
|
|
52
49
|
export type SelectEvents = typeof __propDef.events;
|
|
53
50
|
export type SelectSlots = typeof __propDef.slots;
|
|
54
|
-
/** A single item that can be selected from a popup list of items. */
|
|
55
51
|
export default class Select extends SvelteComponentTyped<SelectProps, SelectEvents, SelectSlots> {
|
|
56
52
|
}
|
|
57
53
|
export {};
|
package/Slider.svelte
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
<script>import { createEventDispatcher } from "svelte";
|
|
2
2
|
import { round } from "lodash-es";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export let value = 0;
|
|
3
|
+
export let composed = false;
|
|
4
|
+
export let disabled = false;
|
|
6
5
|
export let min = 0;
|
|
7
6
|
export let max = 100;
|
|
8
|
-
export let step = void 0;
|
|
9
7
|
export let precision = 0;
|
|
8
|
+
export let step = void 0;
|
|
9
|
+
export let value = 0;
|
|
10
10
|
export let vertical = false;
|
|
11
|
-
export let disabled = false;
|
|
12
|
-
const inputId = uuid();
|
|
13
11
|
let sliderRef;
|
|
14
12
|
const dispatch = createEventDispatcher();
|
|
15
13
|
const raiseChange = (newValue) => {
|
|
@@ -124,84 +122,63 @@ const onKeyDown = (event) => {
|
|
|
124
122
|
<!-- @component
|
|
125
123
|
Slider lets the user chose a value within a min/max range by dragging a thumb button.
|
|
126
124
|
-->
|
|
127
|
-
<div
|
|
128
|
-
{
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
125
|
+
<div
|
|
126
|
+
aria-disabled={disabled}
|
|
127
|
+
aria-valuemin={0}
|
|
128
|
+
aria-valuenow={value}
|
|
129
|
+
aria-valuemax={max}
|
|
130
|
+
class="sterling-slider"
|
|
131
|
+
class:composed
|
|
132
|
+
class:disabled
|
|
133
|
+
class:horizontal={!vertical}
|
|
134
|
+
class:vertical
|
|
135
|
+
role="slider"
|
|
136
|
+
tabindex={!disabled ? 0 : undefined}
|
|
137
|
+
on:blur
|
|
138
|
+
on:click
|
|
139
|
+
on:dblclick
|
|
140
|
+
on:focus
|
|
141
|
+
on:focusin
|
|
142
|
+
on:focusout
|
|
143
|
+
on:keydown
|
|
144
|
+
on:keydown={onKeyDown}
|
|
145
|
+
on:keypress
|
|
146
|
+
on:keyup
|
|
147
|
+
on:mousedown
|
|
148
|
+
on:mouseenter
|
|
149
|
+
on:mouseleave
|
|
150
|
+
on:mousemove
|
|
151
|
+
on:mouseover
|
|
152
|
+
on:mouseout
|
|
153
|
+
on:mouseup
|
|
154
|
+
on:pointercancel
|
|
155
|
+
on:pointerdown
|
|
156
|
+
on:pointerdown={onPointerDown}
|
|
157
|
+
on:pointerenter
|
|
158
|
+
on:pointerleave
|
|
159
|
+
on:pointermove
|
|
160
|
+
on:pointermove={onPointerMove}
|
|
161
|
+
on:pointerover
|
|
162
|
+
on:pointerout
|
|
163
|
+
on:pointerup
|
|
164
|
+
on:pointerup={onPointerUp}
|
|
165
|
+
on:wheel
|
|
166
|
+
{...$$restProps}
|
|
167
|
+
>
|
|
133
168
|
<div
|
|
134
|
-
class="
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
id={inputId}
|
|
139
|
-
role="slider"
|
|
140
|
-
aria-valuemin={0}
|
|
141
|
-
aria-valuenow={value}
|
|
142
|
-
aria-valuemax={max}
|
|
143
|
-
tabindex={!disabled ? 0 : undefined}
|
|
144
|
-
on:blur
|
|
145
|
-
on:click
|
|
146
|
-
on:dblclick
|
|
147
|
-
on:focus
|
|
148
|
-
on:focusin
|
|
149
|
-
on:focusout
|
|
150
|
-
on:keydown
|
|
151
|
-
on:keydown={onKeyDown}
|
|
152
|
-
on:keypress
|
|
153
|
-
on:keyup
|
|
154
|
-
on:mousedown
|
|
155
|
-
on:mouseenter
|
|
156
|
-
on:mouseleave
|
|
157
|
-
on:mousemove
|
|
158
|
-
on:mouseover
|
|
159
|
-
on:mouseout
|
|
160
|
-
on:mouseup
|
|
161
|
-
on:pointercancel
|
|
162
|
-
on:pointerdown
|
|
163
|
-
on:pointerdown={onPointerDown}
|
|
164
|
-
on:pointerenter
|
|
165
|
-
on:pointerleave
|
|
166
|
-
on:pointermove
|
|
167
|
-
on:pointermove={onPointerMove}
|
|
168
|
-
on:pointerover
|
|
169
|
-
on:pointerout
|
|
170
|
-
on:pointerup
|
|
171
|
-
on:pointerup={onPointerUp}
|
|
172
|
-
on:wheel
|
|
173
|
-
{...$$restProps}
|
|
169
|
+
class="container"
|
|
170
|
+
bind:this={sliderRef}
|
|
171
|
+
bind:clientWidth={sliderWidth}
|
|
172
|
+
bind:clientHeight={sliderHeight}
|
|
174
173
|
>
|
|
175
|
-
<div
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
bind:clientWidth={sliderWidth}
|
|
179
|
-
bind:clientHeight={sliderHeight}
|
|
180
|
-
>
|
|
181
|
-
<div class="track" />
|
|
182
|
-
<div class="fill" style={vertical ? `height: ${valueOffset}px` : `width: ${valueOffset}px`} />
|
|
183
|
-
<div class="thumb" style={vertical ? `bottom: ${valueOffset}px` : `left: ${valueOffset}px`} />
|
|
184
|
-
</div>
|
|
174
|
+
<div class="track" />
|
|
175
|
+
<div class="fill" style={vertical ? `height: ${valueOffset}px` : `width: ${valueOffset}px`} />
|
|
176
|
+
<div class="thumb" style={vertical ? `bottom: ${valueOffset}px` : `left: ${valueOffset}px`} />
|
|
185
177
|
</div>
|
|
186
178
|
</div>
|
|
187
179
|
|
|
188
180
|
<style>
|
|
189
181
|
.sterling-slider {
|
|
190
|
-
display: grid;
|
|
191
|
-
grid-template-columns: 1fr;
|
|
192
|
-
grid-template-rows: auto 1fr;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
.sterling-slider.vertical {
|
|
196
|
-
justify-items: center;
|
|
197
|
-
height: 100%;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
.sterling-slider > :global(label) {
|
|
201
|
-
font-size: 0.7em;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
.slider {
|
|
205
182
|
box-sizing: border-box;
|
|
206
183
|
outline: none;
|
|
207
184
|
padding: 0;
|
|
@@ -210,6 +187,10 @@ Slider lets the user chose a value within a min/max range by dragging a thumb bu
|
|
|
210
187
|
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
211
188
|
}
|
|
212
189
|
|
|
190
|
+
.sterling-slider.vertical {
|
|
191
|
+
height: 100%;
|
|
192
|
+
}
|
|
193
|
+
|
|
213
194
|
.container {
|
|
214
195
|
position: relative;
|
|
215
196
|
}
|
|
@@ -249,15 +230,15 @@ Slider lets the user chose a value within a min/max range by dragging a thumb bu
|
|
|
249
230
|
|
|
250
231
|
/* ----- horizontal ----- */
|
|
251
232
|
|
|
252
|
-
.slider.horizontal {
|
|
233
|
+
.sterling-slider.horizontal {
|
|
253
234
|
height: 2em;
|
|
254
235
|
}
|
|
255
236
|
|
|
256
|
-
.slider.horizontal .container {
|
|
237
|
+
.sterling-slider.horizontal .container {
|
|
257
238
|
margin: 0 0.75em;
|
|
258
239
|
}
|
|
259
240
|
|
|
260
|
-
.slider.horizontal .track {
|
|
241
|
+
.sterling-slider.horizontal .track {
|
|
261
242
|
left: 0;
|
|
262
243
|
right: 0;
|
|
263
244
|
top: 50%;
|
|
@@ -265,27 +246,27 @@ Slider lets the user chose a value within a min/max range by dragging a thumb bu
|
|
|
265
246
|
transform: translate(0, -50%);
|
|
266
247
|
}
|
|
267
248
|
|
|
268
|
-
.slider.horizontal .fill {
|
|
249
|
+
.sterling-slider.horizontal .fill {
|
|
269
250
|
height: 3px;
|
|
270
251
|
top: 50%;
|
|
271
252
|
transform: translate(0, -50%);
|
|
272
253
|
}
|
|
273
254
|
|
|
274
|
-
.slider.horizontal .thumb {
|
|
255
|
+
.sterling-slider.horizontal .thumb {
|
|
275
256
|
top: 50%;
|
|
276
257
|
transform: translate(-50%, -50%);
|
|
277
258
|
}
|
|
278
259
|
|
|
279
260
|
/* ----- vertical ----- */
|
|
280
261
|
|
|
281
|
-
.slider.vertical {
|
|
262
|
+
.sterling-slider.vertical {
|
|
282
263
|
width: 2em;
|
|
283
264
|
}
|
|
284
|
-
.slider.vertical .container {
|
|
265
|
+
.sterling-slider.vertical .container {
|
|
285
266
|
margin: 0.75em 0;
|
|
286
267
|
}
|
|
287
268
|
|
|
288
|
-
.slider.vertical .track {
|
|
269
|
+
.sterling-slider.vertical .track {
|
|
289
270
|
bottom: 0;
|
|
290
271
|
left: 50%;
|
|
291
272
|
top: 0;
|
|
@@ -293,14 +274,14 @@ Slider lets the user chose a value within a min/max range by dragging a thumb bu
|
|
|
293
274
|
width: 3px;
|
|
294
275
|
}
|
|
295
276
|
|
|
296
|
-
.slider.vertical .fill {
|
|
277
|
+
.sterling-slider.vertical .fill {
|
|
297
278
|
bottom: 0;
|
|
298
279
|
left: 50%;
|
|
299
280
|
transform: translate(-50%, 0);
|
|
300
281
|
width: 3px;
|
|
301
282
|
}
|
|
302
283
|
|
|
303
|
-
.slider.vertical .thumb {
|
|
284
|
+
.sterling-slider.vertical .thumb {
|
|
304
285
|
left: 50%;
|
|
305
286
|
transform: translate(-50%, 50%);
|
|
306
287
|
}
|
|
@@ -322,31 +303,41 @@ Slider lets the user chose a value within a min/max range by dragging a thumb bu
|
|
|
322
303
|
}
|
|
323
304
|
|
|
324
305
|
/* ----- focus ----- */
|
|
325
|
-
.slider:focus-visible {
|
|
306
|
+
.sterling-slider:focus-visible {
|
|
326
307
|
outline-color: var(--stsv-Common__outline-color);
|
|
327
308
|
outline-offset: var(--stsv-Common__outline-offset);
|
|
328
309
|
outline-style: var(--stsv-Common__outline-style);
|
|
329
310
|
outline-width: var(--stsv-Common__outline-width);
|
|
330
311
|
}
|
|
312
|
+
|
|
331
313
|
/* ----- disabled ----- */
|
|
332
314
|
|
|
333
|
-
.slider.disabled .track {
|
|
315
|
+
.sterling-slider.disabled .track {
|
|
334
316
|
background: var(--stsv-Common__background-color--disabled);
|
|
335
317
|
}
|
|
336
318
|
|
|
337
|
-
.slider.disabled .fill {
|
|
319
|
+
.sterling-slider.disabled .fill {
|
|
338
320
|
background: var(--stsv-Common__color--disabled);
|
|
339
321
|
}
|
|
340
322
|
|
|
341
|
-
.slider.disabled .thumb {
|
|
323
|
+
.sterling-slider.disabled .thumb {
|
|
342
324
|
background-color: var(--stsv-Common__background-color--disabled);
|
|
343
325
|
border-color: var(--stsv-Common__border-color--disabled);
|
|
344
326
|
color: var(--stsv-Common__color--disabled);
|
|
345
327
|
cursor: not-allowed;
|
|
346
328
|
}
|
|
347
329
|
|
|
330
|
+
.sterling-slider.composed,
|
|
331
|
+
.sterling-slider.composed:hover,
|
|
332
|
+
.sterling-slider.composed.focus,
|
|
333
|
+
.sterling-slider.composed.disabled {
|
|
334
|
+
background: none;
|
|
335
|
+
border: none;
|
|
336
|
+
outline: none;
|
|
337
|
+
}
|
|
338
|
+
|
|
348
339
|
@media (prefers-reduced-motion) {
|
|
349
|
-
.slider,
|
|
340
|
+
.sterling-slider,
|
|
350
341
|
.track,
|
|
351
342
|
.fill,
|
|
352
343
|
.thumb {
|
package/Slider.svelte.d.ts
CHANGED
|
@@ -2,13 +2,14 @@ import { SvelteComponentTyped } from "svelte";
|
|
|
2
2
|
declare const __propDef: {
|
|
3
3
|
props: {
|
|
4
4
|
[x: string]: any;
|
|
5
|
-
|
|
5
|
+
composed?: boolean | undefined;
|
|
6
|
+
disabled?: boolean | undefined;
|
|
6
7
|
min?: number | undefined;
|
|
7
8
|
max?: number | undefined;
|
|
8
|
-
step?: number | undefined;
|
|
9
9
|
precision?: number | undefined;
|
|
10
|
+
step?: number | undefined;
|
|
11
|
+
value?: number | undefined;
|
|
10
12
|
vertical?: boolean | undefined;
|
|
11
|
-
disabled?: boolean | undefined;
|
|
12
13
|
};
|
|
13
14
|
events: {
|
|
14
15
|
blur: FocusEvent;
|
|
@@ -40,9 +41,7 @@ declare const __propDef: {
|
|
|
40
41
|
} & {
|
|
41
42
|
[evt: string]: CustomEvent<any>;
|
|
42
43
|
};
|
|
43
|
-
slots: {
|
|
44
|
-
label: {};
|
|
45
|
-
};
|
|
44
|
+
slots: {};
|
|
46
45
|
};
|
|
47
46
|
export type SliderProps = typeof __propDef.props;
|
|
48
47
|
export type SliderEvents = typeof __propDef.events;
|
package/Switch.svelte
CHANGED
|
@@ -3,8 +3,8 @@ import Label from "./Label.svelte";
|
|
|
3
3
|
export let checked = false;
|
|
4
4
|
export let disabled = false;
|
|
5
5
|
export let vertical = false;
|
|
6
|
-
export let onText =
|
|
7
|
-
export let offText =
|
|
6
|
+
export let onText = void 0;
|
|
7
|
+
export let offText = void 0;
|
|
8
8
|
const inputId = uuid();
|
|
9
9
|
let switchWidth = 0;
|
|
10
10
|
let switchHeight = 0;
|
|
@@ -18,6 +18,10 @@ $:
|
|
|
18
18
|
ratio = vertical ? checked ? 0 : 1 : checked ? 1 : 0;
|
|
19
19
|
$:
|
|
20
20
|
valueOffset = (switchSize - thumbSize) * ratio;
|
|
21
|
+
$:
|
|
22
|
+
hasOffLabel = $$slots.offLabel || offText !== void 0 && offText.length > 0;
|
|
23
|
+
$:
|
|
24
|
+
hasOnLabel = $$slots.onLabel || onText !== void 0 && onText.length > 0;
|
|
21
25
|
</script>
|
|
22
26
|
|
|
23
27
|
<!--
|
|
@@ -26,6 +30,9 @@ $:
|
|
|
26
30
|
-->
|
|
27
31
|
<div class="sterling-switch" class:vertical class:disabled>
|
|
28
32
|
<input
|
|
33
|
+
bind:checked
|
|
34
|
+
{disabled}
|
|
35
|
+
id={inputId}
|
|
29
36
|
type="checkbox"
|
|
30
37
|
on:blur
|
|
31
38
|
on:click
|
|
@@ -47,18 +54,17 @@ $:
|
|
|
47
54
|
on:mouseup
|
|
48
55
|
on:toggle
|
|
49
56
|
on:wheel
|
|
50
|
-
bind:checked
|
|
51
|
-
id={inputId}
|
|
52
|
-
{disabled}
|
|
53
57
|
{...$$restProps}
|
|
54
58
|
/>
|
|
55
|
-
|
|
56
|
-
<
|
|
57
|
-
{
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
{#if hasOffLabel}
|
|
60
|
+
<div class="off-label">
|
|
61
|
+
<slot name="offLabel" {checked} {disabled} {inputId} {offText} {vertical}>
|
|
62
|
+
{#if offText}
|
|
63
|
+
<Label for={inputId} {disabled}>{offText}</Label>
|
|
64
|
+
{/if}
|
|
65
|
+
</slot>
|
|
66
|
+
</div>
|
|
67
|
+
{/if}
|
|
62
68
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
63
69
|
<div class="switch" bind:offsetWidth={switchWidth} bind:offsetHeight={switchHeight}>
|
|
64
70
|
<div
|
|
@@ -68,13 +74,15 @@ $:
|
|
|
68
74
|
style={`--thumb-offset: ${valueOffset}px`}
|
|
69
75
|
/>
|
|
70
76
|
</div>
|
|
71
|
-
|
|
72
|
-
<
|
|
73
|
-
{
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
{#if hasOnLabel}
|
|
78
|
+
<div class="on-label">
|
|
79
|
+
<slot name="onLabel" {checked} {disabled} {inputId} {onText} {vertical}>
|
|
80
|
+
{#if onText}
|
|
81
|
+
<Label for={inputId} {disabled}>{onText}</Label>
|
|
82
|
+
{/if}
|
|
83
|
+
</slot>
|
|
84
|
+
</div>
|
|
85
|
+
{/if}
|
|
78
86
|
</div>
|
|
79
87
|
|
|
80
88
|
<style>
|
|
@@ -87,7 +95,7 @@ $:
|
|
|
87
95
|
.sterling-switch:not(.vertical) {
|
|
88
96
|
align-items: center;
|
|
89
97
|
column-gap: 0.5em;
|
|
90
|
-
grid-template-columns: auto
|
|
98
|
+
grid-template-columns: auto 1fr auto;
|
|
91
99
|
grid-template-rows: auto;
|
|
92
100
|
justify-items: stretch;
|
|
93
101
|
}
|
|
@@ -209,11 +217,11 @@ $:
|
|
|
209
217
|
|
|
210
218
|
.sterling-switch:not(.vertical) .thumb {
|
|
211
219
|
top: calc(-1 * var(--stsv-Button__border-width));
|
|
212
|
-
transform: translateX(calc(var(--
|
|
220
|
+
transform: translateX(calc(var(--thumb-offset) - var(--stsv-Button__border-width)));
|
|
213
221
|
}
|
|
214
222
|
|
|
215
223
|
.sterling-switch.vertical .thumb {
|
|
216
224
|
left: calc(-1 * var(--stsv-Button__border-width));
|
|
217
|
-
transform: translateY(calc(var(--
|
|
225
|
+
transform: translateY(calc(var(--thumb-offset) - var(--stsv-Button__border-width)));
|
|
218
226
|
}
|
|
219
227
|
</style>
|
package/Switch.svelte.d.ts
CHANGED
|
@@ -33,18 +33,18 @@ declare const __propDef: {
|
|
|
33
33
|
[evt: string]: CustomEvent<any>;
|
|
34
34
|
};
|
|
35
35
|
slots: {
|
|
36
|
-
|
|
36
|
+
offLabel: {
|
|
37
37
|
checked: boolean;
|
|
38
38
|
disabled: boolean;
|
|
39
39
|
inputId: string;
|
|
40
|
-
offText: string;
|
|
40
|
+
offText: string | undefined;
|
|
41
41
|
vertical: boolean;
|
|
42
42
|
};
|
|
43
|
-
|
|
43
|
+
onLabel: {
|
|
44
44
|
checked: boolean;
|
|
45
45
|
disabled: boolean;
|
|
46
46
|
inputId: string;
|
|
47
|
-
onText: string;
|
|
47
|
+
onText: string | undefined;
|
|
48
48
|
vertical: boolean;
|
|
49
49
|
};
|
|
50
50
|
};
|