@geoffcox/sterling-svelte 2.0.1 → 2.0.2
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/package.json +26 -28
- package/README.md +0 -18
- package/dist/@types/clickOutside.d.ts +0 -15
- package/dist/Button.svelte +0 -25
- package/dist/Button.svelte.d.ts +0 -9
- package/dist/Callout.svelte +0 -177
- package/dist/Callout.svelte.d.ts +0 -15
- package/dist/Callout.types.d.ts +0 -11
- package/dist/Callout.types.js +0 -1
- package/dist/Checkbox.svelte +0 -43
- package/dist/Checkbox.svelte.d.ts +0 -10
- package/dist/Dialog.svelte +0 -151
- package/dist/Dialog.svelte.d.ts +0 -14
- package/dist/Dropdown.svelte +0 -109
- package/dist/Dropdown.svelte.d.ts +0 -18
- package/dist/Input.svelte +0 -55
- package/dist/Input.svelte.d.ts +0 -12
- package/dist/Label.constants.d.ts +0 -2
- package/dist/Label.constants.js +0 -2
- package/dist/Label.svelte +0 -91
- package/dist/Label.svelte.d.ts +0 -17
- package/dist/Link.svelte +0 -25
- package/dist/Link.svelte.d.ts +0 -12
- package/dist/List.constants.d.ts +0 -1
- package/dist/List.constants.js +0 -1
- package/dist/List.svelte +0 -203
- package/dist/List.svelte.d.ts +0 -20
- package/dist/List.types.d.ts +0 -5
- package/dist/List.types.js +0 -1
- package/dist/ListItem.svelte +0 -49
- package/dist/ListItem.svelte.d.ts +0 -13
- package/dist/Menu.svelte +0 -83
- package/dist/Menu.svelte.d.ts +0 -13
- package/dist/MenuBar.constants.d.ts +0 -1
- package/dist/MenuBar.constants.js +0 -1
- package/dist/MenuBar.svelte +0 -113
- package/dist/MenuBar.svelte.d.ts +0 -13
- package/dist/MenuBar.types.d.ts +0 -4
- package/dist/MenuBar.types.js +0 -1
- package/dist/MenuButton.svelte +0 -116
- package/dist/MenuButton.svelte.d.ts +0 -20
- package/dist/MenuItem.constants.d.ts +0 -2
- package/dist/MenuItem.constants.js +0 -2
- package/dist/MenuItem.svelte +0 -342
- package/dist/MenuItem.svelte.d.ts +0 -22
- package/dist/MenuItem.types.d.ts +0 -20
- package/dist/MenuItem.types.js +0 -1
- package/dist/MenuItem.utils.d.ts +0 -7
- package/dist/MenuItem.utils.js +0 -36
- package/dist/MenuSeparator.svelte +0 -11
- package/dist/MenuSeparator.svelte.d.ts +0 -6
- package/dist/Popover.constants.d.ts +0 -1
- package/dist/Popover.constants.js +0 -14
- package/dist/Popover.svelte +0 -121
- package/dist/Popover.svelte.d.ts +0 -15
- package/dist/Popover.types.d.ts +0 -4
- package/dist/Popover.types.js +0 -1
- package/dist/Portal.constants.d.ts +0 -2
- package/dist/Portal.constants.js +0 -2
- package/dist/Portal.types.d.ts +0 -6
- package/dist/Portal.types.js +0 -1
- package/dist/Progress.constants.d.ts +0 -1
- package/dist/Progress.constants.js +0 -1
- package/dist/Progress.svelte +0 -36
- package/dist/Progress.svelte.d.ts +0 -12
- package/dist/Progress.types.d.ts +0 -4
- package/dist/Progress.types.js +0 -1
- package/dist/Radio.svelte +0 -53
- package/dist/Radio.svelte.d.ts +0 -13
- package/dist/Select.svelte +0 -196
- package/dist/Select.svelte.d.ts +0 -20
- package/dist/Slider.svelte +0 -133
- package/dist/Slider.svelte.d.ts +0 -19
- package/dist/Switch.svelte +0 -61
- package/dist/Switch.svelte.d.ts +0 -21
- package/dist/Tab.svelte +0 -51
- package/dist/Tab.svelte.d.ts +0 -12
- package/dist/TabList.constants.d.ts +0 -1
- package/dist/TabList.constants.js +0 -1
- package/dist/TabList.svelte +0 -202
- package/dist/TabList.svelte.d.ts +0 -18
- package/dist/TabList.types.d.ts +0 -5
- package/dist/TabList.types.js +0 -1
- package/dist/TextArea.constants.d.ts +0 -1
- package/dist/TextArea.constants.js +0 -1
- package/dist/TextArea.svelte +0 -74
- package/dist/TextArea.svelte.d.ts +0 -19
- package/dist/TextArea.types.d.ts +0 -4
- package/dist/TextArea.types.js +0 -1
- package/dist/Tooltip.svelte +0 -63
- package/dist/Tooltip.svelte.d.ts +0 -10
- package/dist/Tree.constants.d.ts +0 -1
- package/dist/Tree.constants.js +0 -1
- package/dist/Tree.svelte +0 -53
- package/dist/Tree.svelte.d.ts +0 -15
- package/dist/Tree.types.d.ts +0 -5
- package/dist/Tree.types.js +0 -1
- package/dist/TreeChevron.svelte +0 -27
- package/dist/TreeChevron.svelte.d.ts +0 -9
- package/dist/TreeItem.constants.d.ts +0 -1
- package/dist/TreeItem.constants.js +0 -1
- package/dist/TreeItem.svelte +0 -329
- package/dist/TreeItem.svelte.d.ts +0 -22
- package/dist/TreeItem.types.d.ts +0 -4
- package/dist/TreeItem.types.js +0 -1
- package/dist/actions/applyLightDarkMode.d.ts +0 -10
- package/dist/actions/applyLightDarkMode.js +0 -36
- package/dist/actions/clickOutside.d.ts +0 -15
- package/dist/actions/clickOutside.js +0 -28
- package/dist/actions/extraClass.d.ts +0 -8
- package/dist/actions/extraClass.js +0 -14
- package/dist/actions/forwardEvents.d.ts +0 -12
- package/dist/actions/forwardEvents.js +0 -32
- package/dist/actions/portal.d.ts +0 -8
- package/dist/actions/portal.js +0 -19
- package/dist/actions/trapKeyboardFocus.d.ts +0 -3
- package/dist/actions/trapKeyboardFocus.js +0 -52
- package/dist/idGenerator.d.ts +0 -4
- package/dist/idGenerator.js +0 -10
- package/dist/index.d.ts +0 -59
- package/dist/index.js +0 -54
- package/dist/mediaQueries/prefersColorSchemeDark.d.ts +0 -2
- package/dist/mediaQueries/prefersColorSchemeDark.js +0 -14
- package/dist/mediaQueries/prefersReducedMotion.d.ts +0 -2
- package/dist/mediaQueries/prefersReducedMotion.js +0 -14
- package/dist/mediaQueries/usingKeyboard.d.ts +0 -2
- package/dist/mediaQueries/usingKeyboard.js +0 -17
package/dist/Progress.svelte
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
<svelte:options runes={true} />
|
|
2
|
-
|
|
3
|
-
<script lang="ts">let { class: _class, disabled = false, max = 100, percent = $bindable(0), //readonly
|
|
4
|
-
value = $bindable(0), vertical, ...rest } = $props();
|
|
5
|
-
//----- State ----- //
|
|
6
|
-
let clientHeight = $state(0);
|
|
7
|
-
let clientWidth = $state(0);
|
|
8
|
-
let clampMax = $derived(Math.max(1, max));
|
|
9
|
-
let clampValue = $derived(Math.max(0, Math.min(value, clampMax)));
|
|
10
|
-
let ratio = $derived(clampValue / clampMax);
|
|
11
|
-
$effect(() => {
|
|
12
|
-
percent = Math.round(ratio * 100);
|
|
13
|
-
});
|
|
14
|
-
let percentHeight = $derived(clientHeight * ratio);
|
|
15
|
-
let percentWidth = $derived(clientWidth * ratio);
|
|
16
|
-
let indicatorStyle = $derived(vertical ? `height: ${percentHeight}px` : `width: ${percentWidth}px`);
|
|
17
|
-
export {};
|
|
18
|
-
</script>
|
|
19
|
-
|
|
20
|
-
<!-- svelte-ignore a11y_role_supports_aria_props -->
|
|
21
|
-
<div
|
|
22
|
-
aria-orientation={vertical ? 'vertical' : 'horizontal'}
|
|
23
|
-
class={['sterling-progress', _class].filter(Boolean).join(' ')}
|
|
24
|
-
class:disabled
|
|
25
|
-
class:horizontal={!vertical}
|
|
26
|
-
class:vertical
|
|
27
|
-
data-progress-percent={percent}
|
|
28
|
-
data-progress-max={max}
|
|
29
|
-
data-progress-value={value}
|
|
30
|
-
role="progressbar"
|
|
31
|
-
{...rest}
|
|
32
|
-
>
|
|
33
|
-
<div class="container" bind:clientWidth bind:clientHeight>
|
|
34
|
-
<div class="indicator" style={indicatorStyle}></div>
|
|
35
|
-
</div>
|
|
36
|
-
</div>
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/// <reference types="svelte" />
|
|
2
|
-
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
-
type Props = HTMLAttributes<HTMLDivElement> & {
|
|
4
|
-
disabled?: boolean | null;
|
|
5
|
-
max?: number;
|
|
6
|
-
percent?: number;
|
|
7
|
-
value?: number;
|
|
8
|
-
vertical?: boolean | null;
|
|
9
|
-
};
|
|
10
|
-
declare const Progress: import("svelte").Component<Props, {}, "value" | "percent">;
|
|
11
|
-
type Progress = ReturnType<typeof Progress>;
|
|
12
|
-
export default Progress;
|
package/dist/Progress.types.d.ts
DELETED
package/dist/Progress.types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/Radio.svelte
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
<svelte:options runes={true} />
|
|
2
|
-
|
|
3
|
-
<script lang="ts">import { idGenerator } from './idGenerator';
|
|
4
|
-
import { usingKeyboard } from './mediaQueries/usingKeyboard';
|
|
5
|
-
let { id, children, checked = $bindable(false), class: _class, disabled = false, group = $bindable(), ...rest } = $props();
|
|
6
|
-
let inputRef;
|
|
7
|
-
$effect(() => {
|
|
8
|
-
if (children && id === undefined) {
|
|
9
|
-
id = idGenerator.nextId('Radio');
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
// ----- Methods ----- //
|
|
13
|
-
export const blur = () => {
|
|
14
|
-
inputRef?.blur();
|
|
15
|
-
};
|
|
16
|
-
export const click = () => {
|
|
17
|
-
inputRef?.click();
|
|
18
|
-
};
|
|
19
|
-
export const focus = (options) => {
|
|
20
|
-
inputRef?.focus(options);
|
|
21
|
-
};
|
|
22
|
-
// ----- Event Handlers ----- //
|
|
23
|
-
const onChange = (e) => {
|
|
24
|
-
console.log('onChange', e);
|
|
25
|
-
// if ((e.currentTarget && e.currentTarget.checked) || (e.target && e.target.checked)) {
|
|
26
|
-
// group = value;
|
|
27
|
-
// }
|
|
28
|
-
};
|
|
29
|
-
$effect(() => {
|
|
30
|
-
console.log(id, '-checked', checked);
|
|
31
|
-
});
|
|
32
|
-
</script>
|
|
33
|
-
|
|
34
|
-
<!--
|
|
35
|
-
@component
|
|
36
|
-
A styled HTML input type=radio element with optional label.
|
|
37
|
-
-->
|
|
38
|
-
<div
|
|
39
|
-
class={`sterling-radio ${_class}`}
|
|
40
|
-
class:checked
|
|
41
|
-
class:disabled
|
|
42
|
-
class:using-keyboard={$usingKeyboard}
|
|
43
|
-
>
|
|
44
|
-
<div class="container">
|
|
45
|
-
<input bind:this={inputRef} checked {disabled} bind:group {id} type="radio" {...rest} />
|
|
46
|
-
<div class="indicator"></div>
|
|
47
|
-
</div>
|
|
48
|
-
{#if children}
|
|
49
|
-
<label for={id}>
|
|
50
|
-
{@render children()}
|
|
51
|
-
</label>
|
|
52
|
-
{/if}
|
|
53
|
-
</div>
|
package/dist/Radio.svelte.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/// <reference types="svelte" />
|
|
2
|
-
import type { HTMLInputAttributes } from 'svelte/elements';
|
|
3
|
-
type Props = HTMLInputAttributes & {
|
|
4
|
-
group?: any | null;
|
|
5
|
-
};
|
|
6
|
-
/** A styled HTML input type=radio element with optional label. */
|
|
7
|
-
declare const Radio: import("svelte").Component<Props, {
|
|
8
|
-
blur: () => void;
|
|
9
|
-
click: () => void;
|
|
10
|
-
focus: (options?: FocusOptions) => void;
|
|
11
|
-
}, "group" | "checked">;
|
|
12
|
-
type Radio = ReturnType<typeof Radio>;
|
|
13
|
-
export default Radio;
|
package/dist/Select.svelte
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
<svelte:options runes={true} />
|
|
2
|
-
|
|
3
|
-
<script lang="ts">import { tick } from 'svelte';
|
|
4
|
-
import { clickOutside } from './actions/clickOutside';
|
|
5
|
-
import { idGenerator } from './idGenerator';
|
|
6
|
-
import List from './List.svelte';
|
|
7
|
-
import Popover from './Popover.svelte';
|
|
8
|
-
let { buttonSnippet, children, class: _class, disabled = false, open = $bindable(false), onSelect, onPending, selectedValue = $bindable(), listClass, valueSnippet, ...rest } = $props();
|
|
9
|
-
const popupId = idGenerator.nextId('Select-popup');
|
|
10
|
-
// ----- State ----- //
|
|
11
|
-
// Tracks the pending selected index
|
|
12
|
-
let pendingSelectedValue = $state(selectedValue);
|
|
13
|
-
// svelte-ignore non_reactive_update
|
|
14
|
-
let selectRef = $state(undefined);
|
|
15
|
-
let listRef;
|
|
16
|
-
// ----- Reactions ----- //
|
|
17
|
-
$effect(() => {
|
|
18
|
-
pendingSelectedValue = selectedValue;
|
|
19
|
-
});
|
|
20
|
-
$effect(() => {
|
|
21
|
-
onSelect?.(selectedValue);
|
|
22
|
-
});
|
|
23
|
-
$effect(() => {
|
|
24
|
-
if (open) {
|
|
25
|
-
onPending?.(pendingSelectedValue);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
$effect(() => {
|
|
29
|
-
if (open) {
|
|
30
|
-
tick().then(() => {
|
|
31
|
-
setTimeout(() => {
|
|
32
|
-
listRef?.focus();
|
|
33
|
-
listRef?.scrollToSelectedItem();
|
|
34
|
-
}, 10);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
$effect(() => {
|
|
39
|
-
if (!open) {
|
|
40
|
-
tick().then(() => selectRef?.focus());
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
// ----- Methods ----- //
|
|
44
|
-
export const blur = () => {
|
|
45
|
-
selectRef?.blur();
|
|
46
|
-
};
|
|
47
|
-
export const click = () => {
|
|
48
|
-
selectRef?.click();
|
|
49
|
-
};
|
|
50
|
-
export const focus = (options) => {
|
|
51
|
-
selectRef?.focus();
|
|
52
|
-
};
|
|
53
|
-
export const scrollToSelectedItem = () => {
|
|
54
|
-
if (open) {
|
|
55
|
-
listRef?.scrollToSelectedItem();
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
// ----- Event Handlers ----- //
|
|
59
|
-
const onSelectClick = (event) => {
|
|
60
|
-
if (!disabled) {
|
|
61
|
-
open = !open;
|
|
62
|
-
event.preventDefault();
|
|
63
|
-
event.stopPropagation();
|
|
64
|
-
}
|
|
65
|
-
rest.onclick?.(event);
|
|
66
|
-
};
|
|
67
|
-
const onSelectKeydown = (event) => {
|
|
68
|
-
if (!disabled && !event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) {
|
|
69
|
-
switch (event.key) {
|
|
70
|
-
case ' ':
|
|
71
|
-
{
|
|
72
|
-
if (!open) {
|
|
73
|
-
open = true;
|
|
74
|
-
}
|
|
75
|
-
event.preventDefault();
|
|
76
|
-
event.stopPropagation();
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
break;
|
|
80
|
-
case 'ArrowUp':
|
|
81
|
-
{
|
|
82
|
-
if (selectedValue) {
|
|
83
|
-
listRef?.selectPreviousItem();
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
listRef?.selectLastItem();
|
|
87
|
-
}
|
|
88
|
-
event.preventDefault();
|
|
89
|
-
event.stopPropagation();
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
break;
|
|
93
|
-
case 'ArrowDown':
|
|
94
|
-
{
|
|
95
|
-
if (selectedValue) {
|
|
96
|
-
listRef?.selectNextItem();
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
listRef?.selectFirstItem();
|
|
100
|
-
}
|
|
101
|
-
event.preventDefault();
|
|
102
|
-
event.stopPropagation();
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
rest.onkeydown?.(event);
|
|
109
|
-
};
|
|
110
|
-
const onListKeydown = (event) => {
|
|
111
|
-
if (!disabled && !event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) {
|
|
112
|
-
switch (event.key) {
|
|
113
|
-
case 'Enter':
|
|
114
|
-
{
|
|
115
|
-
selectedValue = pendingSelectedValue;
|
|
116
|
-
open = !open;
|
|
117
|
-
event.preventDefault();
|
|
118
|
-
event.stopPropagation();
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
break;
|
|
122
|
-
case 'Escape':
|
|
123
|
-
{
|
|
124
|
-
pendingSelectedValue = selectedValue;
|
|
125
|
-
open = !open;
|
|
126
|
-
event.preventDefault();
|
|
127
|
-
event.stopPropagation();
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
const onListClick = (event) => {
|
|
135
|
-
open = false;
|
|
136
|
-
event.preventDefault();
|
|
137
|
-
event.stopPropagation();
|
|
138
|
-
return false;
|
|
139
|
-
};
|
|
140
|
-
const onListSelect = (value) => {
|
|
141
|
-
pendingSelectedValue = value;
|
|
142
|
-
if (!open) {
|
|
143
|
-
selectedValue = pendingSelectedValue;
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
</script>
|
|
147
|
-
|
|
148
|
-
<div
|
|
149
|
-
bind:this={selectRef}
|
|
150
|
-
aria-controls={popupId}
|
|
151
|
-
aria-haspopup="listbox"
|
|
152
|
-
aria-expanded={open}
|
|
153
|
-
class={['sterling-select', _class].filter(Boolean).join(' ')}
|
|
154
|
-
class:disabled
|
|
155
|
-
role="combobox"
|
|
156
|
-
tabindex="0"
|
|
157
|
-
use:clickOutside={{ onclickoutside: () => (open = false) }}
|
|
158
|
-
{...rest}
|
|
159
|
-
onclick={onSelectClick}
|
|
160
|
-
onkeydown={onSelectKeydown}
|
|
161
|
-
>
|
|
162
|
-
<div class="value">
|
|
163
|
-
{#if valueSnippet}
|
|
164
|
-
{@render valueSnippet(selectedValue)}
|
|
165
|
-
{:else if selectedValue}
|
|
166
|
-
{selectedValue}
|
|
167
|
-
{:else}
|
|
168
|
-
<span> </span>
|
|
169
|
-
{/if}
|
|
170
|
-
</div>
|
|
171
|
-
<div class="button">
|
|
172
|
-
{#if buttonSnippet}
|
|
173
|
-
{@render buttonSnippet()}
|
|
174
|
-
{:else}
|
|
175
|
-
<div class="chevron"></div>
|
|
176
|
-
{/if}
|
|
177
|
-
</div>
|
|
178
|
-
<Popover reference={selectRef} bind:open id={popupId} conditionalRender={false}>
|
|
179
|
-
<div class={['sterling-select-popup-content', _class].filter(Boolean).join(' ')}>
|
|
180
|
-
<List
|
|
181
|
-
bind:this={listRef}
|
|
182
|
-
{disabled}
|
|
183
|
-
selectedValue={pendingSelectedValue}
|
|
184
|
-
onclick={onListClick}
|
|
185
|
-
onkeydown={onListKeydown}
|
|
186
|
-
onSelect={onListSelect}
|
|
187
|
-
tabindex={open ? 0 : -1}
|
|
188
|
-
class={`composed ${listClass}`}
|
|
189
|
-
>
|
|
190
|
-
{#if children}
|
|
191
|
-
{@render children()}
|
|
192
|
-
{/if}
|
|
193
|
-
</List>
|
|
194
|
-
</div>
|
|
195
|
-
</Popover>
|
|
196
|
-
</div>
|
package/dist/Select.svelte.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { type Snippet } from 'svelte';
|
|
2
|
-
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
-
type Props = HTMLAttributes<HTMLDivElement> & {
|
|
4
|
-
buttonSnippet?: Snippet;
|
|
5
|
-
disabled?: boolean | null;
|
|
6
|
-
listClass?: string;
|
|
7
|
-
onPending?: (value?: string) => void;
|
|
8
|
-
onSelect?: (value?: string) => void;
|
|
9
|
-
open?: boolean | null;
|
|
10
|
-
selectedValue?: string;
|
|
11
|
-
valueSnippet?: Snippet<[string | undefined]>;
|
|
12
|
-
};
|
|
13
|
-
declare const Select: import("svelte").Component<Props, {
|
|
14
|
-
blur: () => void;
|
|
15
|
-
click: () => void;
|
|
16
|
-
focus: (options?: FocusOptions) => void;
|
|
17
|
-
scrollToSelectedItem: () => void;
|
|
18
|
-
}, "open" | "selectedValue">;
|
|
19
|
-
type Select = ReturnType<typeof Select>;
|
|
20
|
-
export default Select;
|
package/dist/Slider.svelte
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
<svelte:options runes={true} />
|
|
2
|
-
|
|
3
|
-
<script lang="ts">import { round } from 'lodash-es';
|
|
4
|
-
let { class: _class, disabled, min = 0, max = 100, onChange, precision = 0, step = 1, value = $bindable(0), vertical, ...rest } = $props();
|
|
5
|
-
let sliderRef;
|
|
6
|
-
export const blur = () => {
|
|
7
|
-
sliderRef?.blur();
|
|
8
|
-
};
|
|
9
|
-
export const click = () => {
|
|
10
|
-
sliderRef?.click();
|
|
11
|
-
};
|
|
12
|
-
export const focus = (options) => {
|
|
13
|
-
sliderRef?.focus();
|
|
14
|
-
};
|
|
15
|
-
let ratio = $derived((value - min) / (max - min));
|
|
16
|
-
const setValue = (newValue) => {
|
|
17
|
-
const clamped = Math.max(min, Math.min(max, newValue));
|
|
18
|
-
value = precision !== undefined ? round(clamped, precision) : clamped;
|
|
19
|
-
};
|
|
20
|
-
// ensure min <= max
|
|
21
|
-
$effect(() => {
|
|
22
|
-
if (min > max) {
|
|
23
|
-
min = max;
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
$effect(() => {
|
|
27
|
-
const clamped = Math.max(min, Math.min(max, value));
|
|
28
|
-
const newValue = precision !== undefined ? round(clamped, precision) : clamped;
|
|
29
|
-
if (value !== newValue) {
|
|
30
|
-
value = newValue;
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
const setValueByOffset = (offset) => {
|
|
34
|
-
if (sliderSize > 0) {
|
|
35
|
-
const positionRatio = Math.max(0, Math.min(1, offset / sliderSize));
|
|
36
|
-
const newValue = min + positionRatio * (max - min);
|
|
37
|
-
setValue(newValue);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
// Raise change event when value changes
|
|
41
|
-
$effect(() => {
|
|
42
|
-
onChange?.(value);
|
|
43
|
-
});
|
|
44
|
-
// ----- Size tracking ----- //
|
|
45
|
-
let sliderWidth = $state(0);
|
|
46
|
-
let sliderHeight = $state(0);
|
|
47
|
-
let sliderSize = $derived(vertical ? sliderHeight : sliderWidth);
|
|
48
|
-
let valueOffset = $derived(sliderSize * ratio);
|
|
49
|
-
// ----- Event handlers ----- //
|
|
50
|
-
const onPointerDown = (event) => {
|
|
51
|
-
if (!disabled) {
|
|
52
|
-
event.currentTarget.setPointerCapture(event.pointerId);
|
|
53
|
-
if (vertical) {
|
|
54
|
-
setValueByOffset(sliderRef.getBoundingClientRect().bottom - event.y);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
setValueByOffset(event.x - sliderRef.getBoundingClientRect().left);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
rest?.onpointerdown?.(event);
|
|
61
|
-
};
|
|
62
|
-
const onPointerMove = (event) => {
|
|
63
|
-
if (!disabled && event.currentTarget.hasPointerCapture(event.pointerId)) {
|
|
64
|
-
if (vertical) {
|
|
65
|
-
setValueByOffset(sliderRef.getBoundingClientRect().bottom - event.y);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
setValueByOffset(event.x - sliderRef.getBoundingClientRect().left);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
rest?.onpointermove?.(event);
|
|
72
|
-
};
|
|
73
|
-
const onPointerUp = (event) => {
|
|
74
|
-
if (!disabled) {
|
|
75
|
-
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
76
|
-
}
|
|
77
|
-
rest?.onpointerup?.(event);
|
|
78
|
-
};
|
|
79
|
-
const onKeyDown = (event) => {
|
|
80
|
-
if (!disabled && !event.ctrlKey && !event.shiftKey && !event.altKey) {
|
|
81
|
-
switch (event.code) {
|
|
82
|
-
case 'ArrowDown':
|
|
83
|
-
case 'ArrowLeft':
|
|
84
|
-
setValue(value - step);
|
|
85
|
-
event.preventDefault();
|
|
86
|
-
event.stopPropagation();
|
|
87
|
-
return;
|
|
88
|
-
case 'ArrowRight':
|
|
89
|
-
case 'ArrowUp':
|
|
90
|
-
setValue(value + step);
|
|
91
|
-
event.preventDefault();
|
|
92
|
-
event.stopPropagation();
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
rest?.onkeydown?.(event);
|
|
97
|
-
};
|
|
98
|
-
</script>
|
|
99
|
-
|
|
100
|
-
<div
|
|
101
|
-
aria-disabled={disabled}
|
|
102
|
-
aria-valuemin={min}
|
|
103
|
-
aria-valuenow={value}
|
|
104
|
-
aria-valuemax={max}
|
|
105
|
-
class={`sterling-slider ${_class}`}
|
|
106
|
-
class:disabled
|
|
107
|
-
class:horizontal={!vertical}
|
|
108
|
-
class:vertical
|
|
109
|
-
role="slider"
|
|
110
|
-
tabindex={!disabled ? 0 : undefined}
|
|
111
|
-
{...rest}
|
|
112
|
-
onkeydown={onKeyDown}
|
|
113
|
-
onpointerdown={onPointerDown}
|
|
114
|
-
onpointermove={onPointerMove}
|
|
115
|
-
onpointerup={onPointerUp}
|
|
116
|
-
>
|
|
117
|
-
<div
|
|
118
|
-
class="container"
|
|
119
|
-
bind:this={sliderRef}
|
|
120
|
-
bind:clientWidth={sliderWidth}
|
|
121
|
-
bind:clientHeight={sliderHeight}
|
|
122
|
-
>
|
|
123
|
-
<div class="track"></div>
|
|
124
|
-
<div
|
|
125
|
-
class="fill"
|
|
126
|
-
style={vertical ? `height: ${valueOffset}px` : `width: ${valueOffset}px`}
|
|
127
|
-
></div>
|
|
128
|
-
<div
|
|
129
|
-
class="thumb"
|
|
130
|
-
style={vertical ? `bottom: ${valueOffset}px` : `left: ${valueOffset}px`}
|
|
131
|
-
></div>
|
|
132
|
-
</div>
|
|
133
|
-
</div>
|
package/dist/Slider.svelte.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/// <reference types="svelte" />
|
|
2
|
-
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
-
type Props = HTMLAttributes<HTMLDivElement> & {
|
|
4
|
-
disabled?: boolean | null;
|
|
5
|
-
min?: number;
|
|
6
|
-
max?: number;
|
|
7
|
-
precision?: number;
|
|
8
|
-
step?: number;
|
|
9
|
-
value?: number;
|
|
10
|
-
vertical?: boolean | null;
|
|
11
|
-
onChange?: (value: number) => void;
|
|
12
|
-
};
|
|
13
|
-
declare const Slider: import("svelte").Component<Props, {
|
|
14
|
-
blur: () => void;
|
|
15
|
-
click: () => void;
|
|
16
|
-
focus: (options?: FocusOptions) => void;
|
|
17
|
-
}, "value">;
|
|
18
|
-
type Slider = ReturnType<typeof Slider>;
|
|
19
|
-
export default Slider;
|
package/dist/Switch.svelte
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
<svelte:options runes={true} />
|
|
2
|
-
|
|
3
|
-
<script lang="ts">import { idGenerator } from './idGenerator';
|
|
4
|
-
import { usingKeyboard } from './mediaQueries/usingKeyboard';
|
|
5
|
-
let { checked = $bindable(false), class: _class, disabled, id, offLabel, onLabel, vertical, ...rest } = $props();
|
|
6
|
-
const inputId = id || idGenerator.nextId('Switch');
|
|
7
|
-
let inputRef;
|
|
8
|
-
let switchWidth = $state(0);
|
|
9
|
-
let switchHeight = $state(0);
|
|
10
|
-
let thumbWidth = $state(0);
|
|
11
|
-
let thumbHeight = $state(0);
|
|
12
|
-
let switchSize = $derived(vertical ? switchHeight : switchWidth);
|
|
13
|
-
let thumbSize = $derived(vertical ? thumbHeight : thumbWidth);
|
|
14
|
-
let ratio = $derived(vertical ? (checked ? 0 : 1) : checked ? 1 : 0);
|
|
15
|
-
let valueOffset = $derived((switchSize - thumbSize) * ratio);
|
|
16
|
-
export const blur = () => {
|
|
17
|
-
inputRef?.blur();
|
|
18
|
-
};
|
|
19
|
-
export const click = () => {
|
|
20
|
-
inputRef?.click();
|
|
21
|
-
};
|
|
22
|
-
export const focus = (options) => {
|
|
23
|
-
inputRef?.focus(options);
|
|
24
|
-
};
|
|
25
|
-
</script>
|
|
26
|
-
|
|
27
|
-
<div
|
|
28
|
-
class={`sterling-switch ${_class}`}
|
|
29
|
-
class:checked
|
|
30
|
-
class:disabled
|
|
31
|
-
class:vertical
|
|
32
|
-
class:using-keyboard={$usingKeyboard}
|
|
33
|
-
>
|
|
34
|
-
<input bind:this={inputRef} bind:checked {disabled} id={inputId} type="checkbox" {...rest} />
|
|
35
|
-
{#if offLabel}
|
|
36
|
-
<div class="off-label">
|
|
37
|
-
{#if typeof offLabel === 'string'}
|
|
38
|
-
{offLabel}
|
|
39
|
-
{:else}
|
|
40
|
-
{@render offLabel({ checked, disabled, inputId })}
|
|
41
|
-
{/if}
|
|
42
|
-
</div>
|
|
43
|
-
{/if}
|
|
44
|
-
<div class="toggle" bind:offsetWidth={switchWidth} bind:offsetHeight={switchHeight}>
|
|
45
|
-
<div
|
|
46
|
-
class="thumb"
|
|
47
|
-
bind:offsetWidth={thumbWidth}
|
|
48
|
-
bind:offsetHeight={thumbHeight}
|
|
49
|
-
style={`--thumb-offset: ${valueOffset}px`}
|
|
50
|
-
></div>
|
|
51
|
-
</div>
|
|
52
|
-
{#if onLabel}
|
|
53
|
-
<div class="on-label">
|
|
54
|
-
{#if typeof onLabel === 'string'}
|
|
55
|
-
{onLabel}
|
|
56
|
-
{:else}
|
|
57
|
-
{@render onLabel({ checked, disabled, inputId })}
|
|
58
|
-
{/if}
|
|
59
|
-
</div>
|
|
60
|
-
{/if}
|
|
61
|
-
</div>
|
package/dist/Switch.svelte.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { HTMLInputAttributes } from 'svelte/elements';
|
|
2
|
-
import type { Snippet } from 'svelte';
|
|
3
|
-
type LabelSnippet = Snippet<[
|
|
4
|
-
{
|
|
5
|
-
checked: boolean | null | undefined;
|
|
6
|
-
disabled: boolean | null | undefined;
|
|
7
|
-
inputId: string;
|
|
8
|
-
}
|
|
9
|
-
]>;
|
|
10
|
-
type Props = HTMLInputAttributes & {
|
|
11
|
-
offLabel?: string | LabelSnippet;
|
|
12
|
-
onLabel?: string | LabelSnippet;
|
|
13
|
-
vertical?: boolean | null | undefined;
|
|
14
|
-
};
|
|
15
|
-
declare const Switch: import("svelte").Component<Props, {
|
|
16
|
-
blur: () => void;
|
|
17
|
-
click: () => void;
|
|
18
|
-
focus: (options?: FocusOptions) => void;
|
|
19
|
-
}, "checked">;
|
|
20
|
-
type Switch = ReturnType<typeof Switch>;
|
|
21
|
-
export default Switch;
|
package/dist/Tab.svelte
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
<svelte:options runes={true} />
|
|
2
|
-
|
|
3
|
-
<script lang="ts">import { getContext } from 'svelte';
|
|
4
|
-
import { TAB_LIST_CONTEXT_KEY } from './TabList.constants';
|
|
5
|
-
import { usingKeyboard } from './mediaQueries/usingKeyboard';
|
|
6
|
-
let { children, class: _class, disabled = false, value, ...rest } = $props();
|
|
7
|
-
let tabRef;
|
|
8
|
-
const tabListContext = getContext(TAB_LIST_CONTEXT_KEY);
|
|
9
|
-
let selected = $state(tabListContext.selectedValue === value);
|
|
10
|
-
let _disabled = $derived(tabListContext.disabled || disabled);
|
|
11
|
-
// Using $derived would be preferred, but this helps avoid
|
|
12
|
-
// updates to every tab when selectedValue changes.
|
|
13
|
-
// let selected = $derived(tabContext.selectedValue === value);
|
|
14
|
-
$effect(() => {
|
|
15
|
-
if (tabListContext.selectedValue === value && !selected) {
|
|
16
|
-
selected = true;
|
|
17
|
-
}
|
|
18
|
-
else if (tabListContext.selectedValue !== value && selected) {
|
|
19
|
-
selected = false;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
export const click = () => {
|
|
23
|
-
tabRef?.click();
|
|
24
|
-
};
|
|
25
|
-
export const blur = () => {
|
|
26
|
-
tabRef?.blur();
|
|
27
|
-
};
|
|
28
|
-
export const focus = (options) => {
|
|
29
|
-
tabRef?.focus(options);
|
|
30
|
-
};
|
|
31
|
-
</script>
|
|
32
|
-
|
|
33
|
-
<button
|
|
34
|
-
bind:this={tabRef}
|
|
35
|
-
aria-selected={selected}
|
|
36
|
-
class={`sterling-tab ${_class}`}
|
|
37
|
-
class:selected
|
|
38
|
-
class:using-keyboard={$usingKeyboard}
|
|
39
|
-
class:vertical={tabListContext.vertical}
|
|
40
|
-
data-value={value}
|
|
41
|
-
disabled={_disabled}
|
|
42
|
-
role="tab"
|
|
43
|
-
type="button"
|
|
44
|
-
tabIndex={selected ? 0 : -1}
|
|
45
|
-
{...rest}
|
|
46
|
-
>
|
|
47
|
-
<div class="content">
|
|
48
|
-
{@render children?.()}
|
|
49
|
-
</div>
|
|
50
|
-
<div class="indicator"></div>
|
|
51
|
-
</button>
|
package/dist/Tab.svelte.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/// <reference types="svelte" />
|
|
2
|
-
import type { HTMLButtonAttributes } from 'svelte/elements';
|
|
3
|
-
type Props = HTMLButtonAttributes & {
|
|
4
|
-
value: string;
|
|
5
|
-
};
|
|
6
|
-
declare const Tab: import("svelte").Component<Props, {
|
|
7
|
-
click: () => void;
|
|
8
|
-
blur: () => void;
|
|
9
|
-
focus: (options?: FocusOptions) => void;
|
|
10
|
-
}, "">;
|
|
11
|
-
type Tab = ReturnType<typeof Tab>;
|
|
12
|
-
export default Tab;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const TAB_LIST_CONTEXT_KEY = "sterlingTabList";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const TAB_LIST_CONTEXT_KEY = 'sterlingTabList';
|