@xds/svelte 1.0.1 → 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
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
A choice between a few views or modes, all visible at once. The selected segment is outlined as
|
|
4
4
|
well as filled, so the choice does not depend on telling two greys apart.
|
|
5
5
|
|
|
6
|
-
It is a group of native radio buttons, so the arrow keys move between segments.
|
|
6
|
+
It is a group of native radio buttons, so the arrow keys move between segments. Without
|
|
7
|
+
`value` it keeps its own choice, from `defaultValue` or else the first segment.
|
|
7
8
|
-->
|
|
8
9
|
<script module lang="ts">
|
|
9
10
|
import type { SegmentedControlBaseProps } from "@xds/core";
|
|
@@ -11,35 +12,48 @@
|
|
|
11
12
|
|
|
12
13
|
export type SegmentedControlProps<Value extends string> = SegmentedControlBaseProps<Value> &
|
|
13
14
|
RootProps & {
|
|
14
|
-
onChange
|
|
15
|
+
onChange?: (value: Value) => void;
|
|
15
16
|
};
|
|
16
17
|
</script>
|
|
17
18
|
|
|
18
19
|
<script lang="ts" generics="Value extends string">
|
|
19
20
|
import {
|
|
20
21
|
classes,
|
|
22
|
+
rootAttributes,
|
|
21
23
|
rootPart,
|
|
22
24
|
segmentedControlClass,
|
|
23
25
|
segmentedControlOptionClass,
|
|
24
26
|
segmentedControlSegmentClass,
|
|
25
27
|
} from "@xds/core";
|
|
28
|
+
import { controllable } from "./controllable.svelte.js";
|
|
26
29
|
import { keepChecked } from "./controlled.js";
|
|
27
30
|
|
|
31
|
+
// `value` stays in the rest, where whether it is given at all can be asked.
|
|
28
32
|
let {
|
|
29
33
|
options,
|
|
30
|
-
|
|
34
|
+
defaultValue,
|
|
31
35
|
"aria-label": ariaLabel,
|
|
32
36
|
fullWidth,
|
|
33
37
|
onChange,
|
|
34
38
|
class: className,
|
|
35
39
|
style,
|
|
40
|
+
...rest
|
|
36
41
|
}: SegmentedControlProps<Value> = $props();
|
|
37
42
|
|
|
43
|
+
const control = controllable<Value | undefined, Value>(
|
|
44
|
+
() => rest,
|
|
45
|
+
"value",
|
|
46
|
+
() => rest.value,
|
|
47
|
+
() => defaultValue ?? options[0]?.value,
|
|
48
|
+
() => onChange,
|
|
49
|
+
);
|
|
50
|
+
|
|
38
51
|
const name = $props.id();
|
|
39
52
|
let group = $state<HTMLDivElement>();
|
|
40
53
|
</script>
|
|
41
54
|
|
|
42
55
|
<div
|
|
56
|
+
{...rootAttributes(rest)}
|
|
43
57
|
bind:this={group}
|
|
44
58
|
aria-label={ariaLabel}
|
|
45
59
|
role="radiogroup"
|
|
@@ -53,14 +67,14 @@
|
|
|
53
67
|
{name}
|
|
54
68
|
value={option.value}
|
|
55
69
|
class="peer sr-only"
|
|
56
|
-
checked={option.value ===
|
|
57
|
-
defaultChecked={option.value ===
|
|
70
|
+
checked={option.value === control.current}
|
|
71
|
+
defaultChecked={option.value === control.current}
|
|
58
72
|
onchange={() => {
|
|
59
|
-
|
|
73
|
+
control.set(option.value);
|
|
60
74
|
// The browser moved the dot already; where the owner kept the old value, it goes
|
|
61
75
|
// back, on every radio of the group.
|
|
62
76
|
for (const input of group?.querySelectorAll("input") ?? []) {
|
|
63
|
-
keepChecked(input, () => input.value ===
|
|
77
|
+
keepChecked(input, () => input.value === control.current);
|
|
64
78
|
}
|
|
65
79
|
}}
|
|
66
80
|
/>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SegmentedControlBaseProps } from "@xds/core";
|
|
2
2
|
import type { RootProps } from "./root.js";
|
|
3
3
|
export type SegmentedControlProps<Value extends string> = SegmentedControlBaseProps<Value> & RootProps & {
|
|
4
|
-
onChange
|
|
4
|
+
onChange?: (value: Value) => void;
|
|
5
5
|
};
|
|
6
6
|
declare function $$render<Value extends string>(): {
|
|
7
7
|
props: SegmentedControlProps<Value>;
|
|
@@ -28,7 +28,8 @@ interface $$IsomorphicComponent {
|
|
|
28
28
|
* A choice between a few views or modes, all visible at once. The selected segment is outlined as
|
|
29
29
|
* well as filled, so the choice does not depend on telling two greys apart.
|
|
30
30
|
*
|
|
31
|
-
* It is a group of native radio buttons, so the arrow keys move between segments.
|
|
31
|
+
* It is a group of native radio buttons, so the arrow keys move between segments. Without
|
|
32
|
+
* `value` it keeps its own choice, from `defaultValue` or else the first segment.
|
|
32
33
|
*/
|
|
33
34
|
declare const SegmentedControl: $$IsomorphicComponent;
|
|
34
35
|
type SegmentedControl<Value extends string> = InstanceType<typeof SegmentedControl<Value>>;
|
package/dist/Select.svelte
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
The field is a button that says it opens a list box and whether the list is open. In the list
|
|
9
9
|
the arrow keys move, typing jumps to an option, and Enter chooses. The chosen option is
|
|
10
|
-
selected for assistive technology and marked with a check.
|
|
10
|
+
selected for assistive technology and marked with a check. Without `value` it keeps its own
|
|
11
|
+
choice, from `defaultValue`.
|
|
11
12
|
-->
|
|
12
13
|
<script module lang="ts">
|
|
13
14
|
import type { SelectBaseProps } from "@xds/core";
|
|
@@ -17,7 +18,7 @@
|
|
|
17
18
|
|
|
18
19
|
export type SelectProps<Value extends string = string> = SelectBaseProps<Value> &
|
|
19
20
|
RootProps & {
|
|
20
|
-
onChange
|
|
21
|
+
onChange?: (value: Value) => void;
|
|
21
22
|
};
|
|
22
23
|
</script>
|
|
23
24
|
|
|
@@ -27,6 +28,7 @@
|
|
|
27
28
|
classes,
|
|
28
29
|
keepListKeys,
|
|
29
30
|
readCssPx,
|
|
31
|
+
rootAttributes,
|
|
30
32
|
type SelectOption,
|
|
31
33
|
selectOptionIds,
|
|
32
34
|
underlayLayerStyle,
|
|
@@ -34,6 +36,7 @@
|
|
|
34
36
|
import * as select from "@zag-js/select";
|
|
35
37
|
import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
|
|
36
38
|
import type { HTMLAttributes, HTMLLabelAttributes } from "svelte/elements";
|
|
39
|
+
import { controllable } from "./controllable.svelte.js";
|
|
37
40
|
import Icon from "./Icon.svelte";
|
|
38
41
|
import { modalPopover } from "./modal-popover.svelte.js";
|
|
39
42
|
import Portal from "./Portal.svelte";
|
|
@@ -41,10 +44,11 @@
|
|
|
41
44
|
|
|
42
45
|
type KeyHandler = (event: KeyboardEvent) => void;
|
|
43
46
|
|
|
47
|
+
// `value` stays in the rest, where whether it is given at all can be asked.
|
|
44
48
|
let {
|
|
45
49
|
label,
|
|
46
50
|
options,
|
|
47
|
-
|
|
51
|
+
defaultValue,
|
|
48
52
|
placeholder,
|
|
49
53
|
description,
|
|
50
54
|
error,
|
|
@@ -53,8 +57,18 @@
|
|
|
53
57
|
onChange,
|
|
54
58
|
class: className,
|
|
55
59
|
style,
|
|
60
|
+
...rest
|
|
56
61
|
}: SelectProps<Value> = $props();
|
|
57
62
|
|
|
63
|
+
const control = controllable<Value | undefined, Value>(
|
|
64
|
+
() => rest,
|
|
65
|
+
"value",
|
|
66
|
+
() => rest.value,
|
|
67
|
+
() => defaultValue,
|
|
68
|
+
() => onChange,
|
|
69
|
+
);
|
|
70
|
+
const value = $derived(control.current);
|
|
71
|
+
|
|
58
72
|
const id = $props.id();
|
|
59
73
|
const valueId = `${id}-value`;
|
|
60
74
|
const descriptionId = `${id}-description`;
|
|
@@ -73,7 +87,7 @@
|
|
|
73
87
|
value: value === undefined ? [] : [value],
|
|
74
88
|
onValueChange: (details: select.ValueChangeDetails<SelectOption<Value>>) => {
|
|
75
89
|
const next = details.value[0];
|
|
76
|
-
if (next !== undefined)
|
|
90
|
+
if (next !== undefined) control.set(next as Value);
|
|
77
91
|
},
|
|
78
92
|
disabled,
|
|
79
93
|
invalid,
|
|
@@ -143,7 +157,13 @@
|
|
|
143
157
|
</script>
|
|
144
158
|
|
|
145
159
|
<!-- Merged, so that the app's style joins any the machine writes on the root. -->
|
|
146
|
-
<div
|
|
160
|
+
<div
|
|
161
|
+
{...mergeProps(api.getRootProps(), {
|
|
162
|
+
...rootAttributes(rest),
|
|
163
|
+
class: classes("xds-select", className),
|
|
164
|
+
style,
|
|
165
|
+
})}
|
|
166
|
+
>
|
|
147
167
|
<span {...labelProps} class="xds-select__label">{label}</span>
|
|
148
168
|
<button
|
|
149
169
|
{...triggerProps}
|
package/dist/Select.svelte.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { SelectBaseProps } from "@xds/core";
|
|
|
2
2
|
import type { RootProps } from "./root.js";
|
|
3
3
|
export type { SelectOption } from "@xds/core";
|
|
4
4
|
export type SelectProps<Value extends string = string> = SelectBaseProps<Value> & RootProps & {
|
|
5
|
-
onChange
|
|
5
|
+
onChange?: (value: Value) => void;
|
|
6
6
|
};
|
|
7
7
|
declare function $$render<Value extends string = string>(): {
|
|
8
8
|
props: SelectProps<Value>;
|
|
@@ -33,7 +33,8 @@ interface $$IsomorphicComponent {
|
|
|
33
33
|
*
|
|
34
34
|
* The field is a button that says it opens a list box and whether the list is open. In the list
|
|
35
35
|
* the arrow keys move, typing jumps to an option, and Enter chooses. The chosen option is
|
|
36
|
-
* selected for assistive technology and marked with a check.
|
|
36
|
+
* selected for assistive technology and marked with a check. Without `value` it keeps its own
|
|
37
|
+
* choice, from `defaultValue`.
|
|
37
38
|
*/
|
|
38
39
|
declare const Select: $$IsomorphicComponent;
|
|
39
40
|
type Select<Value extends string = string> = InstanceType<typeof Select<Value>>;
|
package/dist/Sidebar.svelte
CHANGED
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
<script lang="ts" generics="Value extends string = string">
|
|
28
28
|
import {
|
|
29
29
|
classes,
|
|
30
|
+
rootAttributes,
|
|
30
31
|
rootPart,
|
|
31
32
|
SIDEBAR_PARTS,
|
|
32
33
|
sidebarClass,
|
|
@@ -51,12 +52,14 @@
|
|
|
51
52
|
footer,
|
|
52
53
|
class: className,
|
|
53
54
|
style,
|
|
55
|
+
...rest
|
|
54
56
|
}: SidebarProps<Value> = $props();
|
|
55
57
|
|
|
56
58
|
const id = $props.id();
|
|
57
59
|
</script>
|
|
58
60
|
|
|
59
61
|
<nav
|
|
62
|
+
{...rootAttributes(rest)}
|
|
60
63
|
aria-label={label}
|
|
61
64
|
class={classes(rootPart("Sidebar"), sidebarClass(collapsed), className)}
|
|
62
65
|
{style}
|
package/dist/Skeleton.svelte
CHANGED
|
@@ -14,10 +14,17 @@
|
|
|
14
14
|
</script>
|
|
15
15
|
|
|
16
16
|
<script lang="ts">
|
|
17
|
-
import { classes, rootPart, skeletonClass, skeletonSize } from "@xds/core";
|
|
17
|
+
import { classes, rootAttributes, rootPart, skeletonClass, skeletonSize } from "@xds/core";
|
|
18
18
|
import { useDefaults } from "./defaults.svelte.js";
|
|
19
19
|
|
|
20
|
-
let {
|
|
20
|
+
let {
|
|
21
|
+
shape: ownShape,
|
|
22
|
+
width,
|
|
23
|
+
height,
|
|
24
|
+
class: className,
|
|
25
|
+
style,
|
|
26
|
+
...rest
|
|
27
|
+
}: SkeletonProps = $props();
|
|
21
28
|
|
|
22
29
|
const defaults = useDefaults("Skeleton");
|
|
23
30
|
const shape = $derived(ownShape ?? defaults().shape);
|
|
@@ -36,6 +43,7 @@
|
|
|
36
43
|
</script>
|
|
37
44
|
|
|
38
45
|
<span
|
|
46
|
+
{...rootAttributes(rest)}
|
|
39
47
|
aria-hidden="true"
|
|
40
48
|
class={classes(rootPart("Skeleton"), skeletonClass(shape), className)}
|
|
41
49
|
style={combinedStyle || undefined}
|
package/dist/Slider.svelte
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
The values snap to `step`.
|
|
5
5
|
|
|
6
6
|
It is a slider named by its label with its value, minimum and maximum, and each arrow key moves
|
|
7
|
-
it one step.
|
|
7
|
+
it one step. Without `value` it keeps its own, from `defaultValue` or else `min`.
|
|
8
8
|
-->
|
|
9
9
|
<script module lang="ts">
|
|
10
10
|
import type { SliderBaseProps } from "@xds/core";
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
export type SliderProps = SliderBaseProps &
|
|
14
14
|
RootProps & {
|
|
15
|
-
onChange
|
|
15
|
+
onChange?: (value: number) => void;
|
|
16
16
|
};
|
|
17
17
|
</script>
|
|
18
18
|
|
|
@@ -20,16 +20,19 @@
|
|
|
20
20
|
import {
|
|
21
21
|
classes,
|
|
22
22
|
focusThumbOnPress,
|
|
23
|
+
rootAttributes,
|
|
23
24
|
sliderArrowValue,
|
|
24
25
|
sliderPageSize,
|
|
25
26
|
sliderValueText,
|
|
26
27
|
} from "@xds/core";
|
|
27
28
|
import * as slider from "@zag-js/slider";
|
|
28
29
|
import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
|
|
30
|
+
import { controllable } from "./controllable.svelte.js";
|
|
29
31
|
|
|
32
|
+
// `value` stays in the rest, where whether it is given at all can be asked.
|
|
30
33
|
let {
|
|
31
34
|
label,
|
|
32
|
-
|
|
35
|
+
defaultValue,
|
|
33
36
|
min = 0,
|
|
34
37
|
max = 100,
|
|
35
38
|
step = 1,
|
|
@@ -40,16 +43,25 @@
|
|
|
40
43
|
onChange,
|
|
41
44
|
class: className,
|
|
42
45
|
style,
|
|
46
|
+
...rest
|
|
43
47
|
}: SliderProps = $props();
|
|
44
48
|
|
|
49
|
+
const position = controllable(
|
|
50
|
+
() => rest,
|
|
51
|
+
"value",
|
|
52
|
+
() => rest.value ?? min,
|
|
53
|
+
() => defaultValue ?? min,
|
|
54
|
+
() => onChange,
|
|
55
|
+
);
|
|
56
|
+
|
|
45
57
|
const id = $props.id();
|
|
46
58
|
const pageSize = $derived(sliderPageSize({ min, max, step }));
|
|
47
59
|
const service = useMachine(slider.machine, () => ({
|
|
48
60
|
id,
|
|
49
61
|
name,
|
|
50
|
-
value: [
|
|
62
|
+
value: [position.current],
|
|
51
63
|
// One thumb, so one number.
|
|
52
|
-
onValueChange: (details: slider.ValueChangeDetails) =>
|
|
64
|
+
onValueChange: (details: slider.ValueChangeDetails) => position.set(details.value[0] ?? min),
|
|
53
65
|
min,
|
|
54
66
|
max,
|
|
55
67
|
step,
|
|
@@ -94,7 +106,11 @@
|
|
|
94
106
|
that is for a set of fields, and this is one slider and its label. The app's style is merged
|
|
95
107
|
with the one the machine writes on the root. -->
|
|
96
108
|
<div
|
|
97
|
-
{...mergeProps(api.getRootProps(), {
|
|
109
|
+
{...mergeProps(api.getRootProps(), {
|
|
110
|
+
...rootAttributes(rest),
|
|
111
|
+
class: classes("xds-slider", className),
|
|
112
|
+
style,
|
|
113
|
+
})}
|
|
98
114
|
role="group"
|
|
99
115
|
aria-labelledby={api.getLabelProps().id}
|
|
100
116
|
>
|
|
@@ -103,7 +119,7 @@
|
|
|
103
119
|
{#if showValue}
|
|
104
120
|
<!-- Read when asked for, not at every step: the slider itself announces its value. -->
|
|
105
121
|
<output {...api.getValueTextProps()} aria-live="off" class="xds-slider__output"
|
|
106
|
-
>{sliderValueText(api.value[0] ??
|
|
122
|
+
>{sliderValueText(api.value[0] ?? position.current, locale)}</output
|
|
107
123
|
>
|
|
108
124
|
{/if}
|
|
109
125
|
<div {...control} class="xds-slider__control">
|
package/dist/Slider.svelte.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { SliderBaseProps } from "@xds/core";
|
|
2
2
|
import type { RootProps } from "./root.js";
|
|
3
3
|
export type SliderProps = SliderBaseProps & RootProps & {
|
|
4
|
-
onChange
|
|
4
|
+
onChange?: (value: number) => void;
|
|
5
5
|
};
|
|
6
6
|
/**
|
|
7
7
|
* Picks a number in a range by dragging the thumb, or by pressing the track where it should go.
|
|
8
8
|
* The values snap to `step`.
|
|
9
9
|
*
|
|
10
10
|
* It is a slider named by its label with its value, minimum and maximum, and each arrow key moves
|
|
11
|
-
* it one step.
|
|
11
|
+
* it one step. Without `value` it keeps its own, from `defaultValue` or else `min`.
|
|
12
12
|
*/
|
|
13
13
|
declare const Slider: import("svelte").Component<SliderProps, {}, "">;
|
|
14
14
|
type Slider = ReturnType<typeof Slider>;
|
package/dist/Spinner.svelte
CHANGED
|
@@ -12,16 +12,17 @@
|
|
|
12
12
|
</script>
|
|
13
13
|
|
|
14
14
|
<script lang="ts">
|
|
15
|
-
import { classes, rootPart, spinnerClass } from "@xds/core";
|
|
15
|
+
import { classes, rootAttributes, rootPart, spinnerClass } from "@xds/core";
|
|
16
16
|
import { useDefaults } from "./defaults.svelte.js";
|
|
17
17
|
|
|
18
|
-
let { size: ownSize, label, class: className, style }: SpinnerProps = $props();
|
|
18
|
+
let { size: ownSize, label, class: className, style, ...rest }: SpinnerProps = $props();
|
|
19
19
|
|
|
20
20
|
const defaults = useDefaults("Spinner");
|
|
21
21
|
const size = $derived(ownSize ?? defaults().size);
|
|
22
22
|
</script>
|
|
23
23
|
|
|
24
24
|
<span
|
|
25
|
+
{...rootAttributes(rest)}
|
|
25
26
|
class={classes(rootPart("Spinner"), "inline-flex shrink-0", className)}
|
|
26
27
|
{style}
|
|
27
28
|
role={label ? "status" : undefined}
|
package/dist/Switch.svelte
CHANGED
|
@@ -4,11 +4,15 @@
|
|
|
4
4
|
form, use a Checkbox.
|
|
5
5
|
|
|
6
6
|
It is a native checkbox with the switch role, so the keyboard, forms and screen readers treat
|
|
7
|
-
it as one. The input is hidden and the track is drawn beside it.
|
|
7
|
+
it as one. The input is hidden and the track is drawn beside it. Without `checked` it keeps its
|
|
8
|
+
own state, from `defaultChecked`, and a reset of its form puts that back.
|
|
9
|
+
|
|
10
|
+
`focus()`, `blur()` and `element()` on the instance reach the native checkbox.
|
|
8
11
|
-->
|
|
9
12
|
<script module lang="ts">
|
|
10
13
|
import {
|
|
11
14
|
classes,
|
|
15
|
+
rootAttributes,
|
|
12
16
|
rootPart,
|
|
13
17
|
type SwitchBaseProps,
|
|
14
18
|
switchClass,
|
|
@@ -16,42 +20,82 @@
|
|
|
16
20
|
switchThumbClass,
|
|
17
21
|
switchTrackClass,
|
|
18
22
|
} from "@xds/core";
|
|
23
|
+
import type { FocusEventHandler } from "svelte/elements";
|
|
19
24
|
import type { RootProps } from "./root.js";
|
|
20
25
|
|
|
21
26
|
export type SwitchProps = SwitchBaseProps &
|
|
22
27
|
RootProps & {
|
|
23
|
-
onChange
|
|
28
|
+
onChange?: (checked: boolean) => void;
|
|
29
|
+
onFocus?: FocusEventHandler<HTMLInputElement>;
|
|
30
|
+
onBlur?: FocusEventHandler<HTMLInputElement>;
|
|
24
31
|
};
|
|
25
32
|
</script>
|
|
26
33
|
|
|
27
34
|
<script lang="ts">
|
|
35
|
+
import { controllable, followFormReset } from "./controllable.svelte.js";
|
|
28
36
|
import { keepChecked } from "./controlled.js";
|
|
29
37
|
|
|
38
|
+
// `checked` stays in the rest, where whether it is given at all can be asked.
|
|
30
39
|
let {
|
|
31
|
-
|
|
40
|
+
defaultChecked = false,
|
|
32
41
|
label,
|
|
33
42
|
"aria-label": ariaLabel,
|
|
34
43
|
disabled,
|
|
35
44
|
onChange,
|
|
45
|
+
onFocus,
|
|
46
|
+
onBlur,
|
|
36
47
|
class: className,
|
|
37
48
|
style,
|
|
49
|
+
...rest
|
|
38
50
|
}: SwitchProps = $props();
|
|
51
|
+
|
|
52
|
+
const control = controllable(
|
|
53
|
+
() => rest,
|
|
54
|
+
"checked",
|
|
55
|
+
() => rest.checked ?? false,
|
|
56
|
+
() => defaultChecked,
|
|
57
|
+
() => onChange,
|
|
58
|
+
);
|
|
59
|
+
let input = $state<HTMLInputElement>();
|
|
60
|
+
followFormReset(() => input, control);
|
|
61
|
+
|
|
62
|
+
/** Moves the focus to the native checkbox. */
|
|
63
|
+
export function focus(options?: FocusOptions) {
|
|
64
|
+
input?.focus(options);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Takes the focus from the native checkbox. */
|
|
68
|
+
export function blur() {
|
|
69
|
+
input?.blur();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The native checkbox, once it is on the page. */
|
|
73
|
+
export function element(): HTMLInputElement | undefined {
|
|
74
|
+
return input;
|
|
75
|
+
}
|
|
39
76
|
</script>
|
|
40
77
|
|
|
41
|
-
<label
|
|
78
|
+
<label
|
|
79
|
+
{...rootAttributes(rest)}
|
|
80
|
+
class={classes(rootPart("Switch"), switchClass, className)}
|
|
81
|
+
{style}
|
|
82
|
+
>
|
|
42
83
|
<input
|
|
84
|
+
bind:this={input}
|
|
43
85
|
type="checkbox"
|
|
44
86
|
role="switch"
|
|
45
|
-
aria-checked={
|
|
87
|
+
aria-checked={control.current ? "true" : "false"}
|
|
46
88
|
aria-label={ariaLabel}
|
|
47
89
|
class="peer sr-only"
|
|
48
|
-
{
|
|
49
|
-
defaultChecked={
|
|
90
|
+
checked={control.current}
|
|
91
|
+
defaultChecked={control.controlled ? control.current : defaultChecked}
|
|
50
92
|
{disabled}
|
|
51
93
|
onchange={(event) => {
|
|
52
|
-
|
|
53
|
-
keepChecked(event.currentTarget, () =>
|
|
94
|
+
control.set(event.currentTarget.checked);
|
|
95
|
+
keepChecked(event.currentTarget, () => control.current);
|
|
54
96
|
}}
|
|
97
|
+
onfocus={onFocus}
|
|
98
|
+
onblur={onBlur}
|
|
55
99
|
/>
|
|
56
100
|
<span class={switchTrackClass}><span class={switchThumbClass}></span></span>
|
|
57
101
|
{#if label}
|
package/dist/Switch.svelte.d.ts
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
import { type SwitchBaseProps } from "@xds/core";
|
|
2
|
+
import type { FocusEventHandler } from "svelte/elements";
|
|
2
3
|
import type { RootProps } from "./root.js";
|
|
3
4
|
export type SwitchProps = SwitchBaseProps & RootProps & {
|
|
4
|
-
onChange
|
|
5
|
+
onChange?: (checked: boolean) => void;
|
|
6
|
+
onFocus?: FocusEventHandler<HTMLInputElement>;
|
|
7
|
+
onBlur?: FocusEventHandler<HTMLInputElement>;
|
|
5
8
|
};
|
|
6
9
|
/**
|
|
7
10
|
* Turns a setting on or off, and takes effect at once. For a choice that is applied later, with a
|
|
8
11
|
* form, use a Checkbox.
|
|
9
12
|
*
|
|
10
13
|
* It is a native checkbox with the switch role, so the keyboard, forms and screen readers treat
|
|
11
|
-
* it as one. The input is hidden and the track is drawn beside it.
|
|
14
|
+
* it as one. The input is hidden and the track is drawn beside it. Without `checked` it keeps its
|
|
15
|
+
* own state, from `defaultChecked`, and a reset of its form puts that back.
|
|
16
|
+
*
|
|
17
|
+
* `focus()`, `blur()` and `element()` on the instance reach the native checkbox.
|
|
12
18
|
*/
|
|
13
|
-
declare const Switch: import("svelte").Component<SwitchProps, {
|
|
19
|
+
declare const Switch: import("svelte").Component<SwitchProps, {
|
|
20
|
+
focus: (options?: FocusOptions) => void;
|
|
21
|
+
blur: () => void;
|
|
22
|
+
element: () => HTMLInputElement | undefined;
|
|
23
|
+
}, "">;
|
|
14
24
|
type Switch = ReturnType<typeof Switch>;
|
|
15
25
|
export default Switch;
|
package/dist/Tabs.svelte
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
The selected tab is underlined as well as darker, so the choice does not depend on color. This
|
|
7
7
|
is only the row: the app shows the view that matches `value`. The arrow keys move between tabs.
|
|
8
|
+
Without `value` the tabs keep their own, from `defaultValue` or else the first.
|
|
8
9
|
-->
|
|
9
10
|
<script module lang="ts">
|
|
10
11
|
import type { TabsBaseProps } from "@xds/core";
|
|
@@ -12,37 +13,51 @@
|
|
|
12
13
|
|
|
13
14
|
export type TabsProps<Value extends string> = TabsBaseProps<Value> &
|
|
14
15
|
RootProps & {
|
|
15
|
-
onChange
|
|
16
|
+
onChange?: (value: Value) => void;
|
|
16
17
|
};
|
|
17
18
|
</script>
|
|
18
19
|
|
|
19
20
|
<script lang="ts" generics="Value extends string">
|
|
20
|
-
import { classes, tabStopIndex, tabsClass } from "@xds/core";
|
|
21
|
+
import { classes, rootAttributes, tabStopIndex, tabsClass } from "@xds/core";
|
|
21
22
|
import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
|
|
22
23
|
import * as tabs from "@zag-js/tabs";
|
|
24
|
+
import { controllable } from "./controllable.svelte.js";
|
|
23
25
|
import Icon from "./Icon.svelte";
|
|
24
26
|
|
|
27
|
+
// `value` stays in the rest, where whether it is given at all can be asked.
|
|
25
28
|
let {
|
|
26
29
|
items,
|
|
27
|
-
|
|
30
|
+
defaultValue,
|
|
28
31
|
label,
|
|
29
32
|
fullWidth,
|
|
30
33
|
onChange,
|
|
31
34
|
class: className,
|
|
32
35
|
style,
|
|
36
|
+
...rest
|
|
33
37
|
}: TabsProps<Value> = $props();
|
|
34
38
|
|
|
39
|
+
const control = controllable<Value | undefined, Value>(
|
|
40
|
+
() => rest,
|
|
41
|
+
"value",
|
|
42
|
+
() => rest.value,
|
|
43
|
+
() => defaultValue ?? items[0]?.value,
|
|
44
|
+
() => onChange,
|
|
45
|
+
);
|
|
35
46
|
const id = $props.id();
|
|
36
47
|
const service = useMachine(tabs.machine, () => ({
|
|
37
48
|
id,
|
|
38
|
-
value,
|
|
39
|
-
onValueChange: (details: tabs.ValueChangeDetails) =>
|
|
49
|
+
value: control.current ?? null,
|
|
50
|
+
onValueChange: (details: tabs.ValueChangeDetails) => control.set(details.value as Value),
|
|
40
51
|
}));
|
|
41
52
|
const api = $derived(tabs.connect(service, normalizeProps));
|
|
42
53
|
// Merged, so that the app's style joins any the machine writes on the root. The recipe gives
|
|
43
54
|
// the root part, `xds-tabs`.
|
|
44
55
|
const root = $derived(
|
|
45
|
-
mergeProps(api.getRootProps(), {
|
|
56
|
+
mergeProps(api.getRootProps(), {
|
|
57
|
+
...rootAttributes(rest),
|
|
58
|
+
class: classes(tabsClass(fullWidth), className),
|
|
59
|
+
style,
|
|
60
|
+
}),
|
|
46
61
|
);
|
|
47
62
|
</script>
|
|
48
63
|
|
package/dist/Tabs.svelte.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TabsBaseProps } from "@xds/core";
|
|
2
2
|
import type { RootProps } from "./root.js";
|
|
3
3
|
export type TabsProps<Value extends string> = TabsBaseProps<Value> & RootProps & {
|
|
4
|
-
onChange
|
|
4
|
+
onChange?: (value: Value) => void;
|
|
5
5
|
};
|
|
6
6
|
declare function $$render<Value extends string>(): {
|
|
7
7
|
props: TabsProps<Value>;
|
|
@@ -30,6 +30,7 @@ interface $$IsomorphicComponent {
|
|
|
30
30
|
*
|
|
31
31
|
* The selected tab is underlined as well as darker, so the choice does not depend on color. This
|
|
32
32
|
* is only the row: the app shows the view that matches `value`. The arrow keys move between tabs.
|
|
33
|
+
* Without `value` the tabs keep their own, from `defaultValue` or else the first.
|
|
33
34
|
*/
|
|
34
35
|
declare const Tabs: $$IsomorphicComponent;
|
|
35
36
|
type Tabs<Value extends string> = InstanceType<typeof Tabs<Value>>;
|
package/dist/Text.svelte
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
</script>
|
|
13
13
|
|
|
14
14
|
<script lang="ts">
|
|
15
|
-
import { classes, rootPart, textClass } from "@xds/core";
|
|
15
|
+
import { classes, rootAttributes, rootPart, textClass } from "@xds/core";
|
|
16
16
|
import { useDefaults } from "./defaults.svelte.js";
|
|
17
17
|
|
|
18
18
|
let {
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
class: className,
|
|
23
23
|
style,
|
|
24
24
|
children,
|
|
25
|
+
...rest
|
|
25
26
|
}: TextProps = $props();
|
|
26
27
|
|
|
27
28
|
const defaults = useDefaults("Text");
|
|
@@ -31,6 +32,7 @@
|
|
|
31
32
|
|
|
32
33
|
<svelte:element
|
|
33
34
|
this={as}
|
|
35
|
+
{...rootAttributes(rest)}
|
|
34
36
|
class={classes(rootPart("Text"), textClass({ variant, tone }), className)}
|
|
35
37
|
{style}>{@render children()}</svelte:element
|
|
36
38
|
>
|