@xds/svelte 0.0.0-stage → 0.2.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 (122) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -2
  3. package/dist/Accordion.svelte +89 -0
  4. package/dist/Accordion.svelte.d.ts +43 -0
  5. package/dist/AccordionPanel.svelte +40 -0
  6. package/dist/AccordionPanel.svelte.d.ts +15 -0
  7. package/dist/Avatar.svelte +45 -0
  8. package/dist/Avatar.svelte.d.ts +11 -0
  9. package/dist/AvatarStack.svelte +49 -0
  10. package/dist/AvatarStack.svelte.d.ts +10 -0
  11. package/dist/Badge.svelte +36 -0
  12. package/dist/Badge.svelte.d.ts +15 -0
  13. package/dist/Banner.svelte +88 -0
  14. package/dist/Banner.svelte.d.ts +25 -0
  15. package/dist/Button.svelte +90 -0
  16. package/dist/Button.svelte.d.ts +16 -0
  17. package/dist/Card.svelte +99 -0
  18. package/dist/Card.svelte.d.ts +20 -0
  19. package/dist/Checkbox.svelte +68 -0
  20. package/dist/Checkbox.svelte.d.ts +12 -0
  21. package/dist/Chip.svelte +43 -0
  22. package/dist/Chip.svelte.d.ts +14 -0
  23. package/dist/ChipBar.svelte +32 -0
  24. package/dist/ChipBar.svelte.d.ts +14 -0
  25. package/dist/CountBadge.svelte +50 -0
  26. package/dist/CountBadge.svelte.d.ts +14 -0
  27. package/dist/DatePicker.svelte +178 -0
  28. package/dist/DatePicker.svelte.d.ts +22 -0
  29. package/dist/DateRangePicker.svelte +264 -0
  30. package/dist/DateRangePicker.svelte.d.ts +25 -0
  31. package/dist/Defaults.svelte +29 -0
  32. package/dist/Defaults.svelte.d.ts +17 -0
  33. package/dist/Dialog.svelte +104 -0
  34. package/dist/Dialog.svelte.d.ts +22 -0
  35. package/dist/Divider.svelte +17 -0
  36. package/dist/Divider.svelte.d.ts +6 -0
  37. package/dist/EmptyState.svelte +34 -0
  38. package/dist/EmptyState.svelte.d.ts +14 -0
  39. package/dist/Icon.svelte +38 -0
  40. package/dist/Icon.svelte.d.ts +10 -0
  41. package/dist/IconButton.svelte +67 -0
  42. package/dist/IconButton.svelte.d.ts +13 -0
  43. package/dist/ListRow.svelte +29 -0
  44. package/dist/ListRow.svelte.d.ts +15 -0
  45. package/dist/MediaCard.svelte +112 -0
  46. package/dist/MediaCard.svelte.d.ts +22 -0
  47. package/dist/Menu.svelte +156 -0
  48. package/dist/Menu.svelte.d.ts +19 -0
  49. package/dist/PlaceRow.svelte +66 -0
  50. package/dist/PlaceRow.svelte.d.ts +12 -0
  51. package/dist/Portal.svelte +27 -0
  52. package/dist/Portal.svelte.d.ts +15 -0
  53. package/dist/ProgressBar.svelte +37 -0
  54. package/dist/ProgressBar.svelte.d.ts +10 -0
  55. package/dist/RadioGroup.svelte +114 -0
  56. package/dist/RadioGroup.svelte.d.ts +38 -0
  57. package/dist/SearchField.svelte +93 -0
  58. package/dist/SearchField.svelte.d.ts +17 -0
  59. package/dist/SectionHeader.svelte +56 -0
  60. package/dist/SectionHeader.svelte.d.ts +16 -0
  61. package/dist/SegmentedControl.svelte +70 -0
  62. package/dist/SegmentedControl.svelte.d.ts +35 -0
  63. package/dist/Select.svelte +214 -0
  64. package/dist/Select.svelte.d.ts +40 -0
  65. package/dist/Sidebar.svelte +125 -0
  66. package/dist/Sidebar.svelte.d.ts +43 -0
  67. package/dist/SidebarRailButton.svelte +29 -0
  68. package/dist/SidebarRailButton.svelte.d.ts +14 -0
  69. package/dist/Skeleton.svelte +34 -0
  70. package/dist/Skeleton.svelte.d.ts +13 -0
  71. package/dist/Slider.svelte +111 -0
  72. package/dist/Slider.svelte.d.ts +15 -0
  73. package/dist/Spinner.svelte +35 -0
  74. package/dist/Spinner.svelte.d.ts +11 -0
  75. package/dist/Switch.svelte +60 -0
  76. package/dist/Switch.svelte.d.ts +15 -0
  77. package/dist/Tabs.svelte +65 -0
  78. package/dist/Tabs.svelte.d.ts +36 -0
  79. package/dist/Text.svelte +36 -0
  80. package/dist/Text.svelte.d.ts +11 -0
  81. package/dist/TextField.svelte +163 -0
  82. package/dist/TextField.svelte.d.ts +23 -0
  83. package/dist/Thumbnail.svelte +81 -0
  84. package/dist/Thumbnail.svelte.d.ts +11 -0
  85. package/dist/Toast.svelte +83 -0
  86. package/dist/Toast.svelte.d.ts +17 -0
  87. package/dist/Tooltip.svelte +40 -0
  88. package/dist/Tooltip.svelte.d.ts +19 -0
  89. package/dist/TooltipOverlay.svelte +66 -0
  90. package/dist/TooltipOverlay.svelte.d.ts +17 -0
  91. package/dist/controlled.d.ts +4 -0
  92. package/dist/controlled.js +23 -0
  93. package/dist/defaults.svelte.d.ts +12 -0
  94. package/dist/defaults.svelte.js +25 -0
  95. package/dist/index.d.ts +41 -0
  96. package/dist/index.js +47 -0
  97. package/dist/modal-popover.svelte.d.ts +8 -0
  98. package/dist/modal-popover.svelte.js +22 -0
  99. package/dist/picture.svelte.d.ts +19 -0
  100. package/dist/picture.svelte.js +18 -0
  101. package/dist/presence.svelte.d.ts +6 -0
  102. package/dist/presence.svelte.js +19 -0
  103. package/dist/preview/Component.svelte +56 -0
  104. package/dist/preview/Component.svelte.d.ts +15 -0
  105. package/dist/preview/Draw.svelte +65 -0
  106. package/dist/preview/Draw.svelte.d.ts +15 -0
  107. package/dist/preview/Preview.svelte +41 -0
  108. package/dist/preview/Preview.svelte.d.ts +13 -0
  109. package/dist/preview/Snippets.svelte +36 -0
  110. package/dist/preview/Snippets.svelte.d.ts +19 -0
  111. package/dist/preview/components.js +48 -0
  112. package/dist/preview/index.d.ts +2 -0
  113. package/dist/preview/index.js +4 -0
  114. package/dist/root.d.ts +11 -0
  115. package/dist/root.js +1 -0
  116. package/dist/styles/index.css +5 -0
  117. package/dist/trigger.svelte.d.ts +21 -0
  118. package/dist/trigger.svelte.js +48 -0
  119. package/package.json +62 -4
  120. package/page.css +20 -0
  121. package/styles.css +3354 -0
  122. package/tailwind.css +2665 -0
