@geoffcox/sterling-svelte 2.0.2 → 2.0.4
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 +18 -0
- package/dist/@types/clickOutside.d.ts +15 -0
- package/dist/Button.svelte +29 -0
- package/dist/Button.svelte.d.ts +8 -0
- package/dist/Callout.svelte +243 -0
- package/dist/Callout.svelte.d.ts +14 -0
- package/dist/Callout.types.d.ts +11 -0
- package/dist/Callout.types.js +1 -0
- package/dist/Checkbox.svelte +62 -0
- package/dist/Checkbox.svelte.d.ts +9 -0
- package/dist/Dialog.svelte +201 -0
- package/dist/Dialog.svelte.d.ts +14 -0
- package/dist/Dropdown.svelte +159 -0
- package/dist/Dropdown.svelte.d.ts +23 -0
- package/dist/Input.svelte +80 -0
- package/dist/Input.svelte.d.ts +11 -0
- package/dist/Label.constants.d.ts +2 -0
- package/dist/Label.constants.js +2 -0
- package/dist/Label.svelte +135 -0
- package/dist/Label.svelte.d.ts +17 -0
- package/dist/Link.svelte +31 -0
- package/dist/Link.svelte.d.ts +11 -0
- package/dist/List.constants.d.ts +1 -0
- package/dist/List.constants.js +1 -0
- package/dist/List.svelte +258 -0
- package/dist/List.svelte.d.ts +19 -0
- package/dist/List.types.d.ts +5 -0
- package/dist/List.types.js +1 -0
- package/dist/ListItem.svelte +64 -0
- package/dist/ListItem.svelte.d.ts +12 -0
- package/dist/Menu.svelte +105 -0
- package/dist/Menu.svelte.d.ts +12 -0
- package/dist/MenuBar.constants.d.ts +1 -0
- package/dist/MenuBar.constants.js +1 -0
- package/dist/MenuBar.svelte +144 -0
- package/dist/MenuBar.svelte.d.ts +12 -0
- package/dist/MenuBar.types.d.ts +4 -0
- package/dist/MenuBar.types.js +1 -0
- package/dist/MenuButton.svelte +156 -0
- package/dist/MenuButton.svelte.d.ts +20 -0
- package/dist/MenuItem.constants.d.ts +2 -0
- package/dist/MenuItem.constants.js +2 -0
- package/dist/MenuItem.svelte +431 -0
- package/dist/MenuItem.svelte.d.ts +22 -0
- package/dist/MenuItem.types.d.ts +20 -0
- package/dist/MenuItem.types.js +1 -0
- package/dist/MenuItem.utils.d.ts +7 -0
- package/dist/MenuItem.utils.js +36 -0
- package/dist/MenuSeparator.svelte +11 -0
- package/dist/MenuSeparator.svelte.d.ts +5 -0
- 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.constants.d.ts +1 -0
- package/dist/Popover.constants.js +14 -0
- package/dist/Popover.svelte +175 -0
- package/dist/Popover.svelte.d.ts +14 -0
- package/dist/Popover.types.d.ts +4 -0
- package/dist/Popover.types.js +1 -0
- package/dist/Portal.constants.d.ts +2 -0
- package/dist/Portal.constants.js +2 -0
- package/dist/Portal.types.d.ts +3 -0
- package/dist/Portal.types.js +1 -0
- package/dist/Progress.constants.d.ts +1 -0
- package/dist/Progress.constants.js +1 -0
- package/dist/Progress.svelte +61 -0
- package/dist/Progress.svelte.d.ts +11 -0
- package/dist/Progress.types.d.ts +4 -0
- package/dist/Progress.types.js +1 -0
- package/dist/Radio.svelte +65 -0
- package/dist/Radio.svelte.d.ts +12 -0
- package/dist/Select.svelte +262 -0
- package/dist/Select.svelte.d.ts +26 -0
- package/dist/Slider.svelte +182 -0
- package/dist/Slider.svelte.d.ts +18 -0
- package/dist/Switch.svelte +92 -0
- package/dist/Switch.svelte.d.ts +21 -0
- package/dist/Tab.svelte +66 -0
- package/dist/Tab.svelte.d.ts +11 -0
- package/dist/TabList.constants.d.ts +1 -0
- package/dist/TabList.constants.js +1 -0
- package/dist/TabList.svelte +253 -0
- package/dist/TabList.svelte.d.ts +17 -0
- package/dist/TabList.types.d.ts +5 -0
- package/dist/TabList.types.js +1 -0
- package/dist/TextArea.constants.d.ts +1 -0
- package/dist/TextArea.constants.js +1 -0
- package/dist/TextArea.svelte +116 -0
- package/dist/TextArea.svelte.d.ts +18 -0
- package/dist/TextArea.types.d.ts +4 -0
- package/dist/TextArea.types.js +1 -0
- package/dist/Tooltip.svelte +95 -0
- package/dist/Tooltip.svelte.d.ts +10 -0
- package/dist/Tree.constants.d.ts +1 -0
- package/dist/Tree.constants.js +1 -0
- package/dist/Tree.svelte +81 -0
- package/dist/Tree.svelte.d.ts +14 -0
- package/dist/Tree.types.d.ts +5 -0
- package/dist/Tree.types.js +1 -0
- package/dist/TreeChevron.svelte +39 -0
- package/dist/TreeChevron.svelte.d.ts +8 -0
- package/dist/TreeItem.constants.d.ts +1 -0
- package/dist/TreeItem.constants.js +1 -0
- package/dist/TreeItem.svelte +396 -0
- package/dist/TreeItem.svelte.d.ts +22 -0
- package/dist/TreeItem.types.d.ts +4 -0
- package/dist/TreeItem.types.js +1 -0
- package/dist/actions/applyLightDarkMode.d.ts +11 -0
- package/dist/actions/applyLightDarkMode.js +37 -0
- package/dist/actions/clickOutside.d.ts +15 -0
- package/dist/actions/clickOutside.js +28 -0
- package/dist/actions/colorScheme.d.ts +8 -0
- package/dist/actions/colorScheme.js +26 -0
- package/dist/actions/extraClass.d.ts +9 -0
- package/dist/actions/extraClass.js +15 -0
- package/dist/actions/forwardEvents.d.ts +12 -0
- package/dist/actions/forwardEvents.js +32 -0
- package/dist/actions/portal.d.ts +8 -0
- package/dist/actions/portal.js +19 -0
- package/dist/actions/trapKeyboardFocus.d.ts +3 -0
- package/dist/actions/trapKeyboardFocus.js +52 -0
- package/dist/idGenerator.d.ts +5 -0
- package/dist/idGenerator.js +11 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +56 -0
- package/dist/mediaQueries/prefersColorSchemeDark.d.ts +1 -0
- package/dist/mediaQueries/prefersColorSchemeDark.js +14 -0
- package/dist/mediaQueries/prefersReducedMotion.d.ts +1 -0
- package/dist/mediaQueries/prefersReducedMotion.js +14 -0
- package/dist/mediaQueries/usingKeyboard.d.ts +1 -0
- package/dist/mediaQueries/usingKeyboard.js +17 -0
- package/package.json +17 -13
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
<svelte:options runes={true} />
|
|
2
|
+
|
|
3
|
+
<script lang="ts">
|
|
4
|
+
import { type Snippet } from 'svelte';
|
|
5
|
+
import type { HTMLAttributes, KeyboardEventHandler, MouseEventHandler } from 'svelte/elements';
|
|
6
|
+
import { slide, type SlideParams, type TransitionConfig } from 'svelte/transition';
|
|
7
|
+
import { clickOutside } from './actions/clickOutside';
|
|
8
|
+
import { prefersReducedMotion } from './mediaQueries/prefersReducedMotion';
|
|
9
|
+
import { usingKeyboard } from './mediaQueries/usingKeyboard';
|
|
10
|
+
import Popover from './Popover.svelte';
|
|
11
|
+
|
|
12
|
+
const uuid = $props.id();
|
|
13
|
+
|
|
14
|
+
const popoverId = `Dropdown-Popover-${uuid}`;
|
|
15
|
+
|
|
16
|
+
type DeprecatedProps = {
|
|
17
|
+
/** @deprecated Use icon instead. */
|
|
18
|
+
button?: Snippet;
|
|
19
|
+
/** @deprecated Use icon instead. */
|
|
20
|
+
buttonIcon?: Snippet;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type Props = HTMLAttributes<HTMLDivElement> &
|
|
24
|
+
DeprecatedProps & {
|
|
25
|
+
disabled?: boolean | null | undefined;
|
|
26
|
+
open?: boolean | null | undefined;
|
|
27
|
+
stayOpenOnClickAway?: boolean | null | undefined;
|
|
28
|
+
onOpen?: (open: boolean | null | undefined) => void;
|
|
29
|
+
icon?: Snippet;
|
|
30
|
+
value?: string | Snippet;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
let {
|
|
34
|
+
button,
|
|
35
|
+
buttonIcon,
|
|
36
|
+
class: _class,
|
|
37
|
+
children,
|
|
38
|
+
disabled = false,
|
|
39
|
+
icon,
|
|
40
|
+
open = $bindable(false),
|
|
41
|
+
onOpen,
|
|
42
|
+
stayOpenOnClickAway = false,
|
|
43
|
+
value,
|
|
44
|
+
...rest
|
|
45
|
+
}: Props = $props();
|
|
46
|
+
|
|
47
|
+
icon = icon || buttonIcon || button;
|
|
48
|
+
|
|
49
|
+
// svelte-ignore non_reactive_update
|
|
50
|
+
let dropdownRef: HTMLDivElement | undefined = $state(undefined);
|
|
51
|
+
|
|
52
|
+
// svelte-ignore non_reactive_update
|
|
53
|
+
let popupContentRef: HTMLDivElement | undefined = $state(undefined);
|
|
54
|
+
|
|
55
|
+
// ----- Reactions ----- //
|
|
56
|
+
|
|
57
|
+
$effect(() => {
|
|
58
|
+
onOpen?.(open);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// ----- Methods ----- //
|
|
62
|
+
|
|
63
|
+
export const click = () => {
|
|
64
|
+
dropdownRef?.click();
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const blur = () => {
|
|
68
|
+
dropdownRef?.blur();
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const focus = (options?: FocusOptions) => {
|
|
72
|
+
dropdownRef?.focus(options);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const onClick: MouseEventHandler<HTMLDivElement> = (event) => {
|
|
76
|
+
if (!disabled) {
|
|
77
|
+
open = !open;
|
|
78
|
+
event.preventDefault();
|
|
79
|
+
event.stopPropagation();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
rest.onclick?.(event);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const onKeydown: KeyboardEventHandler<HTMLDivElement> = (event) => {
|
|
86
|
+
if (!event.altKey && !event.ctrlKey && !event.shiftKey) {
|
|
87
|
+
switch (event.key) {
|
|
88
|
+
case ' ':
|
|
89
|
+
open = !open;
|
|
90
|
+
event.preventDefault();
|
|
91
|
+
event.stopPropagation();
|
|
92
|
+
case 'Escape':
|
|
93
|
+
open = false;
|
|
94
|
+
event.preventDefault();
|
|
95
|
+
event.stopPropagation();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
rest.onkeydown?.(event);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const onClickOutside = (event: MouseEvent) => {
|
|
103
|
+
if (!stayOpenOnClickAway) {
|
|
104
|
+
open = false;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// ----- Animation ----- //
|
|
109
|
+
|
|
110
|
+
const slideNoOp = (node: Element, params?: SlideParams): TransitionConfig => {
|
|
111
|
+
return { delay: 0, duration: 0 };
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
let slideMotion = $derived(!$prefersReducedMotion ? slide : slideNoOp);
|
|
115
|
+
</script>
|
|
116
|
+
|
|
117
|
+
<div
|
|
118
|
+
bind:this={dropdownRef}
|
|
119
|
+
aria-controls={popoverId}
|
|
120
|
+
aria-haspopup={true}
|
|
121
|
+
aria-expanded={open}
|
|
122
|
+
class={['sterling-dropdown', _class]}
|
|
123
|
+
class:disabled
|
|
124
|
+
class:open
|
|
125
|
+
class:using-keyboard={$usingKeyboard}
|
|
126
|
+
role="combobox"
|
|
127
|
+
tabindex="0"
|
|
128
|
+
use:clickOutside={{ ignoreOthers: [popupContentRef!], onclickoutside: onClickOutside }}
|
|
129
|
+
{...rest}
|
|
130
|
+
onclick={onClick}
|
|
131
|
+
onkeydown={onKeydown}
|
|
132
|
+
>
|
|
133
|
+
<div class="value">
|
|
134
|
+
{#if value}
|
|
135
|
+
{#if typeof value === 'string'}
|
|
136
|
+
{value}
|
|
137
|
+
{:else}
|
|
138
|
+
{@render value()}
|
|
139
|
+
{/if}
|
|
140
|
+
{/if}
|
|
141
|
+
</div>
|
|
142
|
+
<div class="button icon">
|
|
143
|
+
{#if icon}
|
|
144
|
+
{@render icon()}
|
|
145
|
+
{:else}
|
|
146
|
+
<div class="chevron"></div>
|
|
147
|
+
{/if}
|
|
148
|
+
</div>
|
|
149
|
+
|
|
150
|
+
<Popover id={popoverId} reference={dropdownRef} open={!disabled && open} placement="bottom-start">
|
|
151
|
+
<div
|
|
152
|
+
class={['sterling-dropdown-popup-content', 'sterling-dropdown-content', _class]}
|
|
153
|
+
transition:slideMotion|global={{ duration: 200 }}
|
|
154
|
+
bind:this={popupContentRef}
|
|
155
|
+
>
|
|
156
|
+
{@render children?.()}
|
|
157
|
+
</div>
|
|
158
|
+
</Popover>
|
|
159
|
+
</div>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
type DeprecatedProps = {
|
|
4
|
+
/** @deprecated Use icon instead. */
|
|
5
|
+
button?: Snippet;
|
|
6
|
+
/** @deprecated Use icon instead. */
|
|
7
|
+
buttonIcon?: Snippet;
|
|
8
|
+
};
|
|
9
|
+
type Props = HTMLAttributes<HTMLDivElement> & DeprecatedProps & {
|
|
10
|
+
disabled?: boolean | null | undefined;
|
|
11
|
+
open?: boolean | null | undefined;
|
|
12
|
+
stayOpenOnClickAway?: boolean | null | undefined;
|
|
13
|
+
onOpen?: (open: boolean | null | undefined) => void;
|
|
14
|
+
icon?: Snippet;
|
|
15
|
+
value?: string | Snippet;
|
|
16
|
+
};
|
|
17
|
+
declare const Dropdown: import("svelte").Component<Props, {
|
|
18
|
+
click: () => void;
|
|
19
|
+
blur: () => void;
|
|
20
|
+
focus: (options?: FocusOptions) => void;
|
|
21
|
+
}, "open">;
|
|
22
|
+
type Dropdown = ReturnType<typeof Dropdown>;
|
|
23
|
+
export default Dropdown;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
<svelte:options runes={true} />
|
|
2
|
+
|
|
3
|
+
<script lang="ts">
|
|
4
|
+
import type { HTMLInputAttributes } from 'svelte/elements';
|
|
5
|
+
import { usingKeyboard } from './mediaQueries/usingKeyboard';
|
|
6
|
+
|
|
7
|
+
const uuid = $props.id();
|
|
8
|
+
|
|
9
|
+
type Props = HTMLInputAttributes;
|
|
10
|
+
|
|
11
|
+
let {
|
|
12
|
+
id,
|
|
13
|
+
children,
|
|
14
|
+
class: _class,
|
|
15
|
+
disabled = false,
|
|
16
|
+
value = $bindable(undefined),
|
|
17
|
+
...rest
|
|
18
|
+
}: Props = $props();
|
|
19
|
+
|
|
20
|
+
let inputRef: HTMLInputElement;
|
|
21
|
+
|
|
22
|
+
$effect(() => {
|
|
23
|
+
if (children && id === undefined) {
|
|
24
|
+
id = `Input-${uuid}`;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export const blur = () => {
|
|
29
|
+
inputRef?.blur();
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const click = () => {
|
|
33
|
+
inputRef?.click();
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const focus = (options?: FocusOptions) => {
|
|
37
|
+
inputRef?.focus();
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const select = () => {
|
|
41
|
+
inputRef?.select();
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const setSelectionRange = (
|
|
45
|
+
start: number | null,
|
|
46
|
+
end: number | null,
|
|
47
|
+
direction?: 'forward' | 'backward' | 'none'
|
|
48
|
+
) => {
|
|
49
|
+
inputRef?.setSelectionRange(start, end, direction);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const setRangeText = (
|
|
53
|
+
replacement: string,
|
|
54
|
+
start?: number,
|
|
55
|
+
end?: number,
|
|
56
|
+
selectionMode?: SelectionMode
|
|
57
|
+
) => {
|
|
58
|
+
if (start && end) {
|
|
59
|
+
inputRef?.setRangeText(replacement, start, end, selectionMode);
|
|
60
|
+
} else {
|
|
61
|
+
inputRef?.setRangeText(replacement);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
{#if children}
|
|
67
|
+
<label class={['sterling-input-label', _class]} class:disabled for={id}>
|
|
68
|
+
{@render children()}
|
|
69
|
+
</label>
|
|
70
|
+
{/if}
|
|
71
|
+
<div class={['sterling-input', _class]} class:disabled class:using-keyboard={$usingKeyboard}>
|
|
72
|
+
<input
|
|
73
|
+
bind:this={inputRef}
|
|
74
|
+
class:using-keyboard={$usingKeyboard}
|
|
75
|
+
{disabled}
|
|
76
|
+
{id}
|
|
77
|
+
bind:value
|
|
78
|
+
{...rest}
|
|
79
|
+
/>
|
|
80
|
+
</div>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HTMLInputAttributes } from 'svelte/elements';
|
|
2
|
+
declare const Input: import("svelte").Component<HTMLInputAttributes, {
|
|
3
|
+
blur: () => void;
|
|
4
|
+
click: () => void;
|
|
5
|
+
focus: (options?: FocusOptions) => void;
|
|
6
|
+
select: () => void;
|
|
7
|
+
setSelectionRange: (start: number | null, end: number | null, direction?: "forward" | "backward" | "none") => void;
|
|
8
|
+
setRangeText: (replacement: string, start?: number, end?: number, selectionMode?: SelectionMode) => void;
|
|
9
|
+
}, "value">;
|
|
10
|
+
type Input = ReturnType<typeof Input>;
|
|
11
|
+
export default Input;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
<svelte:options runes={true} />
|
|
2
|
+
|
|
3
|
+
<script lang="ts">
|
|
4
|
+
import { type Snippet } from 'svelte';
|
|
5
|
+
import type { HTMLLabelAttributes, MouseEventHandler } from 'svelte/elements';
|
|
6
|
+
import Tooltip from './Tooltip.svelte';
|
|
7
|
+
import { usingKeyboard } from './mediaQueries/usingKeyboard';
|
|
8
|
+
|
|
9
|
+
type Props = HTMLLabelAttributes & {
|
|
10
|
+
forwardClick?: boolean | null;
|
|
11
|
+
message?: Snippet | string;
|
|
12
|
+
required?: boolean | null;
|
|
13
|
+
requiredIndicator?: Snippet | string;
|
|
14
|
+
requiredReason?: Snippet | string;
|
|
15
|
+
text?: Snippet | string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
let {
|
|
19
|
+
children,
|
|
20
|
+
class: _class,
|
|
21
|
+
for: _for,
|
|
22
|
+
forwardClick = false,
|
|
23
|
+
message,
|
|
24
|
+
required,
|
|
25
|
+
requiredIndicator = '*',
|
|
26
|
+
requiredReason,
|
|
27
|
+
text,
|
|
28
|
+
...rest
|
|
29
|
+
}: Props = $props();
|
|
30
|
+
|
|
31
|
+
// ----- State ----- //
|
|
32
|
+
|
|
33
|
+
let labelRef: HTMLLabelElement | null = $state(null);
|
|
34
|
+
let targetRef: HTMLElement | null = $state(null);
|
|
35
|
+
|
|
36
|
+
const findTarget = () => {
|
|
37
|
+
let candidate: HTMLElement | null = null;
|
|
38
|
+
if (_for) {
|
|
39
|
+
candidate = labelRef?.querySelector<HTMLElement>(`[id="${_for}"]`) || null;
|
|
40
|
+
}
|
|
41
|
+
if (!candidate) {
|
|
42
|
+
candidate =
|
|
43
|
+
labelRef?.querySelector<HTMLElement>(
|
|
44
|
+
'a[href], ' +
|
|
45
|
+
'audio[controls], ' +
|
|
46
|
+
'button, ' +
|
|
47
|
+
'details, ' +
|
|
48
|
+
'div[contenteditable], ' +
|
|
49
|
+
'form, ' +
|
|
50
|
+
'input, ' +
|
|
51
|
+
'select, ' +
|
|
52
|
+
'textarea, ' +
|
|
53
|
+
'video[controls], ' +
|
|
54
|
+
'[tabindex]:not([tabindex="-1"])'
|
|
55
|
+
) || null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
targetRef = candidate;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// ----- Methods ----- //
|
|
62
|
+
|
|
63
|
+
export const click = () => {
|
|
64
|
+
labelRef?.click();
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const blur = () => {
|
|
68
|
+
labelRef?.blur();
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const focus = (options?: FocusOptions) => {
|
|
72
|
+
labelRef?.focus(options);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// ----- Event Handlers ----- //
|
|
76
|
+
|
|
77
|
+
const onClick: MouseEventHandler<HTMLLabelElement> = (event) => {
|
|
78
|
+
if (forwardClick) {
|
|
79
|
+
targetRef?.click();
|
|
80
|
+
}
|
|
81
|
+
rest.onclick?.(event);
|
|
82
|
+
};
|
|
83
|
+
</script>
|
|
84
|
+
|
|
85
|
+
{#snippet stringOrSnippet(item?: string | Snippet)}
|
|
86
|
+
{#if item}
|
|
87
|
+
{#if typeof item === 'string'}
|
|
88
|
+
{item}
|
|
89
|
+
{:else}
|
|
90
|
+
{@render item()}
|
|
91
|
+
{/if}
|
|
92
|
+
{/if}
|
|
93
|
+
{/snippet}
|
|
94
|
+
|
|
95
|
+
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
96
|
+
<label
|
|
97
|
+
bind:this={labelRef}
|
|
98
|
+
class={['sterling-label', _class]}
|
|
99
|
+
class:using-keyboard={$usingKeyboard}
|
|
100
|
+
for={_for}
|
|
101
|
+
{...rest}
|
|
102
|
+
onclick={onClick}
|
|
103
|
+
>
|
|
104
|
+
{#if text}
|
|
105
|
+
<div class="text">
|
|
106
|
+
{@render stringOrSnippet(text)}
|
|
107
|
+
</div>
|
|
108
|
+
{/if}
|
|
109
|
+
{#if children}
|
|
110
|
+
<div class="content">
|
|
111
|
+
{@render children()}
|
|
112
|
+
</div>
|
|
113
|
+
{/if}
|
|
114
|
+
{#if message}
|
|
115
|
+
<div class="message">
|
|
116
|
+
{@render stringOrSnippet(message)}
|
|
117
|
+
</div>
|
|
118
|
+
{/if}
|
|
119
|
+
{#if required && requiredIndicator && requiredReason}
|
|
120
|
+
<Tooltip>
|
|
121
|
+
<div class="required">
|
|
122
|
+
{@render stringOrSnippet(requiredIndicator)}
|
|
123
|
+
</div>
|
|
124
|
+
{#snippet tip()}
|
|
125
|
+
<div class="required-reason">
|
|
126
|
+
{@render stringOrSnippet(requiredReason)}
|
|
127
|
+
</div>
|
|
128
|
+
{/snippet}
|
|
129
|
+
</Tooltip>
|
|
130
|
+
{:else if required && requiredIndicator}
|
|
131
|
+
<div class="required">
|
|
132
|
+
{@render stringOrSnippet(requiredIndicator)}
|
|
133
|
+
</div>
|
|
134
|
+
{/if}
|
|
135
|
+
</label>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLLabelAttributes } from 'svelte/elements';
|
|
3
|
+
type Props = HTMLLabelAttributes & {
|
|
4
|
+
forwardClick?: boolean | null;
|
|
5
|
+
message?: Snippet | string;
|
|
6
|
+
required?: boolean | null;
|
|
7
|
+
requiredIndicator?: Snippet | string;
|
|
8
|
+
requiredReason?: Snippet | string;
|
|
9
|
+
text?: Snippet | string;
|
|
10
|
+
};
|
|
11
|
+
declare const Label: import("svelte").Component<Props, {
|
|
12
|
+
click: () => void;
|
|
13
|
+
blur: () => void;
|
|
14
|
+
focus: (options?: FocusOptions) => void;
|
|
15
|
+
}, "">;
|
|
16
|
+
type Label = ReturnType<typeof Label>;
|
|
17
|
+
export default Label;
|
package/dist/Link.svelte
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<svelte:options runes={true} />
|
|
2
|
+
|
|
3
|
+
<script lang="ts">
|
|
4
|
+
import type { HTMLAnchorAttributes } from 'svelte/elements';
|
|
5
|
+
|
|
6
|
+
type Props = HTMLAnchorAttributes & {
|
|
7
|
+
disabled?: boolean | null;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
let { children, class: _class, disabled, ...rest }: Props = $props();
|
|
11
|
+
|
|
12
|
+
let linkRef: HTMLAnchorElement;
|
|
13
|
+
|
|
14
|
+
export const blur = () => {
|
|
15
|
+
linkRef?.blur();
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const click = () => {
|
|
19
|
+
linkRef?.click();
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const focus = (options?: FocusOptions) => {
|
|
23
|
+
linkRef?.focus();
|
|
24
|
+
};
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<a bind:this={linkRef} class={['sterling-link', _class]} class:disabled {...rest}>
|
|
28
|
+
{#if children}
|
|
29
|
+
{@render children()}
|
|
30
|
+
{/if}
|
|
31
|
+
</a>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HTMLAnchorAttributes } from 'svelte/elements';
|
|
2
|
+
type Props = HTMLAnchorAttributes & {
|
|
3
|
+
disabled?: boolean | null;
|
|
4
|
+
};
|
|
5
|
+
declare const Link: import("svelte").Component<Props, {
|
|
6
|
+
blur: () => void;
|
|
7
|
+
click: () => void;
|
|
8
|
+
focus: (options?: FocusOptions) => void;
|
|
9
|
+
}, "">;
|
|
10
|
+
type Link = ReturnType<typeof Link>;
|
|
11
|
+
export default Link;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const LIST_CONTEXT_KEY = "sterlingList";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const LIST_CONTEXT_KEY = 'sterlingList';
|