@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.
Files changed (62) hide show
  1. package/dist/Accordion.svelte +7 -2
  2. package/dist/Avatar.svelte +10 -2
  3. package/dist/AvatarStack.svelte +11 -1
  4. package/dist/Badge.svelte +14 -3
  5. package/dist/Banner.svelte +6 -1
  6. package/dist/Button.svelte +30 -2
  7. package/dist/Button.svelte.d.ts +10 -1
  8. package/dist/Card.svelte +16 -2
  9. package/dist/Checkbox.svelte +52 -8
  10. package/dist/Checkbox.svelte.d.ts +13 -3
  11. package/dist/Chip.svelte +3 -1
  12. package/dist/ChipBar.svelte +3 -2
  13. package/dist/CountBadge.svelte +4 -2
  14. package/dist/DatePicker.svelte +11 -1
  15. package/dist/DateRangePicker.svelte +6 -1
  16. package/dist/Dialog.svelte +9 -2
  17. package/dist/Divider.svelte +7 -3
  18. package/dist/EmptyState.svelte +15 -3
  19. package/dist/Icon.svelte +11 -2
  20. package/dist/IconButton.svelte +30 -2
  21. package/dist/IconButton.svelte.d.ts +10 -1
  22. package/dist/Labels.svelte +29 -0
  23. package/dist/Labels.svelte.d.ts +17 -0
  24. package/dist/MediaCard.svelte +4 -1
  25. package/dist/Menu.svelte +13 -1
  26. package/dist/PlaceRow.svelte +6 -1
  27. package/dist/ProgressBar.svelte +3 -1
  28. package/dist/RadioGroup.svelte +23 -8
  29. package/dist/RadioGroup.svelte.d.ts +4 -2
  30. package/dist/SearchField.svelte +65 -18
  31. package/dist/SearchField.svelte.d.ts +14 -4
  32. package/dist/SectionHeader.svelte +7 -2
  33. package/dist/SegmentedControl.svelte +21 -7
  34. package/dist/SegmentedControl.svelte.d.ts +3 -2
  35. package/dist/Select.svelte +25 -5
  36. package/dist/Select.svelte.d.ts +3 -2
  37. package/dist/Sidebar.svelte +3 -0
  38. package/dist/Skeleton.svelte +10 -2
  39. package/dist/Slider.svelte +23 -7
  40. package/dist/Slider.svelte.d.ts +2 -2
  41. package/dist/Spinner.svelte +3 -2
  42. package/dist/Switch.svelte +53 -9
  43. package/dist/Switch.svelte.d.ts +13 -3
  44. package/dist/Tabs.svelte +21 -6
  45. package/dist/Tabs.svelte.d.ts +2 -1
  46. package/dist/Text.svelte +3 -1
  47. package/dist/TextField.svelte +59 -14
  48. package/dist/TextField.svelte.d.ts +13 -3
  49. package/dist/Thumbnail.svelte +7 -1
  50. package/dist/Toast.svelte +12 -2
  51. package/dist/Tooltip.svelte +9 -2
  52. package/dist/TooltipOverlay.svelte +9 -2
  53. package/dist/controllable.svelte.d.ts +28 -0
  54. package/dist/controllable.svelte.js +41 -0
  55. package/dist/index.d.ts +1 -0
  56. package/dist/index.js +1 -0
  57. package/dist/labels.svelte.d.ts +13 -0
  58. package/dist/labels.svelte.js +24 -0
  59. package/dist/preview/Component.svelte +2 -0
  60. package/dist/preview/components.js +2 -1
  61. package/dist/root.d.ts +4 -2
  62. package/package.json +3 -3
@@ -25,7 +25,7 @@
25
25
  </script>
26
26
 
27
27
  <script lang="ts" generics="Value extends string = string">
28
- import { ACCORDION_PARTS, classes, focusTitleOnClick } from "@xds/core";
28
+ import { ACCORDION_PARTS, classes, focusTitleOnClick, rootAttributes } from "@xds/core";
29
29
  import * as accordion from "@zag-js/accordion";
