@geoffcox/sterling-svelte 2.0.1 → 2.0.3
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 +1 -1
- package/dist/Button.svelte +18 -14
- package/dist/Button.svelte.d.ts +0 -1
- package/dist/Callout.svelte +162 -96
- package/dist/Callout.svelte.d.ts +1 -2
- package/dist/Checkbox.svelte +34 -15
- package/dist/Checkbox.svelte.d.ts +0 -1
- package/dist/Dialog.svelte +121 -71
- package/dist/Dialog.svelte.d.ts +1 -1
- package/dist/Dropdown.svelte +106 -56
- package/dist/Dropdown.svelte.d.ts +8 -3
- package/dist/Input.svelte +54 -29
- package/dist/Input.svelte.d.ts +1 -2
- package/dist/Label.svelte +99 -55
- package/dist/Label.svelte.d.ts +4 -4
- package/dist/Link.svelte +20 -14
- package/dist/Link.svelte.d.ts +0 -1
- package/dist/List.svelte +181 -126
- package/dist/List.svelte.d.ts +0 -1
- package/dist/ListItem.svelte +36 -21
- package/dist/ListItem.svelte.d.ts +0 -1
- package/dist/Menu.svelte +67 -45
- package/dist/Menu.svelte.d.ts +0 -1
- package/dist/MenuBar.svelte +96 -65
- package/dist/MenuBar.svelte.d.ts +0 -1
- package/dist/MenuButton.svelte +102 -62
- package/dist/MenuButton.svelte.d.ts +1 -1
- package/dist/MenuItem.svelte +332 -243
- package/dist/MenuItem.svelte.d.ts +3 -3
- package/dist/MenuSeparator.svelte +7 -7
- package/dist/MenuSeparator.svelte.d.ts +0 -1
- package/dist/Pagination.svelte +267 -0
- package/dist/Pagination.svelte.d.ts +4 -0
- package/dist/Pagination.types.d.ts +24 -0
- package/dist/Pagination.types.js +1 -0
- package/dist/Popover.svelte +114 -60
- package/dist/Popover.svelte.d.ts +1 -2
- package/dist/Portal.types.d.ts +1 -4
- package/dist/Progress.svelte +40 -15
- package/dist/Progress.svelte.d.ts +0 -1
- package/dist/Radio.svelte +37 -25
- package/dist/Radio.svelte.d.ts +0 -1
- package/dist/Select.svelte +191 -125
- package/dist/Select.svelte.d.ts +8 -2
- package/dist/Slider.svelte +120 -71
- package/dist/Slider.svelte.d.ts +0 -1
- package/dist/Switch.svelte +51 -20
- package/dist/Switch.svelte.d.ts +1 -1
- package/dist/Tab.svelte +39 -24
- package/dist/Tab.svelte.d.ts +0 -1
- package/dist/TabList.svelte +176 -125
- package/dist/TabList.svelte.d.ts +0 -1
- package/dist/TextArea.svelte +83 -41
- package/dist/TextArea.svelte.d.ts +2 -3
- package/dist/Tooltip.svelte +68 -36
- package/dist/Tree.svelte +52 -24
- package/dist/Tree.svelte.d.ts +0 -1
- package/dist/TreeChevron.svelte +24 -12
- package/dist/TreeChevron.svelte.d.ts +0 -1
- package/dist/TreeItem.svelte +292 -225
- package/dist/TreeItem.svelte.d.ts +1 -1
- package/dist/actions/extraClass.d.ts +1 -0
- package/dist/actions/extraClass.js +1 -0
- package/dist/idGenerator.d.ts +1 -0
- package/dist/idGenerator.js +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/mediaQueries/prefersColorSchemeDark.d.ts +0 -1
- package/dist/mediaQueries/prefersReducedMotion.d.ts +0 -1
- package/dist/mediaQueries/usingKeyboard.d.ts +0 -1
- package/package.json +21 -22
package/dist/Radio.svelte.d.ts
CHANGED
package/dist/Select.svelte
CHANGED
|
@@ -1,156 +1,217 @@
|
|
|
1
1
|
<svelte:options runes={true} />
|
|
2
2
|
|
|
3
|
-
<script lang="ts">
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
<script lang="ts">
|
|
4
|
+
import { tick, type Snippet } from 'svelte';
|
|
5
|
+
import type { HTMLAttributes, KeyboardEventHandler, MouseEventHandler } from 'svelte/elements';
|
|
6
|
+
import { clickOutside } from './actions/clickOutside';
|
|
7
|
+
import List from './List.svelte';
|
|
8
|
+
import Popover from './Popover.svelte';
|
|
9
|
+
|
|
10
|
+
const uuid = $props.id();
|
|
11
|
+
|
|
12
|
+
type DeprecatedProps = {
|
|
13
|
+
/** @deprecated Use icon instead */
|
|
14
|
+
buttonSnippet?: Snippet;
|
|
15
|
+
|
|
16
|
+
/** @deprecated Use value instead */
|
|
17
|
+
valueSnippet?: Snippet<[string | undefined]>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type Props = HTMLAttributes<HTMLDivElement> &
|
|
21
|
+
DeprecatedProps & {
|
|
22
|
+
disabled?: boolean | null;
|
|
23
|
+
icon?: Snippet;
|
|
24
|
+
listClass?: string;
|
|
25
|
+
onPending?: (value?: string) => void;
|
|
26
|
+
onSelect?: (value?: string) => void;
|
|
27
|
+
open?: boolean | null;
|
|
28
|
+
selectedValue?: string;
|
|
29
|
+
value?: string | Snippet<[string | undefined]>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
let {
|
|
33
|
+
children,
|
|
34
|
+
class: _class,
|
|
35
|
+
disabled = false,
|
|
36
|
+
icon,
|
|
37
|
+
listClass,
|
|
38
|
+
open = $bindable(false),
|
|
39
|
+
onSelect,
|
|
40
|
+
onPending,
|
|
41
|
+
selectedValue = $bindable(),
|
|
42
|
+
value,
|
|
43
|
+
buttonSnippet,
|
|
44
|
+
valueSnippet,
|
|
45
|
+
...rest
|
|
46
|
+
}: Props = $props();
|
|
47
|
+
|
|
48
|
+
// backwards compatibility
|
|
49
|
+
icon = icon || buttonSnippet;
|
|
50
|
+
value = value || valueSnippet;
|
|
51
|
+
|
|
52
|
+
const popoverId = `Select-Popover-${uuid}`;
|
|
53
|
+
|
|
54
|
+
// ----- State ----- //
|
|
55
|
+
|
|
56
|
+
// Tracks the pending selected index
|
|
57
|
+
let pendingSelectedValue: string | undefined = $state(selectedValue);
|
|
58
|
+
|
|
59
|
+
// svelte-ignore non_reactive_update
|
|
60
|
+
let selectRef: HTMLElement | undefined = $state(undefined);
|
|
61
|
+
let listRef: List;
|
|
62
|
+
|
|
63
|
+
// ----- Reactions ----- //
|
|
64
|
+
|
|
65
|
+
$effect(() => {
|
|
18
66
|
pendingSelectedValue = selectedValue;
|
|
19
|
-
});
|
|
20
|
-
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
$effect(() => {
|
|
21
70
|
onSelect?.(selectedValue);
|
|
22
|
-
});
|
|
23
|
-
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
$effect(() => {
|
|
24
74
|
if (open) {
|
|
25
|
-
|
|
75
|
+
onPending?.(pendingSelectedValue);
|
|
26
76
|
}
|
|
27
|
-
});
|
|
28
|
-
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
$effect(() => {
|
|
29
80
|
if (open) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
81
|
+
tick().then(() => {
|
|
82
|
+
setTimeout(() => {
|
|
83
|
+
listRef?.focus();
|
|
84
|
+
listRef?.scrollToSelectedItem();
|
|
85
|
+
}, 10);
|
|
86
|
+
});
|
|
36
87
|
}
|
|
37
|
-
});
|
|
38
|
-
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
$effect(() => {
|
|
39
91
|
if (!open) {
|
|
40
|
-
|
|
92
|
+
tick().then(() => selectRef?.focus());
|
|
41
93
|
}
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// ----- Methods ----- //
|
|
97
|
+
|
|
98
|
+
export const blur = () => {
|
|
45
99
|
selectRef?.blur();
|
|
46
|
-
};
|
|
47
|
-
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export const click = () => {
|
|
48
103
|
selectRef?.click();
|
|
49
|
-
};
|
|
50
|
-
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export const focus = (options?: FocusOptions) => {
|
|
51
107
|
selectRef?.focus();
|
|
52
|
-
};
|
|
53
|
-
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export const scrollToSelectedItem = () => {
|
|
54
111
|
if (open) {
|
|
55
|
-
|
|
112
|
+
listRef?.scrollToSelectedItem();
|
|
56
113
|
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// ----- Event Handlers ----- //
|
|
117
|
+
|
|
118
|
+
const onSelectClick: MouseEventHandler<HTMLDivElement> = (event) => {
|
|
60
119
|
if (!disabled) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
120
|
+
open = !open;
|
|
121
|
+
event.preventDefault();
|
|
122
|
+
event.stopPropagation();
|
|
64
123
|
}
|
|
65
124
|
rest.onclick?.(event);
|
|
66
|
-
};
|
|
67
|
-
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const onSelectKeydown: KeyboardEventHandler<HTMLDivElement> = (event) => {
|
|
68
128
|
if (!disabled && !event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
129
|
+
switch (event.key) {
|
|
130
|
+
case ' ':
|
|
131
|
+
{
|
|
132
|
+
if (!open) {
|
|
133
|
+
open = true;
|
|
134
|
+
}
|
|
135
|
+
event.preventDefault();
|
|
136
|
+
event.stopPropagation();
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
break;
|
|
140
|
+
case 'ArrowUp':
|
|
141
|
+
{
|
|
142
|
+
if (selectedValue) {
|
|
143
|
+
listRef?.selectPreviousItem();
|
|
144
|
+
} else {
|
|
145
|
+
listRef?.selectLastItem();
|
|
146
|
+
}
|
|
147
|
+
event.preventDefault();
|
|
148
|
+
event.stopPropagation();
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
break;
|
|
152
|
+
case 'ArrowDown':
|
|
153
|
+
{
|
|
154
|
+
if (selectedValue) {
|
|
155
|
+
listRef?.selectNextItem();
|
|
156
|
+
} else {
|
|
157
|
+
listRef?.selectFirstItem();
|
|
158
|
+
}
|
|
159
|
+
event.preventDefault();
|
|
160
|
+
event.stopPropagation();
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
107
165
|
}
|
|
108
166
|
rest.onkeydown?.(event);
|
|
109
|
-
};
|
|
110
|
-
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const onListKeydown = (event: KeyboardEvent) => {
|
|
111
170
|
if (!disabled && !event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
171
|
+
switch (event.key) {
|
|
172
|
+
case 'Enter':
|
|
173
|
+
{
|
|
174
|
+
selectedValue = pendingSelectedValue;
|
|
175
|
+
open = !open;
|
|
176
|
+
event.preventDefault();
|
|
177
|
+
event.stopPropagation();
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
break;
|
|
181
|
+
case 'Escape':
|
|
182
|
+
{
|
|
183
|
+
pendingSelectedValue = selectedValue;
|
|
184
|
+
open = !open;
|
|
185
|
+
event.preventDefault();
|
|
186
|
+
event.stopPropagation();
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
132
191
|
}
|
|
133
|
-
};
|
|
134
|
-
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const onListClick = (event: MouseEvent) => {
|
|
135
195
|
open = false;
|
|
136
196
|
event.preventDefault();
|
|
137
197
|
event.stopPropagation();
|
|
138
198
|
return false;
|
|
139
|
-
};
|
|
140
|
-
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const onListSelect = (value?: string) => {
|
|
141
202
|
pendingSelectedValue = value;
|
|
142
203
|
if (!open) {
|
|
143
|
-
|
|
204
|
+
selectedValue = pendingSelectedValue;
|
|
144
205
|
}
|
|
145
|
-
};
|
|
206
|
+
};
|
|
146
207
|
</script>
|
|
147
208
|
|
|
148
209
|
<div
|
|
149
210
|
bind:this={selectRef}
|
|
150
|
-
aria-controls={
|
|
211
|
+
aria-controls={popoverId}
|
|
151
212
|
aria-haspopup="listbox"
|
|
152
213
|
aria-expanded={open}
|
|
153
|
-
class={['sterling-select', _class]
|
|
214
|
+
class={['sterling-select', _class]}
|
|
154
215
|
class:disabled
|
|
155
216
|
role="combobox"
|
|
156
217
|
tabindex="0"
|
|
@@ -160,23 +221,28 @@ const onListSelect = (value) => {
|
|
|
160
221
|
onkeydown={onSelectKeydown}
|
|
161
222
|
>
|
|
162
223
|
<div class="value">
|
|
163
|
-
{#if
|
|
164
|
-
{
|
|
224
|
+
{#if value}
|
|
225
|
+
{#if typeof value === 'string'}
|
|
226
|
+
{value}
|
|
227
|
+
{:else}
|
|
228
|
+
{@render value(selectedValue)}
|
|
229
|
+
{/if}
|
|
165
230
|
{:else if selectedValue}
|
|
166
231
|
{selectedValue}
|
|
167
232
|
{:else}
|
|
168
233
|
<span> </span>
|
|
169
234
|
{/if}
|
|
170
235
|
</div>
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
236
|
+
<!-- button class was initially incorrect, so leaving it here for now -->
|
|
237
|
+
<div class="button icon">
|
|
238
|
+
{#if icon}
|
|
239
|
+
{@render icon()}
|
|
174
240
|
{:else}
|
|
175
241
|
<div class="chevron"></div>
|
|
176
242
|
{/if}
|
|
177
243
|
</div>
|
|
178
|
-
<Popover reference={selectRef} bind:open
|
|
179
|
-
<div class={['sterling-select-popup-content', _class]
|
|
244
|
+
<Popover id={popoverId} reference={selectRef} bind:open conditionalRender={false}>
|
|
245
|
+
<div class={['sterling-select-popup-content', 'sterling-select-content', _class]}>
|
|
180
246
|
<List
|
|
181
247
|
bind:this={listRef}
|
|
182
248
|
{disabled}
|
|
@@ -185,7 +251,7 @@ const onListSelect = (value) => {
|
|
|
185
251
|
onkeydown={onListKeydown}
|
|
186
252
|
onSelect={onListSelect}
|
|
187
253
|
tabindex={open ? 0 : -1}
|
|
188
|
-
class={
|
|
254
|
+
class={['composed', listClass]}
|
|
189
255
|
>
|
|
190
256
|
{#if children}
|
|
191
257
|
{@render children()}
|
package/dist/Select.svelte.d.ts
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { type Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
-
type
|
|
3
|
+
type DeprecatedProps = {
|
|
4
|
+
/** @deprecated Use icon instead */
|
|
4
5
|
buttonSnippet?: Snippet;
|
|
6
|
+
/** @deprecated Use value instead */
|
|
7
|
+
valueSnippet?: Snippet<[string | undefined]>;
|
|
8
|
+
};
|
|
9
|
+
type Props = HTMLAttributes<HTMLDivElement> & DeprecatedProps & {
|
|
5
10
|
disabled?: boolean | null;
|
|
11
|
+
icon?: Snippet;
|
|
6
12
|
listClass?: string;
|
|
7
13
|
onPending?: (value?: string) => void;
|
|
8
14
|
onSelect?: (value?: string) => void;
|
|
9
15
|
open?: boolean | null;
|
|
10
16
|
selectedValue?: string;
|
|
11
|
-
|
|
17
|
+
value?: string | Snippet<[string | undefined]>;
|
|
12
18
|
};
|
|
13
19
|
declare const Select: import("svelte").Component<Props, {
|
|
14
20
|
blur: () => void;
|
package/dist/Slider.svelte
CHANGED
|
@@ -1,100 +1,149 @@
|
|
|
1
1
|
<svelte:options runes={true} />
|
|
2
2
|
|
|
3
|
-
<script lang="ts">
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
<script lang="ts">
|
|
4
|
+
import { round } from 'lodash-es';
|
|
5
|
+
import type { HTMLAttributes, KeyboardEventHandler, PointerEventHandler } from 'svelte/elements';
|
|
6
|
+
|
|
7
|
+
type Props = HTMLAttributes<HTMLDivElement> & {
|
|
8
|
+
disabled?: boolean | null;
|
|
9
|
+
min?: number;
|
|
10
|
+
max?: number;
|
|
11
|
+
precision?: number;
|
|
12
|
+
step?: number;
|
|
13
|
+
value?: number;
|
|
14
|
+
vertical?: boolean | null;
|
|
15
|
+
onChange?: (value: number) => void;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
let {
|
|
19
|
+
class: _class,
|
|
20
|
+
disabled,
|
|
21
|
+
min = 0,
|
|
22
|
+
max = 100,
|
|
23
|
+
onChange,
|
|
24
|
+
precision = 0,
|
|
25
|
+
step = 1,
|
|
26
|
+
value = $bindable(0),
|
|
27
|
+
vertical,
|
|
28
|
+
...rest
|
|
29
|
+
}: Props = $props();
|
|
30
|
+
|
|
31
|
+
let sliderRef: HTMLDivElement;
|
|
32
|
+
|
|
33
|
+
export const blur = () => {
|
|
7
34
|
sliderRef?.blur();
|
|
8
|
-
};
|
|
9
|
-
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const click = () => {
|
|
10
38
|
sliderRef?.click();
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const focus = (options?: FocusOptions) => {
|
|
42
|
+
sliderRef?.parentElement?.focus(options);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
let ratio = $derived((value - min) / (max - min));
|
|
46
|
+
|
|
47
|
+
const setValue = (newValue: number) => {
|
|
17
48
|
const clamped = Math.max(min, Math.min(max, newValue));
|
|
18
49
|
value = precision !== undefined ? round(clamped, precision) : clamped;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// ensure min <= max
|
|
53
|
+
$effect(() => {
|
|
22
54
|
if (min > max) {
|
|
23
|
-
|
|
55
|
+
min = max;
|
|
24
56
|
}
|
|
25
|
-
});
|
|
26
|
-
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
$effect(() => {
|
|
27
60
|
const clamped = Math.max(min, Math.min(max, value));
|
|
28
61
|
const newValue = precision !== undefined ? round(clamped, precision) : clamped;
|
|
29
62
|
if (value !== newValue) {
|
|
30
|
-
|
|
63
|
+
value = newValue;
|
|
31
64
|
}
|
|
32
|
-
});
|
|
33
|
-
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const setValueByOffset = (offset: number) => {
|
|
34
68
|
if (sliderSize > 0) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
69
|
+
const positionRatio = Math.max(0, Math.min(1, offset / sliderSize));
|
|
70
|
+
const newValue = min + positionRatio * (max - min);
|
|
71
|
+
setValue(newValue);
|
|
38
72
|
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// Raise change event when value changes
|
|
76
|
+
$effect(() => {
|
|
42
77
|
onChange?.(value);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
let
|
|
48
|
-
let
|
|
49
|
-
|
|
50
|
-
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// ----- Size tracking ----- //
|
|
81
|
+
|
|
82
|
+
let sliderWidth: number = $state(0);
|
|
83
|
+
let sliderHeight: number = $state(0);
|
|
84
|
+
|
|
85
|
+
let sliderSize = $derived(vertical ? sliderHeight : sliderWidth);
|
|
86
|
+
|
|
87
|
+
let valueOffset = $derived(sliderSize * ratio);
|
|
88
|
+
|
|
89
|
+
// ----- Event handlers ----- //
|
|
90
|
+
|
|
91
|
+
const onPointerDown: PointerEventHandler<HTMLDivElement> = (event) => {
|
|
51
92
|
if (!disabled) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
93
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
94
|
+
if (vertical) {
|
|
95
|
+
setValueByOffset(sliderRef.getBoundingClientRect().bottom - event.y);
|
|
96
|
+
} else {
|
|
97
|
+
setValueByOffset(event.x - sliderRef.getBoundingClientRect().left);
|
|
98
|
+
}
|
|
99
|
+
event.preventDefault();
|
|
100
|
+
focus();
|
|
59
101
|
}
|
|
102
|
+
|
|
60
103
|
rest?.onpointerdown?.(event);
|
|
61
|
-
};
|
|
62
|
-
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const onPointerMove: PointerEventHandler<HTMLDivElement> = (event) => {
|
|
63
107
|
if (!disabled && event.currentTarget.hasPointerCapture(event.pointerId)) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
108
|
+
if (vertical) {
|
|
109
|
+
setValueByOffset(sliderRef.getBoundingClientRect().bottom - event.y);
|
|
110
|
+
} else {
|
|
111
|
+
setValueByOffset(event.x - sliderRef.getBoundingClientRect().left);
|
|
112
|
+
}
|
|
113
|
+
event.preventDefault();
|
|
70
114
|
}
|
|
115
|
+
|
|
71
116
|
rest?.onpointermove?.(event);
|
|
72
|
-
};
|
|
73
|
-
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const onPointerUp: PointerEventHandler<HTMLDivElement> = (event) => {
|
|
74
120
|
if (!disabled) {
|
|
75
|
-
|
|
121
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
122
|
+
event.preventDefault();
|
|
123
|
+
focus();
|
|
76
124
|
}
|
|
77
125
|
rest?.onpointerup?.(event);
|
|
78
|
-
};
|
|
79
|
-
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const onKeyDown: KeyboardEventHandler<HTMLDivElement> = (event) => {
|
|
80
129
|
if (!disabled && !event.ctrlKey && !event.shiftKey && !event.altKey) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
130
|
+
switch (event.code) {
|
|
131
|
+
case 'ArrowDown':
|
|
132
|
+
case 'ArrowLeft':
|
|
133
|
+
setValue(value - step);
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
event.stopPropagation();
|
|
136
|
+
return;
|
|
137
|
+
case 'ArrowRight':
|
|
138
|
+
case 'ArrowUp':
|
|
139
|
+
setValue(value + step);
|
|
140
|
+
event.preventDefault();
|
|
141
|
+
event.stopPropagation();
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
95
144
|
}
|
|
96
145
|
rest?.onkeydown?.(event);
|
|
97
|
-
};
|
|
146
|
+
};
|
|
98
147
|
</script>
|
|
99
148
|
|
|
100
149
|
<div
|
|
@@ -102,7 +151,7 @@ const onKeyDown = (event) => {
|
|
|
102
151
|
aria-valuemin={min}
|
|
103
152
|
aria-valuenow={value}
|
|
104
153
|
aria-valuemax={max}
|
|
105
|
-
class={
|
|
154
|
+
class={['sterling-slider', _class]}
|
|
106
155
|
class:disabled
|
|
107
156
|
class:horizontal={!vertical}
|
|
108
157
|
class:vertical
|
package/dist/Slider.svelte.d.ts
CHANGED