@@ -0,0 +1,99 @@
1
+ <!--
2
+ @component
3
+ A surface that groups related content. A hairline outline and a trace of shadow lift it off the
4
+ page; in dark mode, where shadows barely show, the lighter fill does that. `title` renders as a
5
+ heading; `actions` sit across from it.
6
+ -->
7
+ <script module lang="ts">
8
+ import type { CardBaseProps } from "@xds/core";
9
+ import type { Snippet } from "svelte";
10
+ import type { RootProps } from "./root.js";
11
+
12
+ export type CardProps = CardBaseProps &
13
+ RootProps & {
14
+ /** Sit across from the title. A pressable card takes none: it is one button already. */
15
+ actions?: Snippet;
16
+ /** A picture or a drawing at the top, running edge to edge above the padding. */
17
+ media?: Snippet;
18
+ /** Makes the whole card one button. Put no other control inside it then. */
19
+ onPress?: () => void;
20
+ children?: Snippet;
21
+ };
22
+ </script>
23
+
24
+ <script lang="ts">
25
+ import { CARD_PARTS, cardClass, cardMediaClass, classes, rootPart } from "@xds/core";
26
+
27
+ let {
28
+ title,
29
+ description,
30
+ flush,
31
+ selected,
32
+ actions,
33
+ media,
34
+ onPress,
35
+ class: className,
36
+ style,
37
+ children,
38
+ }: CardProps = $props();
39
+
40
+ const pressable = $derived(onPress !== undefined);
41
+ // A button may hold only phrasing content, so inside one the parts are spans. Its heading
42
+ // would not be reachable as a heading anyway: a button reads as its text.
43
+ const tags = $derived(
44
+ pressable
45
+ ? { header: "span", box: "span", title: "span", line: "span" }
46
+ : { header: "header", box: "div", title: "h2", line: "p" },
47
+ );
48
+ const surface = $derived(
49
+ classes(rootPart("Card"), cardClass({ selected, flush, pressable }), className),
50
+ );
51
+ </script>
52
+
53
+ {#snippet parts()}
54
+ {#if media}
55
+ <svelte:element this={tags.box} class={cardMediaClass(flush)}>{@render media()}</svelte:element>
56
+ {/if}
57
+ {#if title || (actions && !pressable)}
58
+ <svelte:element this={tags.header} class={CARD_PARTS.header}>
59
+ <svelte:element this={tags.box} class={CARD_PARTS.heading}>
60
+ {#if title}
61
+ <svelte:element this={tags.title} class={CARD_PARTS.title}>{title}</svelte:element>
62
+ {/if}
63
+ {#if description}
64
+ <svelte:element this={tags.line} class={CARD_PARTS.description}
65
+ >{description}</svelte:element
66
+ >
67
+ {/if}
68
+ </svelte:element>
69
+ {#if actions && !pressable}
70
+ <div class={CARD_PARTS.actions}>{@render actions()}</div>
71
+ {/if}
72
+ </svelte:element>
73
+ {/if}
74
+ {@render children?.()}
75
+ {/snippet}
76
+
77
+ {#snippet content()}
78
+ {#if flush}
79
+ <svelte:element this={tags.box} class={CARD_PARTS.flush}>{@render parts()}</svelte:element>
80
+ {:else}
81
+ {@render parts()}
82
+ {/if}
83
+ {/snippet}
84
+
85
+ {#if pressable}
86
+ <button
87
+ type="button"
88
+ onclick={() => onPress?.()}
89
+ aria-pressed={selected === undefined ? undefined : selected ? "true" : "false"}
90
+ class={surface}
91
+ {style}
92
+ >
93
+ {@render content()}
94
+ </button>
95
+ {:else}
96
+ <section aria-current={selected ? "true" : undefined} class={surface} {style}>
97
+ {@render content()}
98
+ </section>
99
+ {/if}
@@ -0,0 +1,20 @@
1
+ import type { CardBaseProps } from "@xds/core";
2
+ import type { Snippet } from "svelte";
3
+ import type { RootProps } from "./root.js";
4
+ export type CardProps = CardBaseProps & RootProps & {
5
+ /** Sit across from the title. A pressable card takes none: it is one button already. */
6
+ actions?: Snippet;
7
+ /** A picture or a drawing at the top, running edge to edge above the padding. */
8
+ media?: Snippet;
9
+ /** Makes the whole card one button. Put no other control inside it then. */
10
+ onPress?: () => void;
11
+ children?: Snippet;
12
+ };
13
+ /**
14
+ * A surface that groups related content. A hairline outline and a trace of shadow lift it off the
15
+ * page; in dark mode, where shadows barely show, the lighter fill does that. `title` renders as a
16
+ * heading; `actions` sit across from it.
17
+ */
18
+ declare const Card: import("svelte").Component<CardProps, {}, "">;
19
+ type Card = ReturnType<typeof Card>;
20
+ export default Card;
@@ -0,0 +1,68 @@
1
+ <!--
2
+ @component
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.
5
+ -->
6
+ <script module lang="ts">
7
+ import type { CheckboxBaseProps } from "@xds/core";
8
+ import type { RootProps } from "./root.js";
9
+
10
+ export type CheckboxProps = CheckboxBaseProps &
11
+ RootProps & {
12
+ onChange: (checked: boolean) => void;
13
+ };
14
+ </script>
15
+
16
+ <script lang="ts">
17
+ import {
18
+ CHECKBOX_MARK,
19
+ checkboxBoxClass,
20
+ checkboxClass,
21
+ checkboxLabelClass,
22
+ checkboxMarkClass,
23
+ classes,
24
+ rootPart,
25
+ } from "@xds/core";
26
+ import { keepChecked } from "./controlled.js";
27
+
28
+ let {
29
+ checked,
30
+ label,
31
+ "aria-label": ariaLabel,
32
+ name,
33
+ disabled,
34
+ onChange,
35
+ class: className,
36
+ style,
37
+ }: CheckboxProps = $props();
38
+ </script>
39
+
40
+ <label class={classes(rootPart("Checkbox"), checkboxClass, className)} {style}>
41
+ <input
42
+ type="checkbox"
43
+ aria-label={ariaLabel}
44
+ class="peer sr-only"
45
+ {checked}
46
+ defaultChecked={checked}
47
+ {disabled}
48
+ name={name || undefined}
49
+ onchange={(event) => {
50
+ onChange(event.currentTarget.checked);
51
+ keepChecked(event.currentTarget, () => checked);
52
+ }}
53
+ />
54
+ <span class={checkboxBoxClass}>
55
+ <svg viewBox="0 0 16 16" fill="none" aria-hidden="true" class={checkboxMarkClass}>
56
+ <path
57
+ d={CHECKBOX_MARK}
58
+ stroke="currentColor"
59
+ stroke-width="2"
60
+ stroke-linecap="round"
61
+ stroke-linejoin="round"
62
+ />
63
+ </svg>
64
+ </span>
65
+ {#if label}
66
+ <span class={checkboxLabelClass}>{label}</span>
67
+ {/if}
68
+ </label>
@@ -0,0 +1,12 @@
1
+ import type { CheckboxBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.js";
3
+ export type CheckboxProps = CheckboxBaseProps & RootProps & {
4
+ onChange: (checked: boolean) => void;
5
+ };
6
+ /**
7
+ * 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.
9
+ */
10
+ declare const Checkbox: import("svelte").Component<CheckboxProps, {}, "">;
11
+ type Checkbox = ReturnType<typeof Checkbox>;
12
+ export default Checkbox;
@@ -0,0 +1,43 @@
1
+ <!--
2
+ @component
3
+ A choice that filters what is shown. Unlike a Badge it is pressed. A selected chip is tinted,
4
+ outlined and marked with a check, so the state does not depend on color.
5
+
6
+ It is a toggle button: assistive technology hears whether it is pressed.
7
+ -->
8
+ <script module lang="ts">
9
+ import type { ChipBaseProps } from "@xds/core";
10
+ import type { RootProps } from "./root.js";
11
+
12
+ export type ChipProps = ChipBaseProps &
13
+ RootProps & {
14
+ onPress?: () => void;
15
+ };
16
+ </script>
17
+
18
+ <script lang="ts">
19
+ import { chipClass, chipIcon, classes, rootPart } from "@xds/core";
20
+ import Icon from "./Icon.svelte";
21
+
22
+ let {
23
+ label,
24
+ selected,
25
+ iconStart,
26
+ disabled,
27
+ onPress,
28
+ class: className,
29
+ style,
30
+ }: ChipProps = $props();
31
+
32
+ const icon = $derived(chipIcon({ selected, iconStart }));
33
+ </script>
34
+
35
+ <button
36
+ type="button"
37
+ aria-pressed={selected ? "true" : "false"}
38
+ {disabled}
39
+ onclick={() => onPress?.()}
40
+ class={classes(rootPart("Chip"), chipClass(selected), className)}
41
+ {style}
42
+ >{#if icon}<Icon name={icon} size="sm" />{/if}{label}</button
43
+ >
@@ -0,0 +1,14 @@
1
+ import type { ChipBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.js";
3
+ export type ChipProps = ChipBaseProps & RootProps & {
4
+ onPress?: () => void;
5
+ };
6
+ /**
7
+ * A choice that filters what is shown. Unlike a Badge it is pressed. A selected chip is tinted,
8
+ * outlined and marked with a check, so the state does not depend on color.
9
+ *
10
+ * It is a toggle button: assistive technology hears whether it is pressed.
11
+ */
12
+ declare const Chip: import("svelte").Component<ChipProps, {}, "">;
13
+ type Chip = ReturnType<typeof Chip>;
14
+ export default Chip;
@@ -0,0 +1,32 @@
1
+ <!--
2
+ @component
3
+ One row of chips. It scrolls sideways when the chips do not fit and never wraps, so the content
4
+ under it stays where it is.
5
+ -->
6
+ <script module lang="ts">
7
+ import type { ChipBarBaseProps } from "@xds/core";
8
+ import type { Snippet } from "svelte";
9
+ import type { RootProps } from "./root.js";
10
+
11
+ export type ChipBarProps = ChipBarBaseProps &
12
+ RootProps & {
13
+ /** The chips. Which of them are selected is the app's business: the bar holds no state. */
14
+ children: Snippet;
15
+ };
16
+ </script>
17
+
18
+ <script lang="ts">
19
+ import { chipBarClass, classes, rootPart } from "@xds/core";
20
+
21
+ let { label, class: className, style, children }: ChipBarProps = $props();
22
+ </script>
23
+
24
+ <!-- A group, not a fieldset: a fieldset cannot be a scrolling flex row in every browser. -->
25
+ <div
26
+ role="group"
27
+ aria-label={label}
28
+ class={classes(rootPart("ChipBar"), chipBarClass, className)}
29
+ {style}
30
+ >
31
+ {@render children()}
32
+ </div>
@@ -0,0 +1,14 @@
1
+ import type { ChipBarBaseProps } from "@xds/core";
2
+ import type { Snippet } from "svelte";
3
+ import type { RootProps } from "./root.js";
4
+ export type ChipBarProps = ChipBarBaseProps & RootProps & {
5
+ /** The chips. Which of them are selected is the app's business: the bar holds no state. */
6
+ children: Snippet;
7
+ };
8
+ /**
9
+ * One row of chips. It scrolls sideways when the chips do not fit and never wraps, so the content
10
+ * under it stays where it is.
11
+ */
12
+ declare const ChipBar: import("svelte").Component<ChipBarProps, {}, "">;
13
+ type ChipBar = ReturnType<typeof ChipBar>;
14
+ export default ChipBar;
@@ -0,0 +1,50 @@
1
+ <!--
2
+ @component
3
+ A count of something waiting: unread messages, items in a cart. On its own it is laid out
4
+ inline; around a child it sits on the child's top end corner.
5
+ -->
6
+ <script module lang="ts">
7
+ import type { CountBadgeBaseProps } from "@xds/core";
8
+ import type { Snippet } from "svelte";
9
+ import type { RootProps } from "./root.js";
10
+
11
+ export type CountBadgeProps = CountBadgeBaseProps &
12
+ RootProps & {
13
+ /** What the count belongs to: an icon, an avatar, a button. The badge sits on its corner. */
14
+ children?: Snippet;
15
+ };
16
+ </script>
17
+
18
+ <script lang="ts">
19
+ import {
20
+ classes,
21
+ countBadgeAnchorClass,
22
+ countBadgeClass,
23
+ countBadgeText,
24
+ rootPart,
25
+ } from "@xds/core";
26
+
27
+ let { count, max, label, class: className, style, children }: CountBadgeProps = $props();
28
+
29
+ // The root is the anchor around the child, or the badge itself when there is none.
30
+ const root = $derived(classes(rootPart("CountBadge"), className));
31
+ </script>
32
+
33
+ {#snippet badge(onChild: boolean)}
34
+ {#if count > 0}
35
+ <span
36
+ role={label ? "img" : undefined}
37
+ aria-label={label || undefined}
38
+ class={classes(countBadgeClass(onChild), !onChild && root)}
39
+ style={onChild ? undefined : style}>{countBadgeText(count, max)}</span
40
+ >
41
+ {/if}
42
+ {/snippet}
43
+
44
+ {#if children}
45
+ <span class={classes(countBadgeAnchorClass, root)} {style}
46
+ >{@render children()}{@render badge(true)}</span
47
+ >
48
+ {:else}
49
+ {@render badge(false)}
50
+ {/if}
@@ -0,0 +1,14 @@
1
+ import type { CountBadgeBaseProps } from "@xds/core";
2
+ import type { Snippet } from "svelte";
3
+ import type { RootProps } from "./root.js";
4
+ export type CountBadgeProps = CountBadgeBaseProps & RootProps & {
5
+ /** What the count belongs to: an icon, an avatar, a button. The badge sits on its corner. */
6
+ children?: Snippet;
7
+ };
8
+ /**
9
+ * A count of something waiting: unread messages, items in a cart. On its own it is laid out
10
+ * inline; around a child it sits on the child's top end corner.
11
+ */
12
+ declare const CountBadge: import("svelte").Component<CountBadgeProps, {}, "">;
13
+ type CountBadge = ReturnType<typeof CountBadge>;
14
+ export default CountBadge;
@@ -0,0 +1,178 @@
1
+ <!--
2
+ @component
3
+ A field for choosing one day. Closed, it looks like a Select: the chosen day in the locale's
4
+ medium form, or the placeholder. Pressed, it opens a calendar of one month under itself, on the
5
+ chosen day, or on today while none is. A press on a day, or Enter on the focused one, calls
6
+ `onChange` with the day as `YYYY-MM-DD` and closes the calendar; Escape or a press outside
7
+ closes it without a choice.
8
+
9
+ The field is a button that says it opens a dialog and whether it is open. In the calendar the
10
+ arrow keys move a day or a week, Page Up and Page Down a month (a year with Shift), and Home and
11
+ End to the first and the last day of the month, never past `min` or `max`. Tab goes round the
12
+ month buttons and the focused day. The chosen day is selected for assistive technology, and
13
+ today is the current date.
14
+ -->
15
+ <script module lang="ts">
16
+ import type { DatePickerBaseProps, IsoDate } from "@xds/core";
17
+ import type { RootProps } from "./root.js";
18
+
19
+ export type { IsoDate } from "@xds/core";
20
+
21
+ export type DatePickerProps = DatePickerBaseProps &
22
+ RootProps & {
23
+ onChange: (value: IsoDate) => void;
24
+ };
25
+ </script>
26
+
27
+ <script lang="ts">
28
+ import {
29
+ classes,
30
+ DATE_PICKER_NAV_CLASS,
31
+ datePickerContentAttrs,
32
+ datePickerIds,
33
+ datePickerLocale,
34
+ datePickerMachineProps,
35
+ datePickerTriggerAttrs,
36
+ focusOpeningDay,
37
+ formatDay,
38
+ keepCalendarFocus,
39
+ keepDayFocused,
40
+ } from "@xds/core";
41
+ import * as datePicker from "@zag-js/date-picker";
42
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
43
+ import { untrack } from "svelte";
44
+ import Icon from "./Icon.svelte";
45
+ import { modalPopover } from "./modal-popover.svelte.js";
46
+ import Portal from "./Portal.svelte";
47
+ import { createPresence } from "./presence.svelte.js";
48
+
49
+ // The rest stays reactive: the machine's props read it each time it changes.
50
+ let { onChange, class: className, style, ...props }: DatePickerProps = $props();
51
+
52
+ const id = $props.id();
53
+ const ids = datePickerIds(id);
54
+ const locale = datePickerLocale();
55
+ const service = useMachine(datePicker.machine, () =>
56
+ datePickerMachineProps(props, { id, locale, onChange }),
57
+ );
58
+ const api = $derived(datePicker.connect(service, normalizeProps));
59
+ const trigger = $derived(api.getTriggerProps());
60
+ const invalid = $derived(props.error !== undefined);
61
+ let positioner = $state<HTMLDivElement>();
62
+ let surface = $state<HTMLDivElement>();
63
+ modalPopover(
64
+ () => api.open,
65
+ () => positioner,
66
+ );
67
+ const present = createPresence(
68
+ () => api.open,
69
+ () => [surface],
70
+ );
71
+ // Strings, so that the effect below runs only when the focused day or the month changes, not
72
+ // on every change of the machine.
73
+ const focused = $derived(api.focusedValue.toString());
74
+ const month = $derived(api.visibleRange.start.toString());
75
+ $effect(() => {
76
+ const open = api.open;
77
+ void focused;
78
+ void month;
79
+ untrack(() => keepDayFocused(open, surface));
80
+ });
81
+ </script>
82
+
83
+ <!-- Merged, so that the app's style joins any the machine writes on the root. -->
84
+ <div {...mergeProps(api.getRootProps(), { class: classes("xds-date-picker", className), style })}>
85
+ <!-- A span: the field is a button, which a <label> cannot point at. -->
86
+ <span id={ids.label} class="xds-date-picker__label">{props.label}</span>
87
+ <!-- What Zag places the calendar against. -->
88
+ <div {...api.getControlProps()} class="xds-date-picker__control">
89
+ <button
90
+ {...trigger}
91
+ {...datePickerTriggerAttrs(props, ids)}
92
+ type="button"
93
+ onclick={(event) => {
94
+ focusOpeningDay(api, props);
95
+ trigger.onclick?.(event);
96
+ }}
97
+ class="xds-date-picker__trigger"
98
+ >
99
+ <span id={ids.value} class="xds-date-picker__value"
100
+ >{props.value === undefined ? props.placeholder : formatDay(props.value, locale)}</span
101
+ >
102
+ <Icon name="calendar" size="sm" class="text-xds-field-placeholder" />
103
+ </button>
104
+ </div>
105
+ <!-- One line under the box: the help, or the error in its place. -->
106
+ {#if invalid || props.description}
107
+ <div class="xds-date-picker__footer">
108
+ {#if invalid}
109
+ <span id={ids.error} class="xds-date-picker__error">{props.error}</span>
110
+ {:else}
111
+ <span id={ids.description} class="xds-date-picker__description">{props.description}</span>
112
+ {/if}
113
+ </div>
114
+ {/if}
115
+ <!-- What a form submits. Zag gives the name to its text input, which is not drawn. -->
116
+ {#if props.name !== undefined}
117
+ <input type="hidden" name={props.name} value={props.value ?? ""} />
118
+ {/if}
119
+ <Portal>
120
+ {#if api.open}
121
+ <!-- Takes a press outside, which then only closes the calendar. The focus stays in the
122
+ calendar until it hands it back to the field. -->
123
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
124
+ <div class="xds-date-picker__underlay" onmousedown={(event) => event.preventDefault()}></div>
125
+ {/if}
126
+ <div {...api.getPositionerProps()} bind:this={positioner} class="xds-date-picker__positioner">
127
+ <!-- Shown until its exit animation ends; Zag would hide it as it closes. -->
128
+ <div
129
+ {...api.getContentProps()}
130
+ {...datePickerContentAttrs(ids)}
131
+ bind:this={surface}
132
+ hidden={!present()}
133
+ onkeydown={(event) => keepCalendarFocus(event, surface)}
134
+ class="xds-date-picker__content"
135
+ >
136
+ <div class="xds-date-picker__header">
137
+ <button {...api.getPreviousTriggerProps()} type="button" class={DATE_PICKER_NAV_CLASS}>
138
+ <Icon name="chevron-left" size="sm" />
139
+ </button>
140
+ <span {...api.getRangeTextProps()} class="xds-date-picker__heading"
141
+ >{api.visibleRangeText.start}</span
142
+ >
143
+ <button {...api.getNextTriggerProps()} type="button" class={DATE_PICKER_NAV_CLASS}>
144
+ <Icon name="chevron-right" size="sm" />
145
+ </button>
146
+ </div>
147
+ <table {...api.getTableProps({ view: "day" })} class="xds-date-picker__grid">
148
+ <thead {...api.getTableHeadProps({ view: "day" })}>
149
+ <tr {...api.getTableRowProps({ view: "day" })}>
150
+ {#each api.weekDays as weekDay (weekDay.long)}
151
+ <th scope="col" class="xds-date-picker__weekday">{weekDay.narrow}</th>
152
+ {/each}
153
+ </tr>
154
+ </thead>
155
+ <tbody {...api.getTableBodyProps({ view: "day" })}>
156
+ <!-- Keyed by the day, not by the object: Zag hands out new dates on every change, and
157
+ a cell made anew would drop the focus it holds when a move is held at `min` or
158
+ `max`. -->
159
+ {#each api.weeks as week (week[0]?.toString())}
160
+ <tr {...api.getTableRowProps({ view: "day" })}>
161
+ {#each week as value (value.toString())}
162
+ <td {...api.getDayTableCellProps({ value })} class="xds-date-picker__cell">
163
+ <div
164
+ {...api.getDayTableCellTriggerProps({ value })}
165
+ class="xds-date-picker__day"
166
+ >
167
+ {value.day}
168
+ </div>
169
+ </td>
170
+ {/each}
171
+ </tr>
172
+ {/each}
173
+ </tbody>
174
+ </table>
175
+ </div>
176
+ </div>
177
+ </Portal>
178
+ </div>
@@ -0,0 +1,22 @@
1
+ import type { DatePickerBaseProps, IsoDate } from "@xds/core";
2
+ import type { RootProps } from "./root.js";
3
+ export type { IsoDate } from "@xds/core";
4
+ export type DatePickerProps = DatePickerBaseProps & RootProps & {
5
+ onChange: (value: IsoDate) => void;
6
+ };
7
+ /**
8
+ * A field for choosing one day. Closed, it looks like a Select: the chosen day in the locale's
9
+ * medium form, or the placeholder. Pressed, it opens a calendar of one month under itself, on the
10
+ * chosen day, or on today while none is. A press on a day, or Enter on the focused one, calls
11
+ * `onChange` with the day as `YYYY-MM-DD` and closes the calendar; Escape or a press outside
12
+ * closes it without a choice.
13
+ *
14
+ * The field is a button that says it opens a dialog and whether it is open. In the calendar the
15
+ * arrow keys move a day or a week, Page Up and Page Down a month (a year with Shift), and Home and
16
+ * End to the first and the last day of the month, never past `min` or `max`. Tab goes round the
17
+ * month buttons and the focused day. The chosen day is selected for assistive technology, and
18
+ * today is the current date.
19
+ */
20
+ declare const DatePicker: import("svelte").Component<DatePickerProps, {}, "">;
21
+ type DatePicker = ReturnType<typeof DatePicker>;
22
+ export default DatePicker;