30
30
  import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
31
31
  import AccordionPanel from "./AccordionPanel.svelte";
@@ -38,6 +38,7 @@
38
38
  onChange,
39
39
  class: className,
40
40
  style,
41
+ ...rest
41
42
  }: AccordionProps<Value> = $props();
42
43
 
43
44
  const id = $props.id();
@@ -52,7 +53,11 @@
52
53
  const api = $derived(accordion.connect(service, normalizeProps));
53
54
  // Merged, so that the app's style joins any the machine writes on the root.
54
55
  const root = $derived(
55
- mergeProps(api.getRootProps(), { class: classes("xds-accordion", className), style }),
56
+ mergeProps(api.getRootProps(), {
57
+ ...rootAttributes(rest),
58
+ class: classes("xds-accordion", className),
59
+ style,
60
+ }),
56
61
  );
57
62
  const body = (value: Value) => {
58
63
  // The panel hides itself once it has finished closing; see AccordionPanel.
@@ -13,11 +13,18 @@
13
13
  </script>
14
14
 
15
15
  <script lang="ts">
16
- import { avatarClass, avatarInitials, classes, pictureClass, rootPart } from "@xds/core";
16
+ import {
17
+ avatarClass,
18
+ avatarInitials,
19
+ classes,
20
+ pictureClass,
21
+ rootAttributes,
22
+ rootPart,
23
+ } from "@xds/core";
17
24
  import { useDefaults } from "./defaults.svelte.js";
18
25
  import { createPicture } from "./picture.svelte.js";
19
26
 
20
- let { name, src, size: ownSize, class: className, style }: AvatarProps = $props();
27
+ let { name, src, size: ownSize, class: className, style, ...rest }: AvatarProps = $props();
21
28
 
22
29
  const defaults = useDefaults("Avatar");
23
30
  const size = $derived(ownSize ?? defaults().size);
@@ -26,6 +33,7 @@
26
33
  </script>
27
34
 
28
35
  <span
36
+ {...rootAttributes(rest)}
29
37
  role="img"
30
38
  aria-label={name}
31
39
  class={classes(rootPart("Avatar"), avatarClass(size), className)}
@@ -17,12 +17,21 @@
17
17
  avatarStackItemClass,
18
18
  avatarStackRestClass,
19
19
  classes,
20
+ rootAttributes,
20
21
  rootPart,
21
22
  } from "@xds/core";
22
23
  import Avatar from "./Avatar.svelte";
23
24
  import { useDefaults } from "./defaults.svelte.js";
24
25
 
25
- let { people, max, size: ownSize, label, class: className, style }: AvatarStackProps = $props();
26
+ let {
27
+ people,
28
+ max,
29
+ size: ownSize,
30
+ label,
31
+ class: className,
32
+ style,
33
+ ...rest
34
+ }: AvatarStackProps = $props();
26
35
 
27
36
  const defaults = useDefaults("AvatarStack");
28
37
  // Resolved here, built-in default included, so that the avatars take the stack's size rather
@@ -33,6 +42,7 @@
33
42
  </script>
34
43
 
35
44
  <span
45
+ {...rootAttributes(rest)}
36
46
  role="img"
37
47
  aria-label={stack.name}
38
48
  class={classes(rootPart("AvatarStack"), avatarStackClass, className)}
package/dist/Badge.svelte CHANGED
@@ -18,17 +18,28 @@
18
18
  </script>
19
19
 
20
20
  <script lang="ts">
21
- import { badgeClass, badgeDotClass, classes, rootPart } from "@xds/core";
21
+ import { badgeClass, badgeDotClass, classes, rootAttributes, rootPart } from "@xds/core";
22
22
  import { useDefaults } from "./defaults.svelte.js";
23
23
  import Icon from "./Icon.svelte";
24
24
 
