@xds/svelte 1.0.0 → 1.1.0
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/Accordion.svelte +7 -2
- package/dist/Avatar.svelte +10 -2
- package/dist/AvatarStack.svelte +11 -1
- package/dist/Badge.svelte +14 -3
- package/dist/Banner.svelte +6 -1
- package/dist/Button.svelte +30 -2
- package/dist/Button.svelte.d.ts +10 -1
- package/dist/Card.svelte +16 -2
- package/dist/Checkbox.svelte +52 -8
- package/dist/Checkbox.svelte.d.ts +13 -3
- package/dist/Chip.svelte +3 -1
- package/dist/ChipBar.svelte +3 -2
- package/dist/CountBadge.svelte +4 -2
- package/dist/DatePicker.svelte +11 -1
- package/dist/DateRangePicker.svelte +6 -1
- package/dist/Dialog.svelte +9 -2
- package/dist/Divider.svelte +7 -3
- package/dist/EmptyState.svelte +15 -3
- package/dist/Icon.svelte +11 -2
- package/dist/IconButton.svelte +30 -2
- package/dist/IconButton.svelte.d.ts +10 -1
- package/dist/Labels.svelte +29 -0
- package/dist/Labels.svelte.d.ts +17 -0
- package/dist/MediaCard.svelte +4 -1
- package/dist/Menu.svelte +13 -1
- package/dist/PlaceRow.svelte +6 -1
- package/dist/ProgressBar.svelte +3 -1
- package/dist/RadioGroup.svelte +23 -8
- package/dist/RadioGroup.svelte.d.ts +4 -2
- package/dist/SearchField.svelte +65 -18
- package/dist/SearchField.svelte.d.ts +14 -4
- package/dist/SectionHeader.svelte +7 -2
- package/dist/SegmentedControl.svelte +21 -7
- package/dist/SegmentedControl.svelte.d.ts +3 -2
- package/dist/Select.svelte +25 -5
- package/dist/Select.svelte.d.ts +3 -2
- package/dist/Sidebar.svelte +3 -0
- package/dist/Skeleton.svelte +10 -2
- package/dist/Slider.svelte +23 -7
- package/dist/Slider.svelte.d.ts +2 -2
- package/dist/Spinner.svelte +3 -2
- package/dist/Switch.svelte +53 -9
- package/dist/Switch.svelte.d.ts +13 -3
- package/dist/Tabs.svelte +21 -6
- package/dist/Tabs.svelte.d.ts +2 -1
- package/dist/Text.svelte +3 -1
- package/dist/TextField.svelte +59 -14
- package/dist/TextField.svelte.d.ts +13 -3
- package/dist/Thumbnail.svelte +7 -1
- package/dist/Toast.svelte +12 -2
- package/dist/Tooltip.svelte +9 -2
- package/dist/TooltipOverlay.svelte +9 -2
- package/dist/controllable.svelte.d.ts +28 -0
- package/dist/controllable.svelte.js +41 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/labels.svelte.d.ts +13 -0
- package/dist/labels.svelte.js +24 -0
- package/dist/preview/Component.svelte +2 -0
- package/dist/preview/components.js +2 -1
- package/dist/root.d.ts +4 -2
- package/package.json +3 -3
package/dist/TextField.svelte
CHANGED
|
@@ -4,16 +4,22 @@
|
|
|
4
4
|
are tied to the input for assistive technology, and the error is announced when it appears.
|
|
5
5
|
|
|
6
6
|
An invalid field blocks its form from being submitted, so `error` has to be cleared as soon as
|
|
7
|
-
the person edits the value.
|
|
7
|
+
the person edits the value. Without `value` it keeps its own text, from `defaultValue`, and a
|
|
8
|
+
reset of its form puts that back.
|
|
9
|
+
|
|
10
|
+
`focus()`, `blur()` and `element()` on the instance reach the native input or text area.
|
|
8
11
|
-->
|
|
9
12
|
<script module lang="ts">
|
|
10
13
|
import type { TextFieldBaseProps } from "@xds/core";
|
|
11
14
|
import type { Snippet } from "svelte";
|
|
15
|
+
import type { FocusEventHandler } from "svelte/elements";
|
|
12
16
|
import type { RootProps } from "./root.js";
|
|
13
17
|
|
|
14
18
|
export type TextFieldProps = TextFieldBaseProps &
|
|
15
19
|
RootProps & {
|
|
16
|
-
onChange
|
|
20
|
+
onChange?: (value: string) => void;
|
|
21
|
+
onFocus?: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
22
|
+
onBlur?: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
17
23
|
/**
|
|
18
24
|
* Inside the box, in front of the text: an icon, a unit. It takes the placeholder's color
|
|
19
25
|
* unless it sets its own.
|
|
@@ -25,14 +31,17 @@
|
|
|
25
31
|
</script>
|
|
26
32
|
|
|
27
33
|
<script lang="ts">
|
|
28
|
-
import { classes } from "@xds/core";
|
|
34
|
+
import { classes, rootAttributes } from "@xds/core";
|
|
29
35
|
import { untrack } from "svelte";
|
|
30
36
|
import type { Attachment } from "svelte/attachments";
|
|
37
|
+
import { controllable, followFormReset } from "./controllable.svelte.js";
|
|
31
38
|
import { keepValue } from "./controlled.js";
|
|
32
39
|
|
|
40
|
+
// `value` stays in the rest, where whether it is given at all can be asked.
|
|
33
41
|
let {
|
|
34
42
|
label,
|
|
35
|
-
|
|
43
|
+
defaultValue = "",
|
|
44
|
+
readOnly,
|
|
36
45
|
description,
|
|
37
46
|
error,
|
|
38
47
|
placeholder,
|
|
@@ -47,12 +56,40 @@
|
|
|
47
56
|
required,
|
|
48
57
|
disabled,
|
|
49
58
|
onChange,
|
|
59
|
+
onFocus,
|
|
60
|
+
onBlur,
|
|
50
61
|
leading,
|
|
51
62
|
trailing,
|
|
52
63
|
class: className,
|
|
53
64
|
style,
|
|
65
|
+
...rest
|
|
54
66
|
}: TextFieldProps = $props();
|
|
55
67
|
|
|
68
|
+
const control = controllable(
|
|
69
|
+
() => rest,
|
|
70
|
+
"value",
|
|
71
|
+
() => rest.value ?? "",
|
|
72
|
+
() => defaultValue,
|
|
73
|
+
() => onChange,
|
|
74
|
+
);
|
|
75
|
+
let input = $state<HTMLInputElement | HTMLTextAreaElement>();
|
|
76
|
+
followFormReset(() => input, control);
|
|
77
|
+
|
|
78
|
+
/** Moves the focus to the native input or text area. */
|
|
79
|
+
export function focus(options?: FocusOptions) {
|
|
80
|
+
input?.focus(options);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Takes the focus from the native input or text area. */
|
|
84
|
+
export function blur() {
|
|
85
|
+
input?.blur();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The native input or text area, once it is on the page. */
|
|
89
|
+
export function element(): HTMLInputElement | HTMLTextAreaElement | undefined {
|
|
90
|
+
return input;
|
|
91
|
+
}
|
|
92
|
+
|
|
56
93
|
const id = $props.id();
|
|
57
94
|
const descriptionId = `${id}-description`;
|
|
58
95
|
const errorId = `${id}-error`;
|
|
@@ -73,17 +110,17 @@
|
|
|
73
110
|
};
|
|
74
111
|
|
|
75
112
|
function oninput(event: Event & { currentTarget: HTMLInputElement | HTMLTextAreaElement }) {
|
|
76
|
-
|
|
113
|
+
control.set(event.currentTarget.value);
|
|
77
114
|
// While a composition is open the text belongs to the input method; it ends with
|
|
78
115
|
// compositionend.
|
|
79
116
|
if (!(event instanceof InputEvent && event.isComposing))
|
|
80
|
-
keepValue(event.currentTarget, () =>
|
|
117
|
+
keepValue(event.currentTarget, () => control.current);
|
|
81
118
|
}
|
|
82
119
|
|
|
83
120
|
function oncompositionend(
|
|
84
121
|
event: CompositionEvent & { currentTarget: HTMLInputElement | HTMLTextAreaElement },
|
|
85
122
|
) {
|
|
86
|
-
keepValue(event.currentTarget, () =>
|
|
123
|
+
keepValue(event.currentTarget, () => control.current);
|
|
87
124
|
}
|
|
88
125
|
</script>
|
|
89
126
|
|
|
@@ -96,20 +133,24 @@
|
|
|
96
133
|
{rows}
|
|
97
134
|
{id}
|
|
98
135
|
class={box ? "xds-text-field__input xds-text-field__control" : "xds-text-field__input"}
|
|
99
|
-
{
|
|
100
|
-
|
|
136
|
+
bind:this={input}
|
|
137
|
+
value={control.current}
|
|
138
|
+
defaultValue={control.controlled ? control.current : defaultValue}
|
|
101
139
|
{placeholder}
|
|
102
140
|
{name}
|
|
103
141
|
maxlength={maxLength}
|
|
104
142
|
inputmode={inputMode}
|
|
105
143
|
autocomplete={autoComplete as HTMLTextAreaElement["autocomplete"]}
|
|
144
|
+
readonly={readOnly}
|
|
106
145
|
{required}
|
|
107
146
|
{disabled}
|
|
108
147
|
aria-invalid={invalid ? "true" : undefined}
|
|
109
148
|
aria-errormessage={invalid ? errorId : undefined}
|
|
110
149
|
aria-describedby={describedBy}
|
|
111
150
|
{oninput}
|
|
112
|
-
{oncompositionend}
|
|
151
|
+
{oncompositionend}
|
|
152
|
+
onfocus={onFocus}
|
|
153
|
+
onblur={onBlur}></textarea>
|
|
113
154
|
{:else}
|
|
114
155
|
<input
|
|
115
156
|
{@attach settle}
|
|
@@ -117,13 +158,15 @@
|
|
|
117
158
|
{type}
|
|
118
159
|
{id}
|
|
119
160
|
class={box ? "xds-text-field__input xds-text-field__control" : "xds-text-field__input"}
|
|
120
|
-
{
|
|
121
|
-
|
|
161
|
+
bind:this={input}
|
|
162
|
+
value={control.current}
|
|
163
|
+
defaultValue={control.controlled ? control.current : defaultValue}
|
|
122
164
|
{placeholder}
|
|
123
165
|
{name}
|
|
124
166
|
maxlength={maxLength}
|
|
125
167
|
inputmode={inputMode}
|
|
126
168
|
autocomplete={autoComplete as HTMLInputElement["autocomplete"]}
|
|
169
|
+
readonly={readOnly}
|
|
127
170
|
{required}
|
|
128
171
|
{disabled}
|
|
129
172
|
aria-invalid={invalid ? "true" : undefined}
|
|
@@ -131,11 +174,13 @@
|
|
|
131
174
|
aria-describedby={describedBy}
|
|
132
175
|
{oninput}
|
|
133
176
|
{oncompositionend}
|
|
177
|
+
onfocus={onFocus}
|
|
178
|
+
onblur={onBlur}
|
|
134
179
|
/>
|
|
135
180
|
{/if}
|
|
136
181
|
{/snippet}
|
|
137
182
|
|
|
138
|
-
<div class={classes("xds-text-field", className)} {style}>
|
|
183
|
+
<div {...rootAttributes(rest)} class={classes("xds-text-field", className)} {style}>
|
|
139
184
|
<label for={id} class="xds-text-field__label">{label}</label>
|
|
140
185
|
{#if leading || trailing}
|
|
141
186
|
<div class="xds-text-field__control xds-text-field__group">
|
|
@@ -162,7 +207,7 @@
|
|
|
162
207
|
<span id={errorId} class="xds-text-field__error" aria-live="polite">{error}</span>
|
|
163
208
|
{#if maxLength !== undefined}
|
|
164
209
|
<span class="ms-auto shrink-0 text-xds-footnote text-xds-text-secondary tabular-nums"
|
|
165
|
-
>{
|
|
210
|
+
>{control.current.length}/{maxLength}</span
|
|
166
211
|
>
|
|
167
212
|
{/if}
|
|
168
213
|
</div>
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { TextFieldBaseProps } from "@xds/core";
|
|
2
2
|
import type { Snippet } from "svelte";
|
|
3
|
+
import type { FocusEventHandler } from "svelte/elements";
|
|
3
4
|
import type { RootProps } from "./root.js";
|
|
4
5
|
export type TextFieldProps = TextFieldBaseProps & RootProps & {
|
|
5
|
-
onChange
|
|
6
|
+
onChange?: (value: string) => void;
|
|
7
|
+
onFocus?: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
8
|
+
onBlur?: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
6
9
|
/**
|
|
7
10
|
* Inside the box, in front of the text: an icon, a unit. It takes the placeholder's color
|
|
8
11
|
* unless it sets its own.
|
|
@@ -16,8 +19,15 @@ export type TextFieldProps = TextFieldBaseProps & RootProps & {
|
|
|
16
19
|
* are tied to the input for assistive technology, and the error is announced when it appears.
|
|
17
20
|
*
|
|
18
21
|
* An invalid field blocks its form from being submitted, so `error` has to be cleared as soon as
|
|
19
|
-
* the person edits the value.
|
|
22
|
+
* the person edits the value. Without `value` it keeps its own text, from `defaultValue`, and a
|
|
23
|
+
* reset of its form puts that back.
|
|
24
|
+
*
|
|
25
|
+
* `focus()`, `blur()` and `element()` on the instance reach the native input or text area.
|
|
20
26
|
*/
|
|
21
|
-
declare const TextField: import("svelte").Component<TextFieldProps, {
|
|
27
|
+
declare const TextField: import("svelte").Component<TextFieldProps, {
|
|
28
|
+
focus: (options?: FocusOptions) => void;
|
|
29
|
+
blur: () => void;
|
|
30
|
+
element: () => HTMLInputElement | HTMLTextAreaElement | undefined;
|
|
31
|
+
}, "">;
|
|
22
32
|
type TextField = ReturnType<typeof TextField>;
|
|
23
33
|
export default TextField;
|
package/dist/Thumbnail.svelte
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import {
|
|
17
17
|
classes,
|
|
18
18
|
pictureClass,
|
|
19
|
+
rootAttributes,
|
|
19
20
|
rootPart,
|
|
20
21
|
THUMBNAIL_PARTS,
|
|
21
22
|
thumbnailBadgeClass,
|
|
@@ -35,6 +36,7 @@
|
|
|
35
36
|
progress,
|
|
36
37
|
class: className,
|
|
37
38
|
style,
|
|
39
|
+
...rest
|
|
38
40
|
}: ThumbnailProps = $props();
|
|
39
41
|
|
|
40
42
|
const defaults = useDefaults("Thumbnail");
|
|
@@ -44,7 +46,11 @@
|
|
|
44
46
|
const watched = $derived(thumbnailWatched(progress));
|
|
45
47
|
</script>
|
|
46
48
|
|
|
47
|
-
<span
|
|
49
|
+
<span
|
|
50
|
+
{...rootAttributes(rest)}
|
|
51
|
+
class={classes(rootPart("Thumbnail"), thumbnailClass(ratio), className)}
|
|
52
|
+
{style}
|
|
53
|
+
>
|
|
48
54
|
<!-- The placeholder is the picture's stand-in for assistive technology too, so the description
|
|
49
55
|
is on the box that always shows, not on the picture that may not. -->
|
|
50
56
|
<span
|
package/dist/Toast.svelte
CHANGED
|
@@ -20,10 +20,19 @@
|
|
|
20
20
|
|
|
21
21
|
<script lang="ts">
|
|
22
22
|
import { motion } from "@xds/tokens";
|
|
23
|
-
import { classes, readCssMs, rootPart, TOAST_PARTS } from "@xds/core";
|
|
23
|
+
import { classes, readCssMs, rootAttributes, rootPart, TOAST_PARTS } from "@xds/core";
|
|
24
24
|
import type { Attachment } from "svelte/attachments";
|
|
25
25
|
|
|
26
|
-
let {
|
|
26
|
+
let {
|
|
27
|
+
open,
|
|
28
|
+
message,
|
|
29
|
+
action,
|
|
30
|
+
duration,
|
|
31
|
+
onClose,
|
|
32
|
+
class: className,
|
|
33
|
+
style,
|
|
34
|
+
...rest
|
|
35
|
+
}: ToastProps = $props();
|
|
27
36
|
|
|
28
37
|
let regionElement = $state<HTMLDivElement>();
|
|
29
38
|
// The toast the pointer is over and the one focus is in. A toast that closed under the pointer
|
|
@@ -60,6 +69,7 @@
|
|
|
60
69
|
<!-- Hover and focus only pause the timer; the action inside is a real button. -->
|
|
61
70
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
62
71
|
<div
|
|
72
|
+
{...rootAttributes(rest)}
|
|
63
73
|
onpointerenter={(event) => (hovered = event.currentTarget)}
|
|
64
74
|
onpointerleave={() => (hovered = undefined)}
|
|
65
75
|
onfocusin={(event) => (focused = event.currentTarget)}
|
package/dist/Tooltip.svelte
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
</script>
|
|
22
22
|
|
|
23
23
|
<script lang="ts">
|
|
24
|
+
import { rootAttributes } from "@xds/core";
|
|
24
25
|
import TooltipOverlay from "./TooltipOverlay.svelte";
|
|
25
26
|
|
|
26
27
|
let {
|
|
@@ -30,11 +31,17 @@
|
|
|
30
31
|
class: className,
|
|
31
32
|
style,
|
|
32
33
|
children,
|
|
34
|
+
...rest
|
|
33
35
|
}: TooltipProps = $props();
|
|
34
36
|
</script>
|
|
35
37
|
|
|
36
38
|
<!-- The overlay gives the root part, `xds-tooltip`, to every tooltip, a collapsed Sidebar's
|
|
37
39
|
too. -->
|
|
38
|
-
<TooltipOverlay
|
|
39
|
-
|
|
40
|
+
<TooltipOverlay
|
|
41
|
+
{...rootAttributes(rest)}
|
|
42
|
+
{label}
|
|
43
|
+
{shortcut}
|
|
44
|
+
placement={() => placement}
|
|
45
|
+
class={className}
|
|
46
|
+
{style}>{@render children()}</TooltipOverlay
|
|
40
47
|
>
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
-->
|
|
7
7
|
<script lang="ts">
|
|
8
8
|
import { motion, space } from "@xds/tokens";
|
|
9
|
-
import { classes, readCssMs, readCssPx } from "@xds/core";
|
|
9
|
+
import { classes, readCssMs, readCssPx, rootAttributes } from "@xds/core";
|
|
10
10
|
import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
|
|
11
11
|
import * as tooltip from "@zag-js/tooltip";
|
|
12
12
|
import type { Snippet } from "svelte";
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
class: className,
|
|
23
23
|
style,
|
|
24
24
|
children,
|
|
25
|
+
...rest
|
|
25
26
|
}: RootProps & {
|
|
26
27
|
label: string;
|
|
27
28
|
shortcut?: string | undefined;
|
|
@@ -32,6 +33,8 @@
|
|
|
32
33
|
const id = $props.id();
|
|
33
34
|
const service = useMachine(tooltip.machine, () => ({
|
|
34
35
|
id,
|
|
36
|
+
// The app's id names the tooltip, and the control's aria-describedby points there.
|
|
37
|
+
ids: rest.id === undefined ? undefined : { content: rest.id },
|
|
35
38
|
openDelay: readCssMs(
|
|
36
39
|
null,
|
|
37
40
|
"--xds-motion-duration-tooltip-delay",
|
|
@@ -59,7 +62,11 @@
|
|
|
59
62
|
<div {...api.getPositionerProps()} class="xds-tooltip__positioner">
|
|
60
63
|
<!-- Shown until its exit animation ends; Zag would hide it as it closes. -->
|
|
61
64
|
<div
|
|
62
|
-
{...mergeProps(api.getContentProps(), {
|
|
65
|
+
{...mergeProps(api.getContentProps(), {
|
|
66
|
+
...rootAttributes(rest),
|
|
67
|
+
class: classes("xds-tooltip", className),
|
|
68
|
+
style,
|
|
69
|
+
})}
|
|
63
70
|
bind:this={content}
|
|
64
71
|
hidden={false}
|
|
65
72
|
>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The state of a control that the app may keep or leave to it (see `controllable`). A change is
|
|
3
|
+
* an `S`, which may be narrower than the state: a group with nothing chosen is changed only to a
|
|
4
|
+
* choice.
|
|
5
|
+
*/
|
|
6
|
+
export type Controllable<T, S extends T = T> = {
|
|
7
|
+
/** Whether the app keeps the state: it gives the prop, even as `undefined`. */
|
|
8
|
+
readonly controlled: boolean;
|
|
9
|
+
/** The app's value while it keeps it, the control's own otherwise. */
|
|
10
|
+
readonly current: T;
|
|
11
|
+
/** Takes a change: the control keeps it unless the app does, and `onChange` hears it. */
|
|
12
|
+
set(next: S): void;
|
|
13
|
+
/** Puts the control's own state back to its default. */
|
|
14
|
+
reset(): void;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The state of a control that the app may keep or leave to it. It is the app's while `props`,
|
|
18
|
+
* the component's rest props, hold `name`, even as `undefined`, and the control's own otherwise,
|
|
19
|
+
* starting from `initial`. Either way a change goes to `onChange`. Call it while the component is
|
|
20
|
+
* set up.
|
|
21
|
+
*/
|
|
22
|
+
export declare function controllable<T, S extends T = T>(props: () => object, name: string, given: () => T, initial: () => T, onChange: () => ((value: S) => void) | undefined): Controllable<T, S>;
|
|
23
|
+
/**
|
|
24
|
+
* Sets a control that keeps its own state back to its default when its form is reset, as the
|
|
25
|
+
* form sets the native field back. A controlled one shows what its owner gives it, whatever the
|
|
26
|
+
* form does. Call it while the component is set up.
|
|
27
|
+
*/
|
|
28
|
+
export declare function followFormReset(element: () => Element | undefined, state: Pick<Controllable<unknown>, "controlled" | "reset">): void;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { isControlled, onFormReset } from "@xds/core";
|
|
2
|
+
/**
|
|
3
|
+
* The state of a control that the app may keep or leave to it. It is the app's while `props`,
|
|
4
|
+
* the component's rest props, hold `name`, even as `undefined`, and the control's own otherwise,
|
|
5
|
+
* starting from `initial`. Either way a change goes to `onChange`. Call it while the component is
|
|
6
|
+
* set up.
|
|
7
|
+
*/
|
|
8
|
+
export function controllable(props, name, given, initial, onChange) {
|
|
9
|
+
// Asked again on each read: Svelte's props answer `in` from what the owner passes now.
|
|
10
|
+
const controlled = $derived(isControlled(props(), name));
|
|
11
|
+
let own = $state.raw(initial());
|
|
12
|
+
const current = $derived(controlled ? given() : own);
|
|
13
|
+
return {
|
|
14
|
+
get controlled() {
|
|
15
|
+
return controlled;
|
|
16
|
+
},
|
|
17
|
+
get current() {
|
|
18
|
+
return current;
|
|
19
|
+
},
|
|
20
|
+
set(next) {
|
|
21
|
+
if (!controlled)
|
|
22
|
+
own = next;
|
|
23
|
+
onChange()?.(next);
|
|
24
|
+
},
|
|
25
|
+
reset() {
|
|
26
|
+
own = initial();
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Sets a control that keeps its own state back to its default when its form is reset, as the
|
|
32
|
+
* form sets the native field back. A controlled one shows what its owner gives it, whatever the
|
|
33
|
+
* form does. Call it while the component is set up.
|
|
34
|
+
*/
|
|
35
|
+
export function followFormReset(element, state) {
|
|
36
|
+
$effect(() => {
|
|
37
|
+
if (state.controlled)
|
|
38
|
+
return;
|
|
39
|
+
return onFormReset(element(), () => state.reset());
|
|
40
|
+
});
|
|
41
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export { default as Divider, type DividerProps } from "./Divider.svelte";
|
|
|
18
18
|
export { default as EmptyState, type EmptyStateProps } from "./EmptyState.svelte";
|
|
19
19
|
export { default as Icon, type IconProps } from "./Icon.svelte";
|
|
20
20
|
export { default as IconButton, type IconButtonProps } from "./IconButton.svelte";
|
|
21
|
+
export { type ComponentLabels, default as Labels, type LabelsProps } from "./Labels.svelte";
|
|
21
22
|
export { default as ListRow, type ListRowProps } from "./ListRow.svelte";
|
|
22
23
|
export { default as MediaCard, type MediaCardProps } from "./MediaCard.svelte";
|
|
23
24
|
export { default as Menu, type MenuItem, type MenuProps } from "./Menu.svelte";
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,7 @@ export { default as Divider } from "./Divider.svelte";
|
|
|
25
25
|
export { default as EmptyState } from "./EmptyState.svelte";
|
|
26
26
|
export { default as Icon } from "./Icon.svelte";
|
|
27
27
|
export { default as IconButton } from "./IconButton.svelte";
|
|
28
|
+
export { default as Labels } from "./Labels.svelte";
|
|
28
29
|
export { default as ListRow } from "./ListRow.svelte";
|
|
29
30
|
export { default as MediaCard } from "./MediaCard.svelte";
|
|
30
31
|
export { default as Menu } from "./Menu.svelte";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ComponentLabels } from "@xds/core";
|
|
2
|
+
type Labels = () => ComponentLabels;
|
|
3
|
+
/**
|
|
4
|
+
* For Labels: gives the components inside it the labels around it, with those of `own`
|
|
5
|
+
* replaced. Call it while the component is set up.
|
|
6
|
+
*/
|
|
7
|
+
export declare function provideLabels(own: () => Partial<ComponentLabels>): void;
|
|
8
|
+
/**
|
|
9
|
+
* For a component with labels of its own: the labels of the closest Labels, or the English ones.
|
|
10
|
+
* Call it while the component is set up; the result follows the providers' values.
|
|
11
|
+
*/
|
|
12
|
+
export declare function useLabels(): Labels;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// The labels that a Labels provider gives the components inside it, in the app's language. They
|
|
2
|
+
// reach a component through context, so that a provider far up the tree applies without each
|
|
3
|
+
// screen passing them along, and each provider merges its own over the ones around it.
|
|
4
|
+
import { DEFAULT_LABELS, mergeLabels } from "@xds/core";
|
|
5
|
+
import { createContext } from "svelte";
|
|
6
|
+
// Not exported from the package: apps give labels with the Labels component.
|
|
7
|
+
const [getLabels, setLabels, hasLabels] = createContext();
|
|
8
|
+
/**
|
|
9
|
+
* For Labels: gives the components inside it the labels around it, with those of `own`
|
|
10
|
+
* replaced. Call it while the component is set up.
|
|
11
|
+
*/
|
|
12
|
+
export function provideLabels(own) {
|
|
13
|
+
const outer = hasLabels() ? getLabels() : undefined;
|
|
14
|
+
const merged = $derived(mergeLabels(outer?.(), own()));
|
|
15
|
+
setLabels(() => merged);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* For a component with labels of its own: the labels of the closest Labels, or the English ones.
|
|
19
|
+
* Call it while the component is set up; the result follows the providers' values.
|
|
20
|
+
*/
|
|
21
|
+
export function useLabels() {
|
|
22
|
+
const labels = hasLabels() ? getLabels() : undefined;
|
|
23
|
+
return () => labels?.() ?? DEFAULT_LABELS;
|
|
24
|
+
}
|
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
const values: Record<string, unknown> = {};
|
|
30
30
|
const slots: (readonly [string, Slot<State>])[] = [];
|
|
31
31
|
const takesNode = nodeProps[name] ?? [];
|
|
32
|
+
// Only the keys the data has: a control tells whether it is controlled by whether `value`
|
|
33
|
+
// or `checked` is passed at all, so one the data leaves out is not passed as `undefined`.
|
|
32
34
|
for (const [key, value] of Object.entries(given)) {
|
|
33
35
|
// A snippet only for what the data gives: a prop left undefined stays unset.
|
|
34
36
|
if (takesNode.includes(key) && value !== undefined) slots.push([key, value as Slot<State>]);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Accordion, Avatar, AvatarStack, Badge, Banner, Button, Card, Checkbox, Chip, ChipBar, CountBadge, DatePicker, DateRangePicker, Defaults, Dialog, Divider, EmptyState, Icon, IconButton, ListRow, MediaCard, Menu, ProgressBar, RadioGroup, SearchField, SectionHeader, SegmentedControl, Select, Sidebar, Skeleton, Slider, Spinner, Switch, Tabs, Text, TextField, Thumbnail, Toast, Tooltip, } from "../index.js";
|
|
1
|
+
import { Accordion, Avatar, AvatarStack, Badge, Banner, Button, Card, Checkbox, Chip, ChipBar, CountBadge, DatePicker, DateRangePicker, Defaults, Labels, Dialog, Divider, EmptyState, Icon, IconButton, ListRow, MediaCard, Menu, ProgressBar, RadioGroup, SearchField, SectionHeader, SegmentedControl, Select, Sidebar, Skeleton, Slider, Spinner, Switch, Tabs, Text, TextField, Thumbnail, Toast, Tooltip, } from "../index.js";
|
|
2
2
|
/**
|
|
3
3
|
* Every component the data can name, each taking the props the data gives it, with a snippet
|
|
4
4
|
* for each node. They are imported by name: a namespace import of the entry would put every
|
|
@@ -19,6 +19,7 @@ const components = {
|
|
|
19
19
|
DatePicker,
|
|
20
20
|
DateRangePicker,
|
|
21
21
|
Defaults,
|
|
22
|
+
Labels,
|
|
22
23
|
Dialog,
|
|
23
24
|
Divider,
|
|
24
25
|
EmptyState,
|
package/dist/root.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import type { RootAttributes } from "@xds/core";
|
|
1
2
|
/**
|
|
2
3
|
* Layer 7 of the library's customization: what an app adds to a component's root element, the
|
|
3
4
|
* one with its root part (`xds-<name>`). For an overlay that is its surface: the menu, the
|
|
4
|
-
* tooltip, the dialog or the toast, while it is open.
|
|
5
|
+
* tooltip, the dialog or the toast, while it is open. An `id` and `data-*` attributes, such as a
|
|
6
|
+
* test's `data-testid`, go on it too.
|
|
5
7
|
*/
|
|
6
|
-
export type RootProps = {
|
|
8
|
+
export type RootProps = RootAttributes & {
|
|
7
9
|
/** Classes added to the root element's own. */
|
|
8
10
|
class?: string;
|
|
9
11
|
/** Inline style for the root element. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xds/svelte",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "The xds design system's components for Svelte.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"design-system",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"page.css"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@xds/tokens": "1.
|
|
47
|
-
"@xds/core": "1.
|
|
46
|
+
"@xds/tokens": "1.1.0",
|
|
47
|
+
"@xds/core": "1.1.0",
|
|
48
48
|
"@internationalized/date": "3.12.4",
|
|
49
49
|
"@zag-js/accordion": "2.0.0-next.4",
|
|
50
50
|
"@zag-js/aria-hidden": "2.0.0-next.4",
|