@geoffcox/sterling-svelte 2.0.4 → 2.0.6
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/dist/Autocomplete.svelte +154 -0
- package/dist/Autocomplete.svelte.d.ts +4 -0
- package/dist/Autocomplete.types.d.ts +7 -0
- package/dist/Autocomplete.types.js +1 -0
- package/dist/Button.svelte +2 -4
- package/dist/Button.svelte.d.ts +1 -2
- package/dist/Button.types.d.ts +2 -0
- package/dist/Button.types.js +1 -0
- package/dist/Callout.svelte +2 -11
- package/dist/Callout.svelte.d.ts +2 -12
- package/dist/Checkbox.svelte +2 -4
- package/dist/Checkbox.svelte.d.ts +1 -2
- package/dist/Checkbox.types.d.ts +2 -0
- package/dist/Checkbox.types.js +1 -0
- package/dist/Dialog.svelte +4 -14
- package/dist/Dialog.svelte.d.ts +2 -12
- package/dist/Dialog.types.d.ts +11 -0
- package/dist/Dialog.types.js +1 -0
- package/dist/Dropdown.svelte +3 -20
- package/dist/Dropdown.svelte.d.ts +2 -17
- package/dist/Dropdown.types.d.ts +17 -0
- package/dist/Dropdown.types.js +1 -0
- package/dist/Input.svelte +2 -4
- package/dist/Input.svelte.d.ts +1 -2
- package/dist/Input.types.d.ts +2 -0
- package/dist/Input.types.js +1 -0
- package/dist/Label.svelte +111 -24
- package/dist/Label.svelte.d.ts +2 -11
- package/dist/Label.types.d.ts +18 -0
- package/dist/Label.types.js +1 -0
- package/dist/Link.svelte +2 -6
- package/dist/Link.svelte.d.ts +2 -5
- package/dist/Link.types.d.ts +4 -0
- package/dist/Link.types.js +1 -0
- package/dist/List.svelte +3 -10
- package/dist/List.svelte.d.ts +2 -8
- package/dist/List.types.d.ts +7 -0
- package/dist/ListItem.svelte +2 -7
- package/dist/ListItem.svelte.d.ts +2 -6
- package/dist/ListItem.types.d.ts +5 -0
- package/dist/ListItem.types.js +1 -0
- package/dist/Menu.svelte +2 -4
- package/dist/Menu.svelte.d.ts +2 -3
- package/dist/Menu.types.d.ts +2 -0
- package/dist/Menu.types.js +1 -0
- package/dist/MenuBar.svelte +2 -9
- package/dist/MenuBar.svelte.d.ts +2 -7
- package/dist/MenuBar.types.d.ts +6 -0
- package/dist/MenuButton.svelte +2 -12
- package/dist/MenuButton.svelte.d.ts +2 -14
- package/dist/MenuButton.types.d.ts +13 -0
- package/dist/MenuButton.types.js +1 -0
- package/dist/MenuItem.svelte +4 -21
- package/dist/MenuItem.svelte.d.ts +2 -16
- package/dist/MenuItem.types.d.ts +14 -0
- package/dist/MenuSeparator.svelte +2 -4
- package/dist/MenuSeparator.svelte.d.ts +2 -3
- package/dist/MenuSeparator.types.d.ts +2 -0
- package/dist/MenuSeparator.types.js +1 -0
- package/dist/Popover.svelte +3 -13
- package/dist/Popover.svelte.d.ts +2 -12
- package/dist/Popover.types.d.ts +10 -0
- package/dist/Progress.svelte +2 -10
- package/dist/Progress.svelte.d.ts +2 -9
- package/dist/Progress.types.d.ts +8 -0
- package/dist/Radio.svelte +2 -6
- package/dist/Radio.svelte.d.ts +2 -5
- package/dist/Radio.types.d.ts +4 -0
- package/dist/Radio.types.js +1 -0
- package/dist/Select.svelte +4 -23
- package/dist/Select.svelte.d.ts +2 -19
- package/dist/Select.types.d.ts +19 -0
- package/dist/Select.types.js +1 -0
- package/dist/Slider.svelte +3 -13
- package/dist/Slider.svelte.d.ts +2 -12
- package/dist/Slider.types.d.ts +11 -0
- package/dist/Slider.types.js +1 -0
- package/dist/Switch.svelte +2 -13
- package/dist/Switch.svelte.d.ts +2 -15
- package/dist/Switch.types.d.ts +14 -0
- package/dist/Switch.types.js +1 -0
- package/dist/Tab.svelte +2 -6
- package/dist/Tab.svelte.d.ts +2 -5
- package/dist/Tab.types.d.ts +4 -0
- package/dist/Tab.types.js +1 -0
- package/dist/TabList.svelte +3 -10
- package/dist/TabList.svelte.d.ts +2 -8
- package/dist/TabList.types.d.ts +7 -0
- package/dist/TextArea.svelte +4 -11
- package/dist/TextArea.svelte.d.ts +3 -10
- package/dist/TextArea.types.d.ts +7 -0
- package/dist/Tooltip.svelte +24 -16
- package/dist/Tooltip.svelte.d.ts +2 -8
- package/dist/Tooltip.types.d.ts +7 -0
- package/dist/Tooltip.types.js +1 -0
- package/dist/Tree.svelte +2 -11
- package/dist/Tree.svelte.d.ts +2 -9
- package/dist/Tree.types.d.ts +8 -0
- package/dist/TreeChevron.svelte +8 -8
- package/dist/TreeChevron.svelte.d.ts +2 -6
- package/dist/TreeChevron.types.d.ts +5 -0
- package/dist/TreeChevron.types.js +1 -0
- package/dist/TreeItem.svelte +4 -11
- package/dist/TreeItem.svelte.d.ts +2 -9
- package/dist/TreeItem.types.d.ts +8 -0
- package/dist/index.d.ts +32 -10
- package/dist/index.js +4 -3
- package/package.json +3 -2
package/dist/Label.svelte
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
<svelte:options runes={true} />
|
|
2
2
|
|
|
3
3
|
<script lang="ts">
|
|
4
|
-
import { type Snippet } from 'svelte';
|
|
4
|
+
import { onMount, type Snippet } from 'svelte';
|
|
5
5
|
import type { HTMLLabelAttributes, MouseEventHandler } from 'svelte/elements';
|
|
6
6
|
import Tooltip from './Tooltip.svelte';
|
|
7
7
|
import { usingKeyboard } from './mediaQueries/usingKeyboard';
|
|
8
|
+
import type { LabelProps } from './Label.types';
|
|
8
9
|
|
|
9
|
-
|
|
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
|
-
};
|
|
10
|
+
//TODO: All component props types should be exported on index
|
|
17
11
|
|
|
18
12
|
let {
|
|
19
13
|
children,
|
|
20
14
|
class: _class,
|
|
21
15
|
for: _for,
|
|
16
|
+
formValidation,
|
|
22
17
|
forwardClick = false,
|
|
18
|
+
onValidation,
|
|
23
19
|
message,
|
|
24
20
|
required,
|
|
25
21
|
requiredIndicator = '*',
|
|
26
22
|
requiredReason,
|
|
27
23
|
text,
|
|
28
24
|
...rest
|
|
29
|
-
}:
|
|
25
|
+
}: LabelProps = $props();
|
|
30
26
|
|
|
31
27
|
// ----- State ----- //
|
|
32
28
|
|
|
33
29
|
let labelRef: HTMLLabelElement | null = $state(null);
|
|
34
30
|
let targetRef: HTMLElement | null = $state(null);
|
|
31
|
+
let targetRequired: boolean | null | undefined = $state(false);
|
|
32
|
+
let valid: boolean | null | undefined = $state(true);
|
|
33
|
+
let validationMessage: string | Snippet | undefined = $state(undefined);
|
|
34
|
+
let validationClass: string | undefined = $state();
|
|
35
35
|
|
|
36
36
|
const findTarget = () => {
|
|
37
37
|
let candidate: HTMLElement | null = null;
|
|
@@ -74,12 +74,93 @@
|
|
|
74
74
|
|
|
75
75
|
// ----- Event Handlers ----- //
|
|
76
76
|
|
|
77
|
+
const updateValidity = () => {
|
|
78
|
+
if (formValidation) {
|
|
79
|
+
const validationTarget = targetRef as HTMLObjectElement;
|
|
80
|
+
if (validationTarget) {
|
|
81
|
+
const newValid = !!validationTarget.checkValidity?.();
|
|
82
|
+
const newValidity = validationTarget.validity;
|
|
83
|
+
const newValidationMessage = validationTarget.validationMessage;
|
|
84
|
+
|
|
85
|
+
const validationResult = onValidation?.(newValidity, newValidationMessage);
|
|
86
|
+
|
|
87
|
+
valid = validationResult?.valid || newValid;
|
|
88
|
+
validationClass = validationResult?.validationClass || valid ? undefined : 'error';
|
|
89
|
+
validationMessage = validationResult?.validationMessage || newValidationMessage;
|
|
90
|
+
|
|
91
|
+
// prevent the browser from showing a tooltip validation message
|
|
92
|
+
validationTarget.setCustomValidity?.('');
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
valid = true;
|
|
96
|
+
validationMessage = undefined;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
77
100
|
const onClick: MouseEventHandler<HTMLLabelElement> = (event) => {
|
|
78
101
|
if (forwardClick) {
|
|
79
102
|
targetRef?.click();
|
|
80
103
|
}
|
|
81
104
|
rest.onclick?.(event);
|
|
82
105
|
};
|
|
106
|
+
|
|
107
|
+
const updateTargetRequired = () => {
|
|
108
|
+
targetRequired = targetRef && 'required' in targetRef && !!targetRef.required;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
$inspect(targetRequired);
|
|
112
|
+
|
|
113
|
+
const onTargetAttributeChanged: MutationCallback = (mutations) => {
|
|
114
|
+
if (
|
|
115
|
+
mutations.findIndex(
|
|
116
|
+
(mutation: MutationRecord) =>
|
|
117
|
+
mutation.type === 'attributes' && mutation.attributeName === 'required'
|
|
118
|
+
) !== -1
|
|
119
|
+
) {
|
|
120
|
+
updateTargetRequired();
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
onMount(() => {
|
|
125
|
+
findTarget();
|
|
126
|
+
|
|
127
|
+
const observer = new MutationObserver(onTargetAttributeChanged);
|
|
128
|
+
|
|
129
|
+
if (targetRef) {
|
|
130
|
+
observer.observe(targetRef, {
|
|
131
|
+
attributes: true,
|
|
132
|
+
attributeFilter: ['required']
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
updateTargetRequired();
|
|
136
|
+
|
|
137
|
+
if ('on' + 'input' in targetRef) {
|
|
138
|
+
targetRef.addEventListener('input', updateValidity);
|
|
139
|
+
}
|
|
140
|
+
if ('on' + 'change' in targetRef) {
|
|
141
|
+
targetRef?.addEventListener('change', updateValidity);
|
|
142
|
+
}
|
|
143
|
+
if ('on' + 'blur' in targetRef) {
|
|
144
|
+
targetRef?.addEventListener('blur', updateValidity);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return () => {
|
|
149
|
+
if (targetRef) {
|
|
150
|
+
observer.disconnect();
|
|
151
|
+
|
|
152
|
+
if ('on' + 'input' in targetRef) {
|
|
153
|
+
targetRef.removeEventListener('input', updateValidity);
|
|
154
|
+
}
|
|
155
|
+
if ('on' + 'change' in targetRef) {
|
|
156
|
+
targetRef?.removeEventListener('change', updateValidity);
|
|
157
|
+
}
|
|
158
|
+
if ('on' + 'blur' in targetRef) {
|
|
159
|
+
targetRef?.removeEventListener('blur', updateValidity);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
});
|
|
83
164
|
</script>
|
|
84
165
|
|
|
85
166
|
{#snippet stringOrSnippet(item?: string | Snippet)}
|
|
@@ -95,7 +176,7 @@
|
|
|
95
176
|
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
96
177
|
<label
|
|
97
178
|
bind:this={labelRef}
|
|
98
|
-
class={['sterling-label', _class]}
|
|
179
|
+
class={['sterling-label', validationClass, _class]}
|
|
99
180
|
class:using-keyboard={$usingKeyboard}
|
|
100
181
|
for={_for}
|
|
101
182
|
{...rest}
|
|
@@ -111,25 +192,31 @@
|
|
|
111
192
|
{@render children()}
|
|
112
193
|
</div>
|
|
113
194
|
{/if}
|
|
114
|
-
{#if
|
|
195
|
+
{#if validationMessage}
|
|
196
|
+
<div class="message validation">
|
|
197
|
+
{@render stringOrSnippet(validationMessage)}
|
|
198
|
+
</div>
|
|
199
|
+
{:else if message}
|
|
115
200
|
<div class="message">
|
|
116
201
|
{@render stringOrSnippet(message)}
|
|
117
202
|
</div>
|
|
118
203
|
{/if}
|
|
119
|
-
{#if required
|
|
120
|
-
|
|
204
|
+
{#if required || (formValidation && targetRequired)}
|
|
205
|
+
{#if requiredIndicator && requiredReason}
|
|
206
|
+
<Tooltip class="sterling-label-tooltip">
|
|
207
|
+
<div class="required">
|
|
208
|
+
{@render stringOrSnippet(requiredIndicator)}
|
|
209
|
+
</div>
|
|
210
|
+
{#snippet tip()}
|
|
211
|
+
<div class="required-reason">
|
|
212
|
+
{@render stringOrSnippet(requiredReason)}
|
|
213
|
+
</div>
|
|
214
|
+
{/snippet}
|
|
215
|
+
</Tooltip>
|
|
216
|
+
{:else if requiredIndicator}
|
|
121
217
|
<div class="required">
|
|
122
218
|
{@render stringOrSnippet(requiredIndicator)}
|
|
123
219
|
</div>
|
|
124
|
-
|
|
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>
|
|
220
|
+
{/if}
|
|
134
221
|
{/if}
|
|
135
222
|
</label>
|
package/dist/Label.svelte.d.ts
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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, {
|
|
1
|
+
import type { LabelProps } from './Label.types';
|
|
2
|
+
declare const Label: import("svelte").Component<LabelProps, {
|
|
12
3
|
click: () => void;
|
|
13
4
|
blur: () => void;
|
|
14
5
|
focus: (options?: FocusOptions) => void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLLabelAttributes } from 'svelte/elements';
|
|
3
|
+
export type LabelValidationResult = {
|
|
4
|
+
valid: boolean;
|
|
5
|
+
validationClass?: string;
|
|
6
|
+
validationMessage?: Snippet | string;
|
|
7
|
+
};
|
|
8
|
+
export type LabelValidationCallback = (validity: ValidityState, validationMessage: string) => LabelValidationResult | undefined;
|
|
9
|
+
export type LabelProps = HTMLLabelAttributes & {
|
|
10
|
+
formValidation?: boolean | null;
|
|
11
|
+
forwardClick?: boolean | null;
|
|
12
|
+
message?: Snippet | string;
|
|
13
|
+
onValidation?: LabelValidationCallback;
|
|
14
|
+
required?: boolean | null;
|
|
15
|
+
requiredIndicator?: Snippet | string;
|
|
16
|
+
requiredReason?: Snippet | string;
|
|
17
|
+
text?: Snippet | string;
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/Link.svelte
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
<svelte:options runes={true} />
|
|
2
2
|
|
|
3
3
|
<script lang="ts">
|
|
4
|
-
import type {
|
|
4
|
+
import type { LinkProps } from './Link.types';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
disabled?: boolean | null;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
let { children, class: _class, disabled, ...rest }: Props = $props();
|
|
6
|
+
let { children, class: _class, disabled, ...rest }: LinkProps = $props();
|
|
11
7
|
|
|
12
8
|
let linkRef: HTMLAnchorElement;
|
|
13
9
|
|
package/dist/Link.svelte.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
disabled?: boolean | null;
|
|
4
|
-
};
|
|
5
|
-
declare const Link: import("svelte").Component<Props, {
|
|
1
|
+
import type { LinkProps } from './Link.types';
|
|
2
|
+
declare const Link: import("svelte").Component<LinkProps, {
|
|
6
3
|
blur: () => void;
|
|
7
4
|
click: () => void;
|
|
8
5
|
focus: (options?: FocusOptions) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/List.svelte
CHANGED
|
@@ -2,18 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
<script lang="ts">
|
|
4
4
|
import { setContext } from 'svelte';
|
|
5
|
-
import type {
|
|
5
|
+
import type { KeyboardEventHandler, MouseEventHandler } from 'svelte/elements';
|
|
6
6
|
import { LIST_CONTEXT_KEY } from './List.constants';
|
|
7
|
-
import type { ListContext } from './List.types';
|
|
7
|
+
import type { ListContext, ListProps } from './List.types';
|
|
8
8
|
import { usingKeyboard } from './mediaQueries/usingKeyboard';
|
|
9
9
|
|
|
10
|
-
type Props = HTMLAttributes<HTMLDivElement> & {
|
|
11
|
-
disabled?: boolean | null;
|
|
12
|
-
horizontal?: boolean | null;
|
|
13
|
-
selectedValue?: string;
|
|
14
|
-
onSelect?: (value?: string) => void;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
10
|
let {
|
|
18
11
|
children,
|
|
19
12
|
class: _class,
|
|
@@ -22,7 +15,7 @@
|
|
|
22
15
|
selectedValue = $bindable(),
|
|
23
16
|
onSelect,
|
|
24
17
|
...rest
|
|
25
|
-
}:
|
|
18
|
+
}: ListProps = $props();
|
|
26
19
|
|
|
27
20
|
let listRef: HTMLDivElement;
|
|
28
21
|
let lastSelectedItemRef: HTMLElement;
|
package/dist/List.svelte.d.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
disabled?: boolean | null;
|
|
4
|
-
horizontal?: boolean | null;
|
|
5
|
-
selectedValue?: string;
|
|
6
|
-
onSelect?: (value?: string) => void;
|
|
7
|
-
};
|
|
8
|
-
declare const List: import("svelte").Component<Props, {
|
|
1
|
+
import type { ListProps } from './List.types';
|
|
2
|
+
declare const List: import("svelte").Component<ListProps, {
|
|
9
3
|
blur: () => void;
|
|
10
4
|
click: () => void;
|
|
11
5
|
focus: (options?: FocusOptions) => void;
|
package/dist/List.types.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
1
2
|
export type ListContext = {
|
|
2
3
|
disabled?: boolean | null | undefined;
|
|
3
4
|
selectedValue?: string;
|
|
4
5
|
horizontal?: boolean | null | undefined;
|
|
5
6
|
};
|
|
7
|
+
export type ListProps = HTMLAttributes<HTMLDivElement> & {
|
|
8
|
+
disabled?: boolean | null;
|
|
9
|
+
horizontal?: boolean | null;
|
|
10
|
+
selectedValue?: string;
|
|
11
|
+
onSelect?: (value?: string) => void;
|
|
12
|
+
};
|
package/dist/ListItem.svelte
CHANGED
|
@@ -2,16 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
<script lang="ts">
|
|
4
4
|
import { getContext } from 'svelte';
|
|
5
|
-
import type { HTMLAttributes } from 'svelte/elements';
|
|
6
5
|
import { LIST_CONTEXT_KEY } from './List.constants';
|
|
7
6
|
import type { ListContext } from './List.types';
|
|
7
|
+
import type { ListItemProps } from './ListItem.types';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
disabled?: boolean | null;
|
|
11
|
-
value?: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
let { children, class: _class, disabled, value, ...rest }: Props = $props();
|
|
9
|
+
let { children, class: _class, disabled, value, ...rest }: ListItemProps = $props();
|
|
15
10
|
|
|
16
11
|
const listContext = getContext<ListContext>(LIST_CONTEXT_KEY);
|
|
17
12
|
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
disabled?: boolean | null;
|
|
4
|
-
value?: string;
|
|
5
|
-
};
|
|
6
|
-
declare const ListItem: import("svelte").Component<Props, {
|
|
1
|
+
import type { ListItemProps } from './ListItem.types';
|
|
2
|
+
declare const ListItem: import("svelte").Component<ListItemProps, {
|
|
7
3
|
click: () => void;
|
|
8
4
|
blur: () => void;
|
|
9
5
|
focus: (options?: FocusOptions) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/Menu.svelte
CHANGED
|
@@ -2,16 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
<script lang="ts">
|
|
4
4
|
import { getContext } from 'svelte';
|
|
5
|
-
import type { HTMLAttributes } from 'svelte/elements';
|
|
6
5
|
import { slide, type SlideParams, type TransitionConfig } from 'svelte/transition';
|
|
7
6
|
import { MENU_ITEM_CONTEXT_KEY } from './MenuItem.constants';
|
|
8
7
|
import type { MenuItemContext } from './MenuItem.types';
|
|
9
8
|
import { isElementEnabledMenuItem, isElementMenuItem } from './MenuItem.utils';
|
|
10
9
|
import { prefersReducedMotion } from './mediaQueries/prefersReducedMotion';
|
|
10
|
+
import type { MenuProps } from './Menu.types';
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let { children, class: _class, ...rest }: Props = $props();
|
|
12
|
+
let { children, class: _class, ...rest }: MenuProps = $props();
|
|
15
13
|
|
|
16
14
|
let menuRef: HTMLDivElement;
|
|
17
15
|
let menuItemsRef: HTMLDivElement;
|
package/dist/Menu.svelte.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
declare const Menu: import("svelte").Component<Props, {
|
|
1
|
+
import type { MenuProps } from './Menu.types';
|
|
2
|
+
declare const Menu: import("svelte").Component<MenuProps, {
|
|
4
3
|
focus: (options?: FocusOptions) => void;
|
|
5
4
|
blur: () => void;
|
|
6
5
|
focusFirstMenuItem: () => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/MenuBar.svelte
CHANGED
|
@@ -2,23 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
<script lang="ts">
|
|
4
4
|
import { setContext } from 'svelte';
|
|
5
|
-
import type { HTMLAttributes } from 'svelte/elements';
|
|
6
5
|
import { clickOutside } from './actions/clickOutside';
|
|
7
6
|
import { MENU_BAR_CONTEXT_KEY } from './MenuBar.constants';
|
|
8
|
-
import type { MenuBarContext } from './MenuBar.types';
|
|
7
|
+
import type { MenuBarContext, MenuBarProps } from './MenuBar.types';
|
|
9
8
|
import { MENU_ITEM_CONTEXT_KEY } from './MenuItem.constants';
|
|
10
9
|
import type { MenuItemContext } from './MenuItem.types';
|
|
11
10
|
import { isElementEnabledMenuItem } from './MenuItem.utils';
|
|
12
11
|
|
|
13
12
|
const uuid = $props.id();
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
onClose?: (value: string) => void;
|
|
17
|
-
onOpen?: (value: string) => void;
|
|
18
|
-
onSelect?: (value: string) => void;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
let { class: _class, children, onClose, onOpen, onSelect, ...rest }: Props = $props();
|
|
14
|
+
let { class: _class, children, onClose, onOpen, onSelect, ...rest }: MenuBarProps = $props();
|
|
22
15
|
|
|
23
16
|
const rootValue = `MenuBar-${uuid}`;
|
|
24
17
|
let openValues: string[] = $state([]);
|
package/dist/MenuBar.svelte.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
onClose?: (value: string) => void;
|
|
4
|
-
onOpen?: (value: string) => void;
|
|
5
|
-
onSelect?: (value: string) => void;
|
|
6
|
-
};
|
|
7
|
-
declare const MenuBar: import("svelte").Component<Props, {
|
|
1
|
+
import type { MenuBarProps } from './MenuBar.types';
|
|
2
|
+
declare const MenuBar: import("svelte").Component<MenuBarProps, {
|
|
8
3
|
blur: () => void;
|
|
9
4
|
focus: (options?: FocusOptions) => void;
|
|
10
5
|
}, "">;
|
package/dist/MenuBar.types.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
1
2
|
export type MenuBarContext = {
|
|
2
3
|
openPreviousMenuBarItem?: () => void;
|
|
3
4
|
openNextMenuBarItem?: () => void;
|
|
4
5
|
};
|
|
6
|
+
export type MenuBarProps = HTMLAttributes<HTMLDivElement> & {
|
|
7
|
+
onClose?: (value: string) => void;
|
|
8
|
+
onOpen?: (value: string) => void;
|
|
9
|
+
onSelect?: (value: string) => void;
|
|
10
|
+
};
|
package/dist/MenuButton.svelte
CHANGED
|
@@ -10,20 +10,10 @@
|
|
|
10
10
|
import type { MenuItemContext } from './MenuItem.types';
|
|
11
11
|
import Popover from './Popover.svelte';
|
|
12
12
|
import type { PopoverPlacement } from './Popover.types';
|
|
13
|
+
import type { MenuButtonProps } from './MenuButton.types';
|
|
13
14
|
|
|
14
15
|
const uuid = $props.id();
|
|
15
16
|
|
|
16
|
-
type Props = HTMLButtonAttributes & {
|
|
17
|
-
items: Snippet;
|
|
18
|
-
menuClass?: string;
|
|
19
|
-
onOpen?: (value: string) => void;
|
|
20
|
-
onClose?: (value: string) => void;
|
|
21
|
-
onSelect?: (value: string) => void;
|
|
22
|
-
open?: boolean | null | undefined;
|
|
23
|
-
popoverPlacement?: PopoverPlacement;
|
|
24
|
-
value?: string;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
17
|
let {
|
|
28
18
|
children,
|
|
29
19
|
class: _class,
|
|
@@ -36,7 +26,7 @@
|
|
|
36
26
|
popoverPlacement = 'bottom-start',
|
|
37
27
|
value,
|
|
38
28
|
...rest
|
|
39
|
-
}:
|
|
29
|
+
}: MenuButtonProps = $props();
|
|
40
30
|
|
|
41
31
|
const instanceId = `MenuButton-${uuid}`;
|
|
42
32
|
|
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import type { PopoverPlacement } from './Popover.types';
|
|
4
|
-
type Props = HTMLButtonAttributes & {
|
|
5
|
-
items: Snippet;
|
|
6
|
-
menuClass?: string;
|
|
7
|
-
onOpen?: (value: string) => void;
|
|
8
|
-
onClose?: (value: string) => void;
|
|
9
|
-
onSelect?: (value: string) => void;
|
|
10
|
-
open?: boolean | null | undefined;
|
|
11
|
-
popoverPlacement?: PopoverPlacement;
|
|
12
|
-
value?: string;
|
|
13
|
-
};
|
|
14
|
-
declare const MenuButton: import("svelte").Component<Props, {
|
|
1
|
+
import type { MenuButtonProps } from './MenuButton.types';
|
|
2
|
+
declare const MenuButton: import("svelte").Component<MenuButtonProps, {
|
|
15
3
|
click: () => void;
|
|
16
4
|
blur: () => void;
|
|
17
5
|
focus: (options?: FocusOptions) => void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PopoverPlacement } from './Popover.types';
|
|
2
|
+
import type { ButtonProps } from './Button.types';
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
4
|
+
export type MenuButtonProps = ButtonProps & {
|
|
5
|
+
items: Snippet;
|
|
6
|
+
menuClass?: string;
|
|
7
|
+
onOpen?: (value: string) => void;
|
|
8
|
+
onClose?: (value: string) => void;
|
|
9
|
+
onSelect?: (value: string) => void;
|
|
10
|
+
open?: boolean | null | undefined;
|
|
11
|
+
popoverPlacement?: PopoverPlacement;
|
|
12
|
+
value?: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/MenuItem.svelte
CHANGED
|
@@ -1,36 +1,19 @@
|
|
|
1
1
|
<svelte:options runes={true} />
|
|
2
2
|
|
|
3
3
|
<script lang="ts">
|
|
4
|
-
import { getContext, setContext, tick
|
|
5
|
-
import type {
|
|
6
|
-
HTMLButtonAttributes,
|
|
7
|
-
KeyboardEventHandler,
|
|
8
|
-
MouseEventHandler
|
|
9
|
-
} from 'svelte/elements';
|
|
4
|
+
import { getContext, setContext, tick } from 'svelte';
|
|
5
|
+
import type { KeyboardEventHandler, MouseEventHandler } from 'svelte/elements';
|
|
10
6
|
import Menu from './Menu.svelte';
|
|
11
7
|
import { MENU_BAR_CONTEXT_KEY } from './MenuBar.constants';
|
|
12
8
|
import type { MenuBarContext } from './MenuBar.types';
|
|
13
9
|
import { MENU_ITEM_CONTEXT_KEY } from './MenuItem.constants';
|
|
14
|
-
import type { MenuItemContext,
|
|
10
|
+
import type { MenuItemContext, MenuItemProps } from './MenuItem.types';
|
|
15
11
|
import { isElementEnabledMenuItem } from './MenuItem.utils';
|
|
16
12
|
import Popover from './Popover.svelte';
|
|
17
13
|
import { usingKeyboard } from './mediaQueries/usingKeyboard';
|
|
18
14
|
|
|
19
15
|
const uuid = $props.id();
|
|
20
16
|
|
|
21
|
-
type Props = HTMLButtonAttributes & {
|
|
22
|
-
checked?: boolean | null;
|
|
23
|
-
item?: Snippet;
|
|
24
|
-
menuClass?: string;
|
|
25
|
-
onClose?: (value: string) => void;
|
|
26
|
-
onOpen?: (value: string) => void;
|
|
27
|
-
onSelect?: (value: string) => void;
|
|
28
|
-
role?: MenuItemRole;
|
|
29
|
-
shortcut?: string | Snippet;
|
|
30
|
-
text?: string | Snippet;
|
|
31
|
-
value: string;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
17
|
let {
|
|
35
18
|
checked,
|
|
36
19
|
children,
|
|
@@ -46,7 +29,7 @@
|
|
|
46
29
|
shortcut,
|
|
47
30
|
value,
|
|
48
31
|
...rest
|
|
49
|
-
}:
|
|
32
|
+
}: MenuItemProps = $props();
|
|
50
33
|
|
|
51
34
|
const menuItemContext = getContext<MenuItemContext>(MENU_ITEM_CONTEXT_KEY) || {};
|
|
52
35
|
|
|
@@ -1,19 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import type { MenuItemRole } from './MenuItem.types';
|
|
4
|
-
type Props = HTMLButtonAttributes & {
|
|
5
|
-
checked?: boolean | null;
|
|
6
|
-
item?: Snippet;
|
|
7
|
-
menuClass?: string;
|
|
8
|
-
onClose?: (value: string) => void;
|
|
9
|
-
onOpen?: (value: string) => void;
|
|
10
|
-
onSelect?: (value: string) => void;
|
|
11
|
-
role?: MenuItemRole;
|
|
12
|
-
shortcut?: string | Snippet;
|
|
13
|
-
text?: string | Snippet;
|
|
14
|
-
value: string;
|
|
15
|
-
};
|
|
16
|
-
declare const MenuItem: import("svelte").Component<Props, {
|
|
1
|
+
import type { MenuItemProps } from './MenuItem.types';
|
|
2
|
+
declare const MenuItem: import("svelte").Component<MenuItemProps, {
|
|
17
3
|
blur: () => void;
|
|
18
4
|
click: () => void;
|
|
19
5
|
focus: (options?: FocusOptions) => void;
|
package/dist/MenuItem.types.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLButtonAttributes } from 'svelte/elements';
|
|
1
3
|
import type { MENU_ITEM_ROLES } from './MenuItem.constants';
|
|
2
4
|
type MenuItemRoleTuple = typeof MENU_ITEM_ROLES;
|
|
3
5
|
export type MenuItemRole = MenuItemRoleTuple[number];
|
|
@@ -17,4 +19,16 @@ export type MenuItemContext = {
|
|
|
17
19
|
onClose?: (value: string) => void;
|
|
18
20
|
onSelect?: (value: string) => void;
|
|
19
21
|
};
|
|
22
|
+
export type MenuItemProps = HTMLButtonAttributes & {
|
|
23
|
+
checked?: boolean | null;
|
|
24
|
+
item?: Snippet;
|
|
25
|
+
menuClass?: string;
|
|
26
|
+
onClose?: (value: string) => void;
|
|
27
|
+
onOpen?: (value: string) => void;
|
|
28
|
+
onSelect?: (value: string) => void;
|
|
29
|
+
role?: MenuItemRole;
|
|
30
|
+
shortcut?: string | Snippet;
|
|
31
|
+
text?: string | Snippet;
|
|
32
|
+
value: string;
|
|
33
|
+
};
|
|
20
34
|
export {};
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
<svelte:options runes={true} />
|
|
2
2
|
|
|
3
3
|
<script lang="ts">
|
|
4
|
-
import type {
|
|
4
|
+
import type { MenuSeparatorProps } from './MenuSeparator.types';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
let { class: _class, ...rest }: Props = $props();
|
|
6
|
+
let { class: _class, ...rest }: MenuSeparatorProps = $props();
|
|
9
7
|
</script>
|
|
10
8
|
|
|
11
9
|
<div class={['sterling-menu-separator', _class]} role="separator" {...rest}></div>
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
declare const MenuSeparator: import("svelte").Component<Props, {}, "">;
|
|
1
|
+
import type { MenuSeparatorProps } from './MenuSeparator.types';
|
|
2
|
+
declare const MenuSeparator: import("svelte").Component<MenuSeparatorProps, {}, "">;
|
|
4
3
|
type MenuSeparator = ReturnType<typeof MenuSeparator>;
|
|
5
4
|
export default MenuSeparator;
|