25
- let { tone: ownTone, dot, icon, class: className, style, children }: BadgeProps = $props();
25
+ let {
26
+ tone: ownTone,
27
+ dot,
28
+ icon,
29
+ class: className,
30
+ style,
31
+ children,
32
+ ...rest
33
+ }: BadgeProps = $props();
26
34
 
27
35
  const defaults = useDefaults("Badge");
28
36
  const tone = $derived(ownTone ?? defaults().tone);
29
37
  </script>
30
38
 
31
- <span class={classes(rootPart("Badge"), badgeClass(tone), className)} {style}
39
+ <span
40
+ {...rootAttributes(rest)}
41
+ class={classes(rootPart("Badge"), badgeClass(tone), className)}
42
+ {style}
32
43
  >{#if dot}<span aria-hidden="true" class={badgeDotClass}></span>{/if}{#if icon}<Icon
33
44
  name={icon}
34
45
  size="xs"
@@ -32,11 +32,13 @@
32
32
  bannerIconPath,
33
33
  bannerRole,
34
34
  classes,
35
+ rootAttributes,
35
36
  rootPart,
36
37
  } from "@xds/core";
37
38
  import Button from "./Button.svelte";
38
39
  import { useDefaults } from "./defaults.svelte.js";
39
40
  import IconButton from "./IconButton.svelte";
41
+ import { useLabels } from "./labels.svelte.js";
40
42
 
41
43
  let {
42
44
  tone: ownTone,
@@ -47,13 +49,16 @@
47
49
  class: className,
48
50
  style,
49
51
  children,
52
+ ...rest
50
53
  }: BannerProps = $props();
51
54
 
52
55
  const defaults = useDefaults("Banner");
56
+ const labels = useLabels();
53
57
  const tone = $derived(ownTone ?? defaults().tone);
54
58
  </script>
55
59
 
56
60
  <div
61
+ {...rootAttributes(rest)}
57
62
  role={bannerRole(tone)}
58
63
  class={classes(rootPart("Banner"), bannerClass(tone), className)}
59
64
  {style}
@@ -78,7 +83,7 @@
78
83
  <div class={BANNER_PARTS.dismiss}>
79
84
  <IconButton
80
85
  icon="x"
81
- label={dismissLabel ?? "Dismiss"}
86
+ label={dismissLabel ?? labels().dismiss}
82
87
  variant="ghost"
83
88
  size="sm"
84
89
  onPress={() => onDismiss()}
@@ -2,10 +2,13 @@
2
2
  @component
3
3
  A native button. It also opens a Menu or a Tooltip it is the trigger of: their props reach it
4
4
  through context.
5
+
6
+ `focus()`, `blur()` and `element()` on the instance reach the native button.
5
7
  -->
6
8
  <script module lang="ts">
7
9
  import type { ButtonBaseProps } from "@xds/core";
8
10
  import type { Snippet } from "svelte";
11
+ import type { FocusEventHandler } from "svelte/elements";
9
12
  import type { RootProps } from "./root.js";
10
13
 
11
14
  export type { ButtonVariant, ControlSize } from "@xds/core";
@@ -13,13 +16,15 @@
13
16
  export type ButtonProps = ButtonBaseProps &
14
17
  RootProps & {
15
18
  onPress?: () => void;
19
+ onFocus?: FocusEventHandler<HTMLButtonElement>;
20
+ onBlur?: FocusEventHandler<HTMLButtonElement>;
16
21
  /** Leave it out for a button that holds only an icon, and name that one with `aria-label`. */
17
22
  children?: Snippet;
18
23
  };
19
24
  </script>
20
25
 
21
26
  <script lang="ts">
22
- import { BUTTON_ICON, buttonClass, classes, isHeld } from "@xds/core";
27
+ import { BUTTON_ICON, buttonClass, classes, isHeld, rootAttributes } from "@xds/core";
23
28
  import type { HTMLButtonAttributes } from "svelte/elements";
24
29
  import { useDefaults } from "./defaults.svelte.js";
