@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
package/dist/EmptyState.svelte
CHANGED
|
@@ -16,13 +16,25 @@
|
|
|
16
16
|
</script>
|
|
17
17
|
|
|
18
18
|
<script lang="ts">
|
|
19
|
-
import { classes, EMPTY_STATE_PARTS, rootPart } from "@xds/core";
|
|
19
|
+
import { classes, EMPTY_STATE_PARTS, rootAttributes, rootPart } from "@xds/core";
|
|
20
20
|
import Icon from "./Icon.svelte";
|
|
21
21
|
|
|
22
|
-
let {
|
|
22
|
+
let {
|
|
23
|
+
icon,
|
|
24
|
+
title,
|
|
25
|
+
description,
|
|
26
|
+
action,
|
|
27
|
+
class: className,
|
|
28
|
+
style,
|
|
29
|
+
...rest
|
|
30
|
+
}: EmptyStateProps = $props();
|
|
23
31
|
</script>
|
|
24
32
|
|
|
25
|
-
<div
|
|
33
|
+
<div
|
|
34
|
+
{...rootAttributes(rest)}
|
|
35
|
+
class={classes(rootPart("EmptyState"), EMPTY_STATE_PARTS.root, className)}
|
|
36
|
+
{style}
|
|
37
|
+
>
|
|
26
38
|
<Icon name={icon} size="xl" class={EMPTY_STATE_PARTS.icon} />
|
|
27
39
|
<p class={EMPTY_STATE_PARTS.title}>{title}</p>
|
|
28
40
|
{#if description}
|
package/dist/Icon.svelte
CHANGED
|
@@ -12,16 +12,25 @@
|
|
|
12
12
|
|
|
13
13
|
<script lang="ts">
|
|
14
14
|
import { icons } from "@xds/tokens";
|
|
15
|
-
import { classes, iconClass, rootPart } from "@xds/core";
|
|
15
|
+
import { classes, iconClass, rootAttributes, rootPart } from "@xds/core";
|
|
16
16
|
import { useDefaults } from "./defaults.svelte.js";
|
|
17
17
|
|
|
18
|
-
let {
|
|
18
|
+
let {
|
|
19
|
+
name,
|
|
20
|
+
size: ownSize,
|
|
21
|
+
filled,
|
|
22
|
+
label,
|
|
23
|
+
class: className,
|
|
24
|
+
style,
|
|
25
|
+
...rest
|
|
26
|
+
}: IconProps = $props();
|
|
19
27
|
|
|
20
28
|
const defaults = useDefaults("Icon");
|
|
21
29
|
const size = $derived(ownSize ?? defaults().size);
|
|
22
30
|
</script>
|
|
23
31
|
|
|
24
32
|
<svg
|
|
33
|
+
{...rootAttributes(rest)}
|
|
25
34
|
viewBox="0 0 24 24"
|
|
26
35
|
fill={filled ? "currentColor" : "none"}
|
|
27
36
|
stroke="currentColor"
|
package/dist/IconButton.svelte
CHANGED
|
@@ -3,19 +3,24 @@
|
|
|
3
3
|
A button that holds only an icon, in Button's variants, sizes and states. It is a square as
|
|
4
4
|
tall as a Button of its size, and its pressable area is never smaller than the minimum target,
|
|
5
5
|
even when the square is. Like Button, it opens a Menu or a Tooltip it is the trigger of.
|
|
6
|
+
|
|
7
|
+
`focus()`, `blur()` and `element()` on the instance reach the native button.
|
|
6
8
|
-->
|
|
7
9
|
<script module lang="ts">
|
|
8
10
|
import type { IconButtonBaseProps } from "@xds/core";
|
|
11
|
+
import type { FocusEventHandler } from "svelte/elements";
|
|
9
12
|
import type { RootProps } from "./root.js";
|
|
10
13
|
|
|
11
14
|
export type IconButtonProps = IconButtonBaseProps &
|
|
12
15
|
RootProps & {
|
|
13
16
|
onPress?: () => void;
|
|
17
|
+
onFocus?: FocusEventHandler<HTMLButtonElement>;
|
|
18
|
+
onBlur?: FocusEventHandler<HTMLButtonElement>;
|
|
14
19
|
};
|
|
15
20
|
</script>
|
|
16
21
|
|
|
17
22
|
<script lang="ts">
|
|
18
|
-
import { buttonClass, classes, ICON_BUTTON_BOX, isHeld } from "@xds/core";
|
|
23
|
+
import { buttonClass, classes, ICON_BUTTON_BOX, isHeld, rootAttributes } from "@xds/core";
|
|
19
24
|
import type { HTMLButtonAttributes } from "svelte/elements";
|
|
20
25
|
import { useDefaults } from "./defaults.svelte.js";
|
|
21
26
|
import Icon from "./Icon.svelte";
|
|
@@ -31,8 +36,11 @@
|
|
|
31
36
|
disabled,
|
|
32
37
|
loading,
|
|
33
38
|
onPress,
|
|
39
|
+
onFocus,
|
|
40
|
+
onBlur,
|
|
34
41
|
class: className,
|
|
35
42
|
style,
|
|
43
|
+
...rest
|
|
36
44
|
}: IconButtonProps = $props();
|
|
37
45
|
|
|
38
46
|
const defaults = useDefaults("IconButton");
|
|
@@ -53,12 +61,32 @@
|
|
|
53
61
|
onclick: () => {
|
|
54
62
|
if (!loading) onPress?.();
|
|
55
63
|
},
|
|
64
|
+
onfocus: onFocus,
|
|
65
|
+
onblur: onBlur,
|
|
56
66
|
}),
|
|
57
67
|
() => loading === true,
|
|
58
68
|
);
|
|
69
|
+
let button = $state<HTMLButtonElement>();
|
|
70
|
+
|
|
71
|
+
/** Moves the focus to the native button. */
|
|
72
|
+
export function focus(options?: FocusOptions) {
|
|
73
|
+
button?.focus(options);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Takes the focus from the native button. */
|
|
77
|
+
export function blur() {
|
|
78
|
+
button?.blur();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The native button, once it is on the page. */
|
|
82
|
+
export function element(): HTMLButtonElement | undefined {
|
|
83
|
+
return button;
|
|
84
|
+
}
|
|
59
85
|
</script>
|
|
60
86
|
|
|
61
|
-
|
|
87
|
+
<!-- The app's id gives way to the one an overlay gives its trigger, which the overlay's own
|
|
88
|
+
parts point at. -->
|
|
89
|
+
<button {...rootAttributes(rest)} {...attributes()} bind:this={button}>
|
|
62
90
|
{#if loading}
|
|
63
91
|
<span class={ICON_BUTTON_BOX[size]}><Spinner size="sm" /></span>
|
|
64
92
|
{:else}
|
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
import type { IconButtonBaseProps } from "@xds/core";
|
|
2
|
+
import type { FocusEventHandler } from "svelte/elements";
|
|
2
3
|
import type { RootProps } from "./root.js";
|
|
3
4
|
export type IconButtonProps = IconButtonBaseProps & RootProps & {
|
|
4
5
|
onPress?: () => void;
|
|
6
|
+
onFocus?: FocusEventHandler<HTMLButtonElement>;
|
|
7
|
+
onBlur?: FocusEventHandler<HTMLButtonElement>;
|
|
5
8
|
};
|
|
6
9
|
/**
|
|
7
10
|
* A button that holds only an icon, in Button's variants, sizes and states. It is a square as
|
|
8
11
|
* tall as a Button of its size, and its pressable area is never smaller than the minimum target,
|
|
9
12
|
* even when the square is. Like Button, it opens a Menu or a Tooltip it is the trigger of.
|
|
13
|
+
*
|
|
14
|
+
* `focus()`, `blur()` and `element()` on the instance reach the native button.
|
|
10
15
|
*/
|
|
11
|
-
declare const IconButton: import("svelte").Component<IconButtonProps, {
|
|
16
|
+
declare const IconButton: import("svelte").Component<IconButtonProps, {
|
|
17
|
+
focus: (options?: FocusOptions) => void;
|
|
18
|
+
blur: () => void;
|
|
19
|
+
element: () => HTMLButtonElement | undefined;
|
|
20
|
+
}, "">;
|
|
12
21
|
type IconButton = ReturnType<typeof IconButton>;
|
|
13
22
|
export default IconButton;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
The names the components inside it give their own parts, in the app's language: a banner's
|
|
4
|
+
dismiss control, a search field's clear control, a calendar's month buttons. A label passed to a
|
|
5
|
+
component wins, and a Labels inside another keeps the outer one's labels and replaces only those
|
|
6
|
+
it names.
|
|
7
|
+
-->
|
|
8
|
+
<script module lang="ts">
|
|
9
|
+
import type { ComponentLabels } from "@xds/core";
|
|
10
|
+
import type { Snippet } from "svelte";
|
|
11
|
+
|
|
12
|
+
export type { ComponentLabels } from "@xds/core";
|
|
13
|
+
|
|
14
|
+
export type LabelsProps = {
|
|
15
|
+
/** The labels, by key: `{ dismiss: "닫기" }`. It may change; the components follow it. */
|
|
16
|
+
value: Partial<ComponentLabels>;
|
|
17
|
+
children: Snippet;
|
|
18
|
+
};
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<script lang="ts">
|
|
22
|
+
import { provideLabels } from "./labels.svelte.js";
|
|
23
|
+
|
|
24
|
+
let { value, children }: LabelsProps = $props();
|
|
25
|
+
|
|
26
|
+
provideLabels(() => value);
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
{@render children()}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ComponentLabels } from "@xds/core";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
export type { ComponentLabels } from "@xds/core";
|
|
4
|
+
export type LabelsProps = {
|
|
5
|
+
/** The labels, by key: `{ dismiss: "닫기" }`. It may change; the components follow it. */
|
|
6
|
+
value: Partial<ComponentLabels>;
|
|
7
|
+
children: Snippet;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The names the components inside it give their own parts, in the app's language: a banner's
|
|
11
|
+
* dismiss control, a search field's clear control, a calendar's month buttons. A label passed to a
|
|
12
|
+
* component wins, and a Labels inside another keeps the outer one's labels and replaces only those
|
|
13
|
+
* it names.
|
|
14
|
+
*/
|
|
15
|
+
declare const Labels: import("svelte").Component<LabelsProps, {}, "">;
|
|
16
|
+
type Labels = ReturnType<typeof Labels>;
|
|
17
|
+
export default Labels;
|
package/dist/MediaCard.svelte
CHANGED
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
mediaCardContentClass,
|
|
31
31
|
mediaCardIds,
|
|
32
32
|
mediaCardThumbnailClass,
|
|
33
|
+
rootAttributes,
|
|
33
34
|
rootPart,
|
|
34
35
|
} from "@xds/core";
|
|
35
36
|
import { useDefaults } from "./defaults.svelte.js";
|
|
@@ -50,6 +51,7 @@
|
|
|
50
51
|
onPress,
|
|
51
52
|
class: className,
|
|
52
53
|
style,
|
|
54
|
+
...rest
|
|
53
55
|
}: MediaCardProps = $props();
|
|
54
56
|
|
|
55
57
|
const defaults = useDefaults("MediaCard");
|
|
@@ -89,7 +91,7 @@
|
|
|
89
91
|
{/snippet}
|
|
90
92
|
|
|
91
93
|
{#if pressable}
|
|
92
|
-
<div class={classes(MEDIA_CARD_PARTS.pressable, root)} {style}>
|
|
94
|
+
<div {...rootAttributes(rest)} class={classes(MEDIA_CARD_PARTS.pressable, root)} {style}>
|
|
93
95
|
<button
|
|
94
96
|
type="button"
|
|
95
97
|
onclick={() => onPress?.()}
|
|
@@ -102,6 +104,7 @@
|
|
|
102
104
|
<!-- A group, not a fieldset: a fieldset groups form controls, and sizes itself to its
|
|
103
105
|
content, which would undo the ellipses. -->
|
|
104
106
|
<div
|
|
107
|
+
{...rootAttributes(rest)}
|
|
105
108
|
role="group"
|
|
106
109
|
aria-labelledby={ids.names}
|
|
107
110
|
class={classes(MEDIA_CARD_PARTS.group, root)}
|
package/dist/Menu.svelte
CHANGED
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
menuItemClass,
|
|
33
33
|
opensOnPress,
|
|
34
34
|
readCssPx,
|
|
35
|
+
rootAttributes,
|
|
35
36
|
underlayLayerStyle,
|
|
36
37
|
} from "@xds/core";
|
|
37
38
|
import * as menu from "@zag-js/menu";
|
|
@@ -42,11 +43,21 @@
|
|
|
42
43
|
import { createPresence } from "./presence.svelte.js";
|
|
43
44
|
import { provideTrigger, type TriggerProps } from "./trigger.svelte.js";
|
|
44
45
|
|
|
45
|
-
let {
|
|
46
|
+
let {
|
|
47
|
+
label,
|
|
48
|
+
items,
|
|
49
|
+
align = "start",
|
|
50
|
+
trigger,
|
|
51
|
+
class: className,
|
|
52
|
+
style,
|
|
53
|
+
...rest
|
|
54
|
+
}: MenuProps = $props();
|
|
46
55
|
|
|
47
56
|
const id = $props.id();
|
|
48
57
|
const service = useMachine(menu.machine, () => ({
|
|
49
58
|
id,
|
|
59
|
+
// The app's id names the menu, and the trigger's aria-controls points there.
|
|
60
|
+
ids: rest.id === undefined ? undefined : { content: rest.id },
|
|
50
61
|
"aria-label": label,
|
|
51
62
|
positioning: {
|
|
52
63
|
placement: `bottom-${align}` as const,
|
|
@@ -112,6 +123,7 @@
|
|
|
112
123
|
);
|
|
113
124
|
const content = $derived(
|
|
114
125
|
mergeProps(api.getContentProps(), {
|
|
126
|
+
...rootAttributes(rest),
|
|
115
127
|
class: classes("xds-menu", className),
|
|
116
128
|
style,
|
|
117
129
|
// This handler runs before Zag's.
|
package/dist/PlaceRow.svelte
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
listRowClass,
|
|
12
12
|
listRowDescriptionClass,
|
|
13
13
|
listRowTitleClass,
|
|
14
|
+
rootAttributes,
|
|
14
15
|
} from "@xds/core";
|
|
15
16
|
import Icon from "./Icon.svelte";
|
|
16
17
|
import type { ListRowProps } from "./ListRow.svelte";
|
|
@@ -28,6 +29,7 @@
|
|
|
28
29
|
class: className,
|
|
29
30
|
style,
|
|
30
31
|
current: kind,
|
|
32
|
+
...rest
|
|
31
33
|
}: ListRowProps & { current: "true" | "page" } = $props();
|
|
32
34
|
|
|
33
35
|
const current = $derived(selected ? kind : undefined);
|
|
@@ -52,6 +54,7 @@
|
|
|
52
54
|
|
|
53
55
|
{#if onPress}
|
|
54
56
|
<button
|
|
57
|
+
{...rootAttributes(rest)}
|
|
55
58
|
aria-current={current}
|
|
56
59
|
type="button"
|
|
57
60
|
{disabled}
|
|
@@ -62,5 +65,7 @@
|
|
|
62
65
|
{@render content()}
|
|
63
66
|
</button>
|
|
64
67
|
{:else}
|
|
65
|
-
<div aria-current={current} class={row} {style}>
|
|
68
|
+
<div {...rootAttributes(rest)} aria-current={current} class={row} {style}>
|
|
69
|
+
{@render content()}
|
|
70
|
+
</div>
|
|
66
71
|
{/if}
|
package/dist/ProgressBar.svelte
CHANGED
|
@@ -16,15 +16,17 @@
|
|
|
16
16
|
progressBarClass,
|
|
17
17
|
progressBarFillClass,
|
|
18
18
|
progressPercent,
|
|
19
|
+
rootAttributes,
|
|
19
20
|
rootPart,
|
|
20
21
|
} from "@xds/core";
|
|
21
22
|
|
|
22
|
-
let { value, label, class: className, style }: ProgressBarProps = $props();
|
|
23
|
+
let { value, label, class: className, style, ...rest }: ProgressBarProps = $props();
|
|
23
24
|
|
|
24
25
|
const percent = $derived(progressPercent(value));
|
|
25
26
|
</script>
|
|
26
27
|
|
|
27
28
|
<div
|
|
29
|
+
{...rootAttributes(rest)}
|
|
28
30
|
role="progressbar"
|
|
29
31
|
aria-label={label}
|
|
30
32
|
aria-valuemin={0}
|
package/dist/RadioGroup.svelte
CHANGED
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
The chosen option has a dot and a thicker ring, so the choice does not depend on color. The
|
|
7
7
|
options are native radio buttons, hidden and drawn beside, in a group named by the legend: the
|
|
8
|
-
arrow keys move between them, and the error is tied to the group and announced.
|
|
8
|
+
arrow keys move between them, and the error is tied to the group and announced. Without
|
|
9
|
+
`value` it keeps its own choice, from `defaultValue`, and a reset of its form puts that back;
|
|
10
|
+
given `value`, even as `undefined`, it shows the app's.
|
|
9
11
|
-->
|
|
10
12
|
<script module lang="ts">
|
|
11
13
|
import type { RadioGroupBaseProps } from "@xds/core";
|
|
@@ -15,34 +17,47 @@
|
|
|
15
17
|
|
|
16
18
|
export type RadioGroupProps<Value extends string = string> = RadioGroupBaseProps<Value> &
|
|
17
19
|
RootProps & {
|
|
18
|
-
onChange
|
|
20
|
+
onChange?: (value: Value) => void;
|
|
19
21
|
};
|
|
20
22
|
</script>
|
|
21
23
|
|
|
22
24
|
<script lang="ts" generics="Value extends string = string">
|
|
23
|
-
import { classes } from "@xds/core";
|
|
25
|
+
import { classes, rootAttributes } from "@xds/core";
|
|
26
|
+
import { controllable, followFormReset } from "./controllable.svelte.js";
|
|
24
27
|
import { keepChecked } from "./controlled.js";
|
|
25
28
|
|
|
29
|
+
// `value` stays in the rest, where whether it is given at all can be asked.
|
|
26
30
|
let {
|
|
27
31
|
label,
|
|
28
32
|
options,
|
|
29
|
-
|
|
33
|
+
defaultValue,
|
|
30
34
|
disabled,
|
|
31
35
|
error,
|
|
32
36
|
name,
|
|
33
37
|
onChange,
|
|
34
38
|
class: className,
|
|
35
39
|
style,
|
|
40
|
+
...rest
|
|
36
41
|
}: RadioGroupProps<Value> = $props();
|
|
37
42
|
|
|
43
|
+
const control = controllable<Value | undefined, Value>(
|
|
44
|
+
() => rest,
|
|
45
|
+
"value",
|
|
46
|
+
() => rest.value,
|
|
47
|
+
() => defaultValue,
|
|
48
|
+
() => onChange,
|
|
49
|
+
);
|
|
50
|
+
|
|
38
51
|
const id = $props.id();
|
|
39
52
|
const labelId = `${id}-label`;
|
|
40
53
|
const errorId = `${id}-error`;
|
|
41
54
|
const invalid = $derived(error !== undefined);
|
|
42
55
|
let group = $state<HTMLDivElement>();
|
|
56
|
+
followFormReset(() => group, control);
|
|
43
57
|
</script>
|
|
44
58
|
|
|
45
59
|
<div
|
|
60
|
+
{...rootAttributes(rest)}
|
|
46
61
|
bind:this={group}
|
|
47
62
|
role="radiogroup"
|
|
48
63
|
aria-labelledby={labelId}
|
|
@@ -67,8 +82,8 @@
|
|
|
67
82
|
class="xds-radio-group__input sr-only"
|
|
68
83
|
name={name ?? id}
|
|
69
84
|
value={option.value}
|
|
70
|
-
checked={option.value ===
|
|
71
|
-
defaultChecked={option.value ===
|
|
85
|
+
checked={option.value === control.current}
|
|
86
|
+
defaultChecked={option.value === (control.controlled ? control.current : defaultValue)}
|
|
72
87
|
{disabled}
|
|
73
88
|
aria-labelledby={`${id}-${index}`}
|
|
74
89
|
aria-describedby={[
|
|
@@ -79,11 +94,11 @@
|
|
|
79
94
|
.join(" ") || undefined}
|
|
80
95
|
aria-invalid={invalid ? "true" : undefined}
|
|
81
96
|
onchange={() => {
|
|
82
|
-
|
|
97
|
+
control.set(option.value);
|
|
83
98
|
// The browser moved the dot already; where the owner kept the old value, it goes
|
|
84
99
|
// back, on every radio of the group.
|
|
85
100
|
for (const input of group?.querySelectorAll("input") ?? []) {
|
|
86
|
-
keepChecked(input, () => input.value ===
|
|
101
|
+
keepChecked(input, () => input.value === control.current);
|
|
87
102
|
}
|
|
88
103
|
}}
|
|
89
104
|
/>
|
|
@@ -2,7 +2,7 @@ import type { RadioGroupBaseProps } from "@xds/core";
|
|
|
2
2
|
import type { RootProps } from "./root.js";
|
|
3
3
|
export type { RadioOption } from "@xds/core";
|
|
4
4
|
export type RadioGroupProps<Value extends string = string> = RadioGroupBaseProps<Value> & RootProps & {
|
|
5
|
-
onChange
|
|
5
|
+
onChange?: (value: Value) => void;
|
|
6
6
|
};
|
|
7
7
|
declare function $$render<Value extends string = string>(): {
|
|
8
8
|
props: RadioGroupProps<Value>;
|
|
@@ -31,7 +31,9 @@ interface $$IsomorphicComponent {
|
|
|
31
31
|
*
|
|
32
32
|
* The chosen option has a dot and a thicker ring, so the choice does not depend on color. The
|
|
33
33
|
* options are native radio buttons, hidden and drawn beside, in a group named by the legend: the
|
|
34
|
-
* arrow keys move between them, and the error is tied to the group and announced.
|
|
34
|
+
* arrow keys move between them, and the error is tied to the group and announced. Without
|
|
35
|
+
* `value` it keeps its own choice, from `defaultValue`, and a reset of its form puts that back;
|
|
36
|
+
* given `value`, even as `undefined`, it shows the app's.
|
|
35
37
|
*/
|
|
36
38
|
declare const RadioGroup: $$IsomorphicComponent;
|
|
37
39
|
type RadioGroup<Value extends string = string> = InstanceType<typeof RadioGroup<Value>>;
|
package/dist/SearchField.svelte
CHANGED
|
@@ -1,45 +1,89 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
@component
|
|
3
3
|
A text field for a query: TextField's box as a pill, with a search icon in front and, while
|
|
4
|
-
there is a value, a control that clears it. Escape clears too.
|
|
4
|
+
there is a value, a control that clears it. Escape clears too. A read-only field has neither.
|
|
5
5
|
|
|
6
6
|
Use it to filter or search what is on the screen. For a value that is saved with a form, use a
|
|
7
|
-
TextField, which has a visible label.
|
|
7
|
+
TextField, which has a visible label. Without `value` it keeps its own query, from
|
|
8
|
+
`defaultValue`, and a reset of its form puts that back.
|
|
9
|
+
|
|
10
|
+
`focus()`, `blur()` and `element()` on the instance reach the native input.
|
|
8
11
|
-->
|
|
9
12
|
<script module lang="ts">
|
|
10
13
|
import type { SearchFieldBaseProps } from "@xds/core";
|
|
14
|
+
import type { FocusEventHandler } from "svelte/elements";
|
|
11
15
|
import type { RootProps } from "./root.js";
|
|
12
16
|
|
|
13
17
|
export type SearchFieldProps = SearchFieldBaseProps &
|
|
14
18
|
RootProps & {
|
|
15
|
-
onChange
|
|
19
|
+
onChange?: (value: string) => void;
|
|
16
20
|
/** Called with the query on Enter, or on the search key of a software keyboard. */
|
|
17
21
|
onSubmit?: (value: string) => void;
|
|
22
|
+
onFocus?: FocusEventHandler<HTMLInputElement>;
|
|
23
|
+
onBlur?: FocusEventHandler<HTMLInputElement>;
|
|
18
24
|
};
|
|
19
25
|
</script>
|
|
20
26
|
|
|
21
27
|
<script lang="ts">
|
|
22
|
-
import { classes, rootPart } from "@xds/core";
|
|
28
|
+
import { classes, rootAttributes, rootPart } from "@xds/core";
|
|
29
|
+
import { controllable, followFormReset } from "./controllable.svelte.js";
|
|
23
30
|
import { keepValue } from "./controlled.js";
|
|
24
31
|
import Icon from "./Icon.svelte";
|
|
32
|
+
import { useLabels } from "./labels.svelte.js";
|
|
25
33
|
|
|
34
|
+
// `value` stays in the rest, where whether it is given at all can be asked.
|
|
26
35
|
let {
|
|
27
|
-
|
|
36
|
+
defaultValue = "",
|
|
37
|
+
readOnly,
|
|
28
38
|
label,
|
|
29
39
|
placeholder,
|
|
30
40
|
disabled,
|
|
31
41
|
clearLabel,
|
|
32
42
|
onChange,
|
|
33
43
|
onSubmit,
|
|
44
|
+
onFocus,
|
|
45
|
+
onBlur,
|
|
34
46
|
class: className,
|
|
35
47
|
style,
|
|
48
|
+
...rest
|
|
36
49
|
}: SearchFieldProps = $props();
|
|
37
50
|
|
|
51
|
+
const labels = useLabels();
|
|
52
|
+
|
|
53
|
+
const control = controllable(
|
|
54
|
+
() => rest,
|
|
55
|
+
"value",
|
|
56
|
+
() => rest.value ?? "",
|
|
57
|
+
() => defaultValue,
|
|
58
|
+
() => onChange,
|
|
59
|
+
);
|
|
38
60
|
let input = $state<HTMLInputElement>();
|
|
61
|
+
followFormReset(() => input, control);
|
|
62
|
+
// Nothing to clear in a field that cannot be changed.
|
|
63
|
+
const clearable = $derived(control.current !== "" && !disabled && !readOnly);
|
|
64
|
+
|
|
65
|
+
/** Moves the focus to the native input. */
|
|
66
|
+
export function focus(options?: FocusOptions) {
|
|
67
|
+
input?.focus(options);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Takes the focus from the native input. */
|
|
71
|
+
export function blur() {
|
|
72
|
+
input?.blur();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The native input, once it is on the page. */
|
|
76
|
+
export function element(): HTMLInputElement | undefined {
|
|
77
|
+
return input;
|
|
78
|
+
}
|
|
39
79
|
</script>
|
|
40
80
|
|
|
41
81
|
<!-- TextField's box, so its part as well as its own. -->
|
|
42
|
-
<div
|
|
82
|
+
<div
|
|
83
|
+
{...rootAttributes(rest)}
|
|
84
|
+
class={classes("xds-text-field", rootPart("SearchField"), className)}
|
|
85
|
+
{style}
|
|
86
|
+
>
|
|
43
87
|
<div class="xds-text-field__control xds-text-field__control--pill xds-text-field__group">
|
|
44
88
|
<span class="xds-text-field__slot xds-text-field__slot--leading"
|
|
45
89
|
><Icon name="search" size="sm" /></span
|
|
@@ -54,36 +98,39 @@
|
|
|
54
98
|
aria-label={label}
|
|
55
99
|
enterkeyhint="search"
|
|
56
100
|
{placeholder}
|
|
57
|
-
{
|
|
58
|
-
defaultValue={
|
|
101
|
+
value={control.current}
|
|
102
|
+
defaultValue={control.controlled ? control.current : defaultValue}
|
|
103
|
+
readonly={readOnly}
|
|
59
104
|
{disabled}
|
|
60
|
-
data-uses-escape={
|
|
105
|
+
data-uses-escape={clearable ? "" : undefined}
|
|
61
106
|
oninput={(event) => {
|
|
62
|
-
|
|
107
|
+
control.set(event.currentTarget.value);
|
|
63
108
|
if (!(event instanceof InputEvent && event.isComposing))
|
|
64
|
-
keepValue(event.currentTarget, () =>
|
|
109
|
+
keepValue(event.currentTarget, () => control.current);
|
|
65
110
|
}}
|
|
66
|
-
oncompositionend={(event) => keepValue(event.currentTarget, () =>
|
|
111
|
+
oncompositionend={(event) => keepValue(event.currentTarget, () => control.current)}
|
|
67
112
|
onkeydown={(event) => {
|
|
68
113
|
// While a composition is open, Enter and Escape belong to the input method.
|
|
69
114
|
if (event.isComposing) return;
|
|
70
115
|
if (event.key === "Enter" && onSubmit) {
|
|
71
116
|
event.preventDefault();
|
|
72
|
-
onSubmit(
|
|
117
|
+
onSubmit(control.current);
|
|
73
118
|
}
|
|
74
|
-
if (event.key === "Escape" &&
|
|
119
|
+
if (event.key === "Escape" && clearable) {
|
|
75
120
|
event.stopPropagation();
|
|
76
|
-
|
|
121
|
+
control.set("");
|
|
77
122
|
}
|
|
78
123
|
}}
|
|
124
|
+
onfocus={onFocus}
|
|
125
|
+
onblur={onBlur}
|
|
79
126
|
/>
|
|
80
|
-
{#if
|
|
127
|
+
{#if clearable}
|
|
81
128
|
<span class="xds-text-field__slot xds-text-field__slot--trailing">
|
|
82
129
|
<button
|
|
83
130
|
type="button"
|
|
84
|
-
aria-label={clearLabel ??
|
|
131
|
+
aria-label={clearLabel ?? labels().clear}
|
|
85
132
|
onclick={() => {
|
|
86
|
-
|
|
133
|
+
control.set("");
|
|
87
134
|
// The control is about to disappear, and focus would be lost with it.
|
|
88
135
|
input?.focus();
|
|
89
136
|
}}
|
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
import type { SearchFieldBaseProps } from "@xds/core";
|
|
2
|
+
import type { FocusEventHandler } from "svelte/elements";
|
|
2
3
|
import type { RootProps } from "./root.js";
|
|
3
4
|
export type SearchFieldProps = SearchFieldBaseProps & RootProps & {
|
|
4
|
-
onChange
|
|
5
|
+
onChange?: (value: string) => void;
|
|
5
6
|
/** Called with the query on Enter, or on the search key of a software keyboard. */
|
|
6
7
|
onSubmit?: (value: string) => void;
|
|
8
|
+
onFocus?: FocusEventHandler<HTMLInputElement>;
|
|
9
|
+
onBlur?: FocusEventHandler<HTMLInputElement>;
|
|
7
10
|
};
|
|
8
11
|
/**
|
|
9
12
|
* A text field for a query: TextField's box as a pill, with a search icon in front and, while
|
|
10
|
-
* there is a value, a control that clears it. Escape clears too.
|
|
13
|
+
* there is a value, a control that clears it. Escape clears too. A read-only field has neither.
|
|
11
14
|
*
|
|
12
15
|
* Use it to filter or search what is on the screen. For a value that is saved with a form, use a
|
|
13
|
-
* TextField, which has a visible label.
|
|
16
|
+
* TextField, which has a visible label. Without `value` it keeps its own query, from
|
|
17
|
+
* `defaultValue`, and a reset of its form puts that back.
|
|
18
|
+
*
|
|
19
|
+
* `focus()`, `blur()` and `element()` on the instance reach the native input.
|
|
14
20
|
*/
|
|
15
|
-
declare const SearchField: import("svelte").Component<SearchFieldProps, {
|
|
21
|
+
declare const SearchField: import("svelte").Component<SearchFieldProps, {
|
|
22
|
+
focus: (options?: FocusOptions) => void;
|
|
23
|
+
blur: () => void;
|
|
24
|
+
element: () => HTMLInputElement | undefined;
|
|
25
|
+
}, "">;
|
|
16
26
|
type SearchField = ReturnType<typeof SearchField>;
|
|
17
27
|
export default SearchField;
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
</script>
|
|
16
16
|
|
|
17
17
|
<script lang="ts">
|
|
18
|
-
import { classes, rootPart, SECTION_HEADER_PARTS } from "@xds/core";
|
|
18
|
+
import { classes, rootAttributes, rootPart, SECTION_HEADER_PARTS } from "@xds/core";
|
|
19
19
|
import Button from "./Button.svelte";
|
|
20
20
|
import Icon from "./Icon.svelte";
|
|
21
21
|
|
|
@@ -27,10 +27,15 @@
|
|
|
27
27
|
action,
|
|
28
28
|
class: className,
|
|
29
29
|
style,
|
|
30
|
+
...rest
|
|
30
31
|
}: SectionHeaderProps = $props();
|
|
31
32
|
</script>
|
|
32
33
|
|
|
33
|
-
<div
|
|
34
|
+
<div
|
|
35
|
+
{...rootAttributes(rest)}
|
|
36
|
+
class={classes(rootPart("SectionHeader"), SECTION_HEADER_PARTS.root, className)}
|
|
37
|
+
{style}
|
|
38
|
+
>
|
|
34
39
|
<div class={SECTION_HEADER_PARTS.lead}>
|
|
35
40
|
{#if icon}
|
|
36
41
|
<span class={SECTION_HEADER_PARTS.icon}><Icon name={icon} size="md" /></span>
|