25
30
  import Icon from "./Icon.svelte";
@@ -37,10 +42,13 @@
37
42
  fullWidth = false,
38
43
  type = "button",
39
44
  onPress,
45
+ onFocus,
46
+ onBlur,
40
47
  "aria-label": ariaLabel,
41
48
  class: className,
42
49
  style,
43
50
  children,
51
+ ...rest
44
52
  }: ButtonProps = $props();
45
53
 
46
54
  const defaults = useDefaults("Button");
@@ -77,12 +85,32 @@
77
85
  }
78
86
  onPress?.();
79
87
  },
88
+ onfocus: onFocus,
89
+ onblur: onBlur,
80
90
  }),
81
91
  () => loading === true,
82
92
  );
93
+ let button = $state<HTMLButtonElement>();
94
+
95
+ /** Moves the focus to the native button. */
96
+ export function focus(options?: FocusOptions) {
97
+ button?.focus(options);
98
+ }
99
+
100
+ /** Takes the focus from the native button. */
101
+ export function blur() {
102
+ button?.blur();
103
+ }
104
+
105
+ /** The native button, once it is on the page. */
106
+ export function element(): HTMLButtonElement | undefined {
107
+ return button;
108
+ }
83
109
  </script>
84
110
 
85
- <button {...attributes()}
111
+ <!-- The app's id gives way to the one an overlay gives its trigger, which the overlay's own
112
+ parts point at. -->
113
+ <button {...rootAttributes(rest)} {...attributes()} bind:this={button}
86
114
  >{#if loading}{#if iconStart}
87
115
  <!-- Where the icon was, so the button keeps its width. -->
88
116
  <span class={icon.box}><Spinner size="sm" /></span>
@@ -1,16 +1,25 @@
1
1
  import type { ButtonBaseProps } 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 { ButtonVariant, ControlSize } from "@xds/core";
5
6
  export type ButtonProps = ButtonBaseProps & RootProps & {
6
7
  onPress?: () => void;
8
+ onFocus?: FocusEventHandler<HTMLButtonElement>;
9
+ onBlur?: FocusEventHandler<HTMLButtonElement>;
7
10
  /** Leave it out for a button that holds only an icon, and name that one with `aria-label`. */
8
11
  children?: Snippet;
9
12
  };
10
13
  /**
11
14
  * A native button. It also opens a Menu or a Tooltip it is the trigger of: their props reach it
12
15
  * through context.
16
+ *
17
+ * `focus()`, `blur()` and `element()` on the instance reach the native button.
13
18
  */
14
- declare const Button: import("svelte").Component<ButtonProps, {}, "">;
19
+ declare const Button: import("svelte").Component<ButtonProps, {
20
+ focus: (options?: FocusOptions) => void;
21
+ blur: () => void;
22
+ element: () => HTMLButtonElement | undefined;
23
+ }, "">;
15
24
  type Button = ReturnType<typeof Button>;
16
25
  export default Button;
package/dist/Card.svelte CHANGED
@@ -22,7 +22,14 @@
22
22
  </script>
23
23
 
24
24
  <script lang="ts">
25
- import { CARD_PARTS, cardClass, cardMediaClass, classes, rootPart } from "@xds/core";
25
+ import {
26
+ CARD_PARTS,
27
+ cardClass,
28
+ cardMediaClass,
29
+ classes,
30
+ rootAttributes,
31
+ rootPart,
32
+ } from "@xds/core";
26
33
 
27
34
  let {
28
35
  title,
@@ -35,6 +42,7 @@
35
42
  class: className,
36
43
  style,
37
44
  children,
45
+ ...rest
38
46
  }: CardProps = $props();
39
47
 
40
48
  const pressable = $derived(onPress !== undefined);
@@ -84,6 +92,7 @@
84
92
 
85
93
  {#if pressable}
86
94
  <button
95
+ {...rootAttributes(rest)}
87
96
  type="button"
88
97
  onclick={() => onPress?.()}
89
98
  aria-pressed={selected === undefined ? undefined : selected ? "true" : "false"}
@@ -93,7 +102,12 @@
93
102
  {@render content()}
94
103
  </button>
95
104
  {:else}
96
- <section aria-current={selected ? "true" : undefined} class={surface} {style}>
105
+ <section
106
+ {...rootAttributes(rest)}
107
+ aria-current={selected ? "true" : undefined}
108
+ class={surface}
109
+ {style}
110
+ >
97
111
  {@render content()}
98
112
  </section>
99
113
  {/if}
@@ -1,15 +1,21 @@
1
1
  <!--
2
2
  @component
3
3
  A choice that is applied later, with the form it belongs to. A native checkbox: the input is
4
- hidden and the box is drawn beside it.
4
+ hidden and the box is drawn beside it. Without `checked` it keeps its own state, from
5
+ `defaultChecked`, and a reset of its form puts that back.
6
+
7
+ `focus()`, `blur()` and `element()` on the instance reach the native checkbox.
5
8
  -->
6
9
  <script module lang="ts">
7
10
  import type { CheckboxBaseProps } from "@xds/core";
11
+ import type { FocusEventHandler } from "svelte/elements";
8
12
  import type { RootProps } from "./root.js";
9
13
 
10
14
  export type CheckboxProps = CheckboxBaseProps &
11
15
  RootProps & {
12
- onChange: (checked: boolean) => void;
16
+ onChange?: (checked: boolean) => void;
17
+ onFocus?: FocusEventHandler<HTMLInputElement>;
18
+ onBlur?: FocusEventHandler<HTMLInputElement>;
13
19
  };
14
20
  </script>
15
21
 
@@ -21,35 +27,73 @@
21
27
  checkboxLabelClass,
22
28
  checkboxMarkClass,
23
29
  classes,
30
+ rootAttributes,
24
31
  rootPart,
25
32
  } from "@xds/core";
33
+ import { controllable, followFormReset } from "./controllable.svelte.js";
26
34
  import { keepChecked } from "./controlled.js";
27
35
 
36
+ // `checked` stays in the rest, where whether it is given at all can be asked.
28
37
  let {
29
- checked,
38
+ defaultChecked = false,
30
39
  label,
31
40
  "aria-label": ariaLabel,
32
41
  name,
33
42
  disabled,
34
43
  onChange,
44
+ onFocus,
45
+ onBlur,
35
46
  class: className,
36
47
  style,
48
+ ...rest
37
49
  }: CheckboxProps = $props();
50
+
51
+ const control = controllable(
52
+ () => rest,
53
+ "checked",
54
+ () => rest.checked ?? false,
55
+ () => defaultChecked,
56
+ () => onChange,
57
+ );
58
+ let input = $state<HTMLInputElement>();
59
+ followFormReset(() => input, control);
60
+
61
+ /** Moves the focus to the native checkbox. */
62
+ export function focus(options?: FocusOptions) {
63
+ input?.focus(options);
64
+ }
65
+
66
+ /** Takes the focus from the native checkbox. */
67
+ export function blur() {
68
+ input?.blur();
69
+ }
70
+
71
+ /** The native checkbox, once it is on the page. */
72
+ export function element(): HTMLInputElement | undefined {
73
+ return input;
74
+ }
38
75
  </script>
39
76
 
40
- <label class={classes(rootPart("Checkbox"), checkboxClass, className)} {style}>
77
+ <label
78
+ {...rootAttributes(rest)}
79
+ class={classes(rootPart("Checkbox"), checkboxClass, className)}
80
+ {style}
81
+ >
41
82
  <input
83
+ bind:this={input}
42
84
  type="checkbox"
43
85
  aria-label={ariaLabel}
44
86
  class="peer sr-only"
45
- {checked}
46
- defaultChecked={checked}
87
+ checked={control.current}
88
+ defaultChecked={control.controlled ? control.current : defaultChecked}
47
89
  {disabled}
48
90
  name={name || undefined}
49
91
  onchange={(event) => {
50
- onChange(event.currentTarget.checked);
51
- keepChecked(event.currentTarget, () => checked);
92
+ control.set(event.currentTarget.checked);
93
+ keepChecked(event.currentTarget, () => control.current);
52
94
  }}
95
+ onfocus={onFocus}
96
+ onblur={onBlur}
53
97
  />
54
98
  <span class={checkboxBoxClass}>
55
99
  <svg viewBox="0 0 16 16" fill="none" aria-hidden="true" class={checkboxMarkClass}>
@@ -1,12 +1,22 @@
1
1
  import type { CheckboxBaseProps } from "@xds/core";
2
+ import type { FocusEventHandler } from "svelte/elements";
2
3
  import type { RootProps } from "./root.js";
3
4
  export type CheckboxProps = CheckboxBaseProps & RootProps & {
4
- onChange: (checked: boolean) => void;
5
+ onChange?: (checked: boolean) => void;
6
+ onFocus?: FocusEventHandler<HTMLInputElement>;
7
+ onBlur?: FocusEventHandler<HTMLInputElement>;
5
8
  };
6
9
  /**
7
10
  * A choice that is applied later, with the form it belongs to. A native checkbox: the input is
8
- * hidden and the box is drawn beside it.
11
+ * hidden and the box is drawn beside it. Without `checked` it keeps its own state, from
12
+ * `defaultChecked`, and a reset of its form puts that back.
13
+ *
14
+ * `focus()`, `blur()` and `element()` on the instance reach the native checkbox.
9
15
  */
10
- declare const Checkbox: import("svelte").Component<CheckboxProps, {}, "">;
16
+ declare const Checkbox: import("svelte").Component<CheckboxProps, {
17
+ focus: (options?: FocusOptions) => void;
18
+ blur: () => void;
19
+ element: () => HTMLInputElement | undefined;
20
+ }, "">;
11
21
  type Checkbox = ReturnType<typeof Checkbox>;
12
22
  export default Checkbox;
package/dist/Chip.svelte CHANGED
@@ -16,7 +16,7 @@
16
16
  </script>
17
17
 
18
18
  <script lang="ts">
19
- import { chipClass, chipIcon, classes, rootPart } from "@xds/core";
19
+ import { chipClass, chipIcon, classes, rootAttributes, rootPart } from "@xds/core";
20
20
  import Icon from "./Icon.svelte";
21
21
 
22
22
  let {
@@ -27,12 +27,14 @@
27
27
  onPress,
28
28
  class: className,
29
29
  style,
30
+ ...rest
30
31
  }: ChipProps = $props();
31
32
 
32
33
  const icon = $derived(chipIcon({ selected, iconStart }));
33
34
  </script>
34
35
 
35
36
  <button
37
+ {...rootAttributes(rest)}
36
38
  type="button"
37
39
  aria-pressed={selected ? "true" : "false"}
38
40
  {disabled}
@@ -16,13 +16,14 @@
16
16
  </script>
17
17
 
18
18
  <script lang="ts">
19
- import { chipBarClass, classes, rootPart } from "@xds/core";
19
+ import { chipBarClass, classes, rootAttributes, rootPart } from "@xds/core";
20
20
 
21
- let { label, class: className, style, children }: ChipBarProps = $props();
21
+ let { label, class: className, style, children, ...rest }: ChipBarProps = $props();
22
22
  </script>
23
23
 
24
24
  <!-- A group, not a fieldset: a fieldset cannot be a scrolling flex row in every browser. -->
25
25
  <div
26
+ {...rootAttributes(rest)}
26
27
  role="group"
27
28
  aria-label={label}
28
29
  class={classes(rootPart("ChipBar"), chipBarClass, className)}
@@ -21,10 +21,11 @@
21
21
  countBadgeAnchorClass,
22
22
  countBadgeClass,
23
23
  countBadgeText,
24
+ rootAttributes,
24
25
  rootPart,
25
26
  } from "@xds/core";
26
27
 
27
- let { count, max, label, class: className, style, children }: CountBadgeProps = $props();
28
+ let { count, max, label, class: className, style, children, ...rest }: CountBadgeProps = $props();
28
29
 
29
30
  // The root is the anchor around the child, or the badge itself when there is none.
30
31
  const root = $derived(classes(rootPart("CountBadge"), className));
@@ -33,6 +34,7 @@
33
34
  {#snippet badge(onChild: boolean)}
34
35
  {#if count > 0}
35
36
  <span
37
+ {...onChild ? {} : rootAttributes(rest)}
36
38
  role={label ? "img" : undefined}
37
39
  aria-label={label || undefined}
38
40
  class={classes(countBadgeClass(onChild), !onChild && root)}
@@ -42,7 +44,7 @@
42
44
  {/snippet}
43
45
 
44
46
  {#if children}
45
- <span class={classes(countBadgeAnchorClass, root)} {style}
47
+ <span {...rootAttributes(rest)} class={classes(countBadgeAnchorClass, root)} {style}
46
48
  >{@render children()}{@render badge(true)}</span
47
49
  >
48
50
  {:else}
@@ -39,12 +39,14 @@
39
39
  keepCalendarFocus,
40
40
  keepDayFocused,
41
41
  readCssPx,
42
+ rootAttributes,
42
43
  underlayLayerStyle,
43
44
  } from "@xds/core";
44
45
  import * as datePicker from "@zag-js/date-picker";
45
46
  import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
46
47
  import { untrack } from "svelte";
47
48
  import Icon from "./Icon.svelte";
49
+ import { useLabels } from "./labels.svelte.js";
48
50
  import { modalPopover } from "./modal-popover.svelte.js";
49
51
  import Portal from "./Portal.svelte";
50
52
  import { createPresence } from "./presence.svelte.js";
@@ -55,12 +57,14 @@
55
57
  const id = $props.id();
56
58
  const ids = datePickerIds(id);
57
59
  const locale = $derived(datePickerLocale(props.locale));
60
+ const labels = useLabels();
58
61
  const service = useMachine(datePicker.machine, () =>
59
62
  datePickerMachineProps(props, {
60
63
  id,
61
64
  locale,
62
65
  onChange,
63
66
  gutter: readCssPx(null, "--xds-space-1", space[1]),
67
+ labels: labels(),
64
68
  }),
65
69
  );
66
70
  const api = $derived(datePicker.connect(service, normalizeProps));
@@ -89,7 +93,13 @@
89
93
  </script>
90
94
 
91
95
  <!-- Merged, so that the app's style joins any the machine writes on the root. -->
92
- <div {...mergeProps(api.getRootProps(), { class: classes("xds-date-picker", className), style })}>
96
+ <div
97
+ {...mergeProps(api.getRootProps(), {
98
+ ...rootAttributes(props),
99
+ class: classes("xds-date-picker", className),
100
+ style,
101
+ })}
102
+ >
93
103
  <!-- A span: the field is a button, which a <label> cannot point at. -->
94
104
  <span id={ids.label} class="xds-date-picker__label">{props.label}</span>
95
105
  <!-- What Zag places the calendar against. -->
@@ -50,6 +50,7 @@
50
50
  rangeMonthViews,
51
51
  rangeSummary,
52
52
  readCssPx,
53
+ rootAttributes,
53
54
  shownRange,
54
55
  underlayLayerStyle,
55
56
  } from "@xds/core";
@@ -57,6 +58,7 @@
57
58
  import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
58
59
  import { untrack } from "svelte";
59
60
  import Icon from "./Icon.svelte";
61
+ import { useLabels } from "./labels.svelte.js";
60
62
  import { modalPopover } from "./modal-popover.svelte.js";
61
63
  import Portal from "./Portal.svelte";
62
64
  import { createPresence } from "./presence.svelte.js";
@@ -67,6 +69,7 @@
67
69
  const id = $props.id();
68
70
  const ids = datePickerIds(id);
69
71
  const locale = $derived(datePickerLocale(props.locale));
72
+ const labels = useLabels();
70
73
  // A start alone while the end is chosen; null while the calendar shows the chosen range.
71
74
  let draft = $state.raw<RangeDraft | null>(null);
72
75
  let months = $state(1);
@@ -79,12 +82,13 @@
79
82
  onDraft: (next) => (draft = next),
80
83
  onChange,
81
84
  gutter: readCssPx(null, "--xds-space-1", space[1]),
85
+ labels: labels(),
82
86
  }),
83
87
  );
84
88
  const api = $derived(datePicker.connect(service, normalizeProps));
85
89
  const trigger = $derived(api.getTriggerProps());
86
90
  const invalid = $derived(props.error !== undefined);
87
- const summary = $derived(rangeSummary(shown, props, locale));
91
+ const summary = $derived(rangeSummary(shown, props, locale, labels()));
88
92
  const views = $derived(rangeMonthViews(api, months));
89
93
  let positioner = $state<HTMLDivElement>();
90
94
  let surface = $state<HTMLDivElement>();
@@ -120,6 +124,7 @@
120
124
  <!-- Merged, so that the app's style joins any the machine writes on the root. -->
121
125
  <div
122
126
  {...mergeProps(api.getRootProps(), {
127
+ ...rootAttributes(props),
123
128
  class: classes("xds-date-picker xds-date-range-picker", className),
124
129
  style,
125
130
  })}
@@ -24,7 +24,7 @@
24
24
  </script>
25
25
 
26
26
  <script lang="ts">
27
- import { classes, leaveEscapeToFields } from "@xds/core";
27
+ import { classes, leaveEscapeToFields, rootAttributes } from "@xds/core";
28
28
  import * as dialog from "@zag-js/dialog";
29
29
  import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
30
30
  import Portal from "./Portal.svelte";
@@ -41,6 +41,7 @@
41
41
  style,
42
42
  children,
43
43
  actions,
44
+ ...rest
44
45
  }: DialogProps = $props();
45
46
 
46
47
  const id = $props.id();
@@ -49,6 +50,8 @@
49
50
  let content = $state<HTMLElement>();
50
51
  const service = useMachine(dialog.machine, () => ({
51
52
  id,
53
+ // The app's id names the dialog, and what Zag points at it points there.
54
+ ids: rest.id === undefined ? undefined : { content: rest.id },
52
55
  open,
53
56
  onOpenChange: (details: dialog.OpenChangeDetails) => {
54
57
  if (!details.open) onClose();
@@ -84,7 +87,11 @@
84
87
  ></div>
85
88
  <div {...api.getPositionerProps()} bind:this={positioner} class="xds-dialog__positioner">
86
89
  <section
87
- {...mergeProps(api.getContentProps(), { class: classes("xds-dialog", className), style })}
90
+ {...mergeProps(api.getContentProps(), {
91
+ ...rootAttributes(rest),
92
+ class: classes("xds-dialog", className),
93
+ style,
94
+ })}
88
95
  bind:this={content}
89
96
  hidden={false}
90
97
  >
@@ -9,9 +9,13 @@
9
9
  </script>
10
10
 
11
11
  <script lang="ts">
12
- import { classes, dividerClass, rootPart } from "@xds/core";
12
+ import { classes, dividerClass, rootAttributes, rootPart } from "@xds/core";
13
13
 
14
- let { class: className, style }: DividerProps = $props();
14
+ let { class: className, style, ...rest }: DividerProps = $props();
15
15
  </script>
16
16
 
17
- <hr class={classes(rootPart("Divider"), dividerClass, className)} {style} />
17
+ <hr
18
+ {...rootAttributes(rest)}
19
+ class={classes(rootPart("Divider"), dividerClass, className)}
20
+ {style}
21
+ />