@xds/solid 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.
Files changed (128) hide show
  1. package/dist/dom/Accordion.js +3 -2
  2. package/dist/dom/Avatar.js +17 -13
  3. package/dist/dom/AvatarStack.js +17 -13
  4. package/dist/dom/Badge.js +12 -10
  5. package/dist/dom/Banner.js +25 -15
  6. package/dist/dom/Button.js +10 -3
  7. package/dist/dom/Card.js +31 -26
  8. package/dist/dom/Checkbox.js +49 -24
  9. package/dist/dom/Chip.js +21 -17
  10. package/dist/dom/ChipBar.js +17 -13
  11. package/dist/dom/CountBadge.js +28 -23
  12. package/dist/dom/DatePicker.js +13 -7
  13. package/dist/dom/DateRangePicker.js +16 -10
  14. package/dist/dom/Dialog.js +3 -2
  15. package/dist/dom/Divider.js +12 -10
  16. package/dist/dom/EmptyState.js +14 -11
  17. package/dist/dom/Icon.js +30 -19
  18. package/dist/dom/IconButton.js +10 -3
  19. package/dist/dom/Labels.js +26 -0
  20. package/dist/dom/ListRow.js +34 -28
  21. package/dist/dom/MediaCard.js +32 -23
  22. package/dist/dom/Menu.js +3 -1
  23. package/dist/dom/ProgressBar.js +27 -15
  24. package/dist/dom/RadioGroup.js +44 -23
  25. package/dist/dom/SearchField.js +58 -32
  26. package/dist/dom/SectionHeader.js +17 -10
  27. package/dist/dom/SegmentedControl.js +33 -19
  28. package/dist/dom/Select.js +18 -5
  29. package/dist/dom/Sidebar.js +17 -13
  30. package/dist/dom/Skeleton.js +15 -13
  31. package/dist/dom/Slider.js +15 -7
  32. package/dist/dom/Spinner.js +23 -17
  33. package/dist/dom/Switch.js +49 -24
  34. package/dist/dom/Tabs.js +16 -6
  35. package/dist/dom/Text.js +6 -3
  36. package/dist/dom/TextField.js +37 -19
  37. package/dist/dom/Thumbnail.js +21 -14
  38. package/dist/dom/Toast.js +19 -20
  39. package/dist/dom/Tooltip.js +10 -6
  40. package/dist/dom/controllable.js +44 -0
  41. package/dist/dom/index.js +2 -1
  42. package/dist/dom/preview.js +2 -0
  43. package/dist/dom/root.js +16 -4
  44. package/dist/dom/trigger.js +5 -3
  45. package/dist/source/Accordion.jsx +3 -2
  46. package/dist/source/Avatar.d.ts +1 -1
  47. package/dist/source/Avatar.jsx +2 -1
  48. package/dist/source/AvatarStack.d.ts +1 -1
  49. package/dist/source/AvatarStack.jsx +2 -1
  50. package/dist/source/Badge.d.ts +1 -1
  51. package/dist/source/Badge.jsx +2 -1
  52. package/dist/source/Banner.d.ts +1 -1
  53. package/dist/source/Banner.jsx +5 -2
  54. package/dist/source/Button.d.ts +5 -1
  55. package/dist/source/Button.jsx +5 -2
  56. package/dist/source/Card.d.ts +1 -1
  57. package/dist/source/Card.jsx +3 -2
  58. package/dist/source/Checkbox.d.ts +10 -4
  59. package/dist/source/Checkbox.jsx +18 -6
  60. package/dist/source/Chip.d.ts +1 -1
  61. package/dist/source/Chip.jsx +2 -1
  62. package/dist/source/ChipBar.d.ts +1 -1
  63. package/dist/source/ChipBar.jsx +2 -1
  64. package/dist/source/CountBadge.d.ts +1 -1
  65. package/dist/source/CountBadge.jsx +3 -2
  66. package/dist/source/DatePicker.jsx +13 -7
  67. package/dist/source/DateRangePicker.jsx +16 -10
  68. package/dist/source/Dialog.jsx +3 -2
  69. package/dist/source/Divider.d.ts +1 -1
  70. package/dist/source/Divider.jsx +2 -1
  71. package/dist/source/EmptyState.d.ts +1 -1
  72. package/dist/source/EmptyState.jsx +2 -1
  73. package/dist/source/Icon.d.ts +1 -1
  74. package/dist/source/Icon.jsx +2 -1
  75. package/dist/source/IconButton.d.ts +5 -1
  76. package/dist/source/IconButton.jsx +5 -2
  77. package/dist/source/Labels.d.ts +17 -0
  78. package/dist/source/Labels.jsx +11 -0
  79. package/dist/source/ListRow.d.ts +1 -1
  80. package/dist/source/ListRow.jsx +3 -2
  81. package/dist/source/MediaCard.d.ts +1 -1
  82. package/dist/source/MediaCard.jsx +3 -2
  83. package/dist/source/Menu.d.ts +1 -1
  84. package/dist/source/Menu.jsx +3 -1
  85. package/dist/source/ProgressBar.d.ts +1 -1
  86. package/dist/source/ProgressBar.jsx +2 -1
  87. package/dist/source/RadioGroup.d.ts +5 -2
  88. package/dist/source/RadioGroup.jsx +18 -5
  89. package/dist/source/SearchField.d.ts +11 -3
  90. package/dist/source/SearchField.jsx +26 -12
  91. package/dist/source/SectionHeader.d.ts +1 -1
  92. package/dist/source/SectionHeader.jsx +2 -1
  93. package/dist/source/SegmentedControl.d.ts +4 -3
  94. package/dist/source/SegmentedControl.jsx +16 -5
  95. package/dist/source/Select.d.ts +4 -1
  96. package/dist/source/Select.jsx +16 -5
  97. package/dist/source/Sidebar.d.ts +1 -1
  98. package/dist/source/Sidebar.jsx +2 -1
  99. package/dist/source/Skeleton.jsx +2 -2
  100. package/dist/source/Slider.d.ts +2 -2
  101. package/dist/source/Slider.jsx +14 -6
  102. package/dist/source/Spinner.d.ts +1 -1
  103. package/dist/source/Spinner.jsx +2 -1
  104. package/dist/source/Switch.d.ts +10 -4
  105. package/dist/source/Switch.jsx +18 -6
  106. package/dist/source/Tabs.d.ts +2 -2
  107. package/dist/source/Tabs.jsx +16 -5
  108. package/dist/source/Text.d.ts +1 -1
  109. package/dist/source/Text.jsx +2 -1
  110. package/dist/source/TextField.d.ts +12 -3
  111. package/dist/source/TextField.jsx +24 -9
  112. package/dist/source/Thumbnail.d.ts +1 -1
  113. package/dist/source/Thumbnail.jsx +2 -1
  114. package/dist/source/Toast.d.ts +1 -1
  115. package/dist/source/Toast.jsx +2 -1
  116. package/dist/source/Tooltip.jsx +4 -3
  117. package/dist/source/controllable.d.ts +30 -0
  118. package/dist/source/controllable.js +30 -0
  119. package/dist/source/index.d.ts +1 -0
  120. package/dist/source/index.js +1 -0
  121. package/dist/source/preview.jsx +2 -1
  122. package/dist/source/root.d.ts +14 -4
  123. package/dist/source/root.js +7 -2
  124. package/dist/source/trigger.d.ts +4 -2
  125. package/dist/source/trigger.js +2 -2
  126. package/package.json +3 -3
  127. package/styles.css +4 -0
  128. package/tailwind.css +1 -1
@@ -2,6 +2,7 @@ import { BUTTON_ICON, buttonClass, classes, isHeld } from "@xds/core";
2
2
  import { children, createMemo, Show } from "solid-js";
3
3
  import { useDefaults } from "./Defaults.jsx";
4
4
  import { Icon } from "./Icon.jsx";
5
+ import { rootAttributes } from "./root.js";
5
6
  import { Spinner } from "./Spinner.jsx";
6
7
  import { withTrigger } from "./trigger.js";
7
8
  export function Button(props) {
@@ -32,8 +33,10 @@ export function Button(props) {
32
33
  }
33
34
  props.onPress?.();
34
35
  },
35
- })), () => props.loading === true);
36
- return (<button {...attributes}>
36
+ onFocus: (event) => props.onFocus?.(event),
37
+ onBlur: (event) => props.onBlur?.(event),
38
+ })), () => props.loading === true, rootAttributes(props));
39
+ return (<button ref={props.ref} {...attributes}>
37
40
  <Show when={props.loading}>
38
41
  <Show when={props.iconStart} fallback={<Spinner size="sm"/>}>
39
42
 
@@ -1,6 +1,6 @@
1
1
  import { type CardBaseProps } from "@xds/core";
2
2
  import { type Element } from "solid-js";
3
- import type { RootProps } from "./root.ts";
3
+ import { type RootProps } from "./root.ts";
4
4
  export type CardProps = CardBaseProps & RootProps & {
5
5
  /** Sit across from the title. A pressable card takes none: it is one button already. */
6
6
  actions?: Element;
@@ -1,6 +1,7 @@
1
1
  import { CARD_PARTS, cardClass, cardMediaClass, classes, rootPart, } from "@xds/core";
2
2
  import { dynamic } from "@solidjs/web";
3
3
  import { children, Show } from "solid-js";
4
+ import { rootAttributes } from "./root.js";
4
5
  const ROOT = rootPart("Card");
5
6
  export function Card(props) {
6
7
  const media = children(() => props.media);
@@ -36,10 +37,10 @@ export function Card(props) {
36
37
  const content = () => (<Show when={props.flush} fallback={parts()}>
37
38
  <Box class={CARD_PARTS.flush}>{parts()}</Box>
38
39
  </Show>);
39
- return (<Show when={pressable()} fallback={<section aria-current={props.selected ? "true" : undefined} class={surface()} style={props.style}>
40
+ return (<Show when={pressable()} fallback={<section {...rootAttributes(props)} aria-current={props.selected ? "true" : undefined} class={surface()} style={props.style}>
40
41
  {content()}
41
42
  </section>}>
42
- <button type="button" onClick={() => props.onPress?.()} aria-pressed={props.selected === undefined ? undefined : props.selected ? "true" : "false"} class={surface()} style={props.style}>
43
+ <button {...rootAttributes(props)} type="button" onClick={() => props.onPress?.()} aria-pressed={props.selected === undefined ? undefined : props.selected ? "true" : "false"} class={surface()} style={props.style}>
43
44
  {content()}
44
45
  </button>
45
46
  </Show>);
@@ -1,10 +1,16 @@
1
1
  import { type CheckboxBaseProps } from "@xds/core";
2
- import type { RootProps } from "./root.ts";
2
+ import type { JSX } from "@solidjs/web";
3
+ import { type RootProps } from "./root.ts";
3
4
  export type CheckboxProps = CheckboxBaseProps & RootProps & {
4
- onChange: (checked: boolean) => void;
5
+ onChange?: (checked: boolean) => void;
6
+ onFocus?: JSX.FocusEventHandler<HTMLInputElement, FocusEvent>;
7
+ onBlur?: JSX.FocusEventHandler<HTMLInputElement, FocusEvent>;
8
+ /** The native checkbox. */
9
+ ref?: JSX.Ref<HTMLInputElement>;
5
10
  };
6
11
  /**
7
12
  * 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.
13
+ * hidden and the box is drawn beside it. Without `checked` it keeps its own state, from
14
+ * `defaultChecked`.
9
15
  */
10
- export declare function Checkbox(props: CheckboxProps): import("@solidjs/web").JSX.Element;
16
+ export declare function Checkbox(props: CheckboxProps): JSX.Element;
@@ -1,13 +1,25 @@
1
- import { CHECKBOX_MARK, checkboxBoxClass, checkboxClass, checkboxLabelClass, checkboxMarkClass, classes, rootPart, } from "@xds/core";
1
+ import { CHECKBOX_MARK, checkboxBoxClass, checkboxClass, checkboxLabelClass, checkboxMarkClass, classes, isControlled, rootPart, } from "@xds/core";
2
2
  import { Show } from "solid-js";
3
+ import { composeRefs, createControllable, resetWithForm } from "./controllable.js";
3
4
  import { keepChecked } from "./controlled.js";
5
+ import { rootAttributes } from "./root.js";
4
6
  const ROOT = rootPart("Checkbox");
5
7
  export function Checkbox(props) {
6
- return (<label class={classes(ROOT, checkboxClass, props.class)} style={props.style}>
7
- <input type="checkbox" aria-label={props["aria-label"]} class="peer sr-only" checked={props.checked} defaultChecked={props.checked} disabled={props.disabled} name={props.name || undefined} onChange={(event) => {
8
- props.onChange(event.currentTarget.checked);
9
- keepChecked(event.currentTarget, () => props.checked);
10
- }}/>
8
+ const controlled = () => isControlled(props, "checked");
9
+ const defaultChecked = () => props.defaultChecked ?? false;
10
+ const checked = createControllable({
11
+ controlled,
12
+ value: () => props.checked ?? false,
13
+ defaultValue: defaultChecked,
14
+ onChange: (next) => props.onChange?.(next),
15
+ });
16
+ let input;
17
+ resetWithForm(() => input, controlled, checked.reset);
18
+ return (<label {...rootAttributes(props)} class={classes(ROOT, checkboxClass, props.class)} style={props.style}>
19
+ <input ref={composeRefs((element) => (input = element), () => props.ref)} type="checkbox" aria-label={props["aria-label"]} class="peer sr-only" checked={checked.value()} defaultChecked={controlled() ? checked.value() : defaultChecked()} disabled={props.disabled} name={props.name || undefined} onChange={(event) => {
20
+ checked.set(event.currentTarget.checked);
21
+ keepChecked(event.currentTarget, checked.value);
22
+ }} onFocus={(event) => props.onFocus?.(event)} onBlur={(event) => props.onBlur?.(event)}/>
11
23
  <span class={checkboxBoxClass}>
12
24
  <svg viewBox="0 0 16 16" fill="none" aria-hidden="true" class={checkboxMarkClass}>
13
25
  <path d={CHECKBOX_MARK} stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
@@ -1,5 +1,5 @@
1
1
  import { type ChipBaseProps } from "@xds/core";
2
- import type { RootProps } from "./root.ts";
2
+ import { type RootProps } from "./root.ts";
3
3
  export type ChipProps = ChipBaseProps & RootProps & {
4
4
  onPress?: () => void;
5
5
  };
@@ -1,9 +1,10 @@
1
1
  import { chipClass, chipIcon, classes, rootPart } from "@xds/core";
2
2
  import { Show } from "solid-js";
3
3
  import { Icon } from "./Icon.jsx";
4
+ import { rootAttributes } from "./root.js";
4
5
  const ROOT = rootPart("Chip");
5
6
  export function Chip(props) {
6
- return (<button type="button" aria-pressed={props.selected ? "true" : "false"} disabled={props.disabled} onClick={() => props.onPress?.()} class={classes(ROOT, chipClass(props.selected), props.class)} style={props.style}>
7
+ return (<button {...rootAttributes(props)} type="button" aria-pressed={props.selected ? "true" : "false"} disabled={props.disabled} onClick={() => props.onPress?.()} class={classes(ROOT, chipClass(props.selected), props.class)} style={props.style}>
7
8
  <Show when={chipIcon({ selected: props.selected, iconStart: props.iconStart })}>
8
9
  {(name) => <Icon name={name()} size="sm"/>}
9
10
  </Show>
@@ -1,6 +1,6 @@
1
1
  import { type ChipBarBaseProps } from "@xds/core";
2
2
  import type { Element } from "solid-js";
3
- import type { RootProps } from "./root.ts";
3
+ import { type RootProps } from "./root.ts";
4
4
  export type ChipBarProps = ChipBarBaseProps & RootProps & {
5
5
  /** The chips. Which of them are selected is the app's business: the bar holds no state. */
6
6
  children: Element;
@@ -1,7 +1,8 @@
1
1
  import { chipBarClass, classes, rootPart } from "@xds/core";
2
+ import { rootAttributes } from "./root.js";
2
3
  const ROOT = rootPart("ChipBar");
3
4
  export function ChipBar(props) {
4
- return (<div role="group" aria-label={props.label} class={classes(ROOT, chipBarClass, props.class)} style={props.style}>
5
+ return (<div {...rootAttributes(props)} role="group" aria-label={props.label} class={classes(ROOT, chipBarClass, props.class)} style={props.style}>
5
6
  {props.children}
6
7
  </div>);
7
8
  }
@@ -1,6 +1,6 @@
1
1
  import { type CountBadgeBaseProps } from "@xds/core";
2
2
  import { type Element } from "solid-js";
3
- import type { RootProps } from "./root.ts";
3
+ import { type RootProps } from "./root.ts";
4
4
  export type CountBadgeProps = CountBadgeBaseProps & RootProps & {
5
5
  /** What the count belongs to: an icon, an avatar, a button. The badge sits on its corner. */
6
6
  children?: Element;
@@ -1,15 +1,16 @@
1
1
  import { countBadgeAnchorClass, countBadgeClass, countBadgeText, classes, rootPart, } from "@xds/core";
2
2
  import { children, Show } from "solid-js";
3
+ import { rootAttributes } from "./root.js";
3
4
  const ROOT = rootPart("CountBadge");
4
5
  export function CountBadge(props) {
5
6
  const child = children(() => props.children);
6
7
  const badge = (onChild) => (<Show when={props.count > 0}>
7
- <span role={props.label ? "img" : undefined} aria-label={props.label || undefined} class={classes(!onChild && ROOT, countBadgeClass(onChild), !onChild && props.class)} style={onChild ? undefined : props.style}>
8
+ <span {...(onChild ? {} : rootAttributes(props))} role={props.label ? "img" : undefined} aria-label={props.label || undefined} class={classes(!onChild && ROOT, countBadgeClass(onChild), !onChild && props.class)} style={onChild ? undefined : props.style}>
8
9
  {countBadgeText(props.count, props.max)}
9
10
  </span>
10
11
  </Show>);
11
12
  return (<Show when={child() != null} fallback={badge(false)}>
12
- <span class={classes(ROOT, countBadgeAnchorClass, props.class)} style={props.style}>
13
+ <span {...rootAttributes(props)} class={classes(ROOT, countBadgeAnchorClass, props.class)} style={props.style}>
13
14
  {child()}
14
15
  {badge(true)}
15
16
  </span>
@@ -4,22 +4,28 @@ import * as datePicker from "@zag-js/date-picker";
4
4
  import { normalizeProps, useMachine } from "@zag-js/solid";
5
5
  import { createEffect, createMemo, createUniqueId, For, Show } from "solid-js";
6
6
  import { Icon } from "./Icon.jsx";
7
+ import { useLabels } from "./Labels.jsx";
7
8
  import { modalPopover } from "./modal-popover.js";
8
9
  import { Portal } from "./portal.jsx";
9
10
  import { createPresence } from "./presence.js";
10
- import { withStyle } from "./root.js";
11
+ import { rootAttributes, withStyle } from "./root.js";
11
12
  export function DatePicker(props) {
12
13
  const id = createUniqueId();
13
14
  const ids = datePickerIds(id);
14
15
  const locale = () => datePickerLocale(props.locale);
15
- const service = useMachine(datePicker.machine, () => datePickerMachineProps(props, {
16
- id,
17
- locale: locale(),
18
- onChange: (value) => props.onChange(value),
19
- gutter: readCssPx(null, "--xds-space-1", space[1]),
16
+ const labels = useLabels();
17
+ const service = useMachine(datePicker.machine, () => ({
18
+ ...datePickerMachineProps(props, {
19
+ id,
20
+ locale: locale(),
21
+ onChange: (value) => props.onChange(value),
22
+ gutter: readCssPx(null, "--xds-space-1", space[1]),
23
+ labels: labels(),
24
+ }),
25
+ ids: { root: props.id },
20
26
  }));
21
27
  const api = createMemo(() => datePicker.connect(service, normalizeProps));
22
- const root = withStyle(() => api().getRootProps(), () => props.style);
28
+ const root = withStyle(() => api().getRootProps(), () => props.style, rootAttributes(props));
23
29
  let positioner;
24
30
  let surface;
25
31
  modalPopover(() => api().open, () => positioner);
@@ -4,27 +4,33 @@ import * as datePicker from "@zag-js/date-picker";
4
4
  import { normalizeProps, useMachine } from "@zag-js/solid";
5
5
  import { createEffect, createMemo, createSignal, createUniqueId, For, Show } from "solid-js";
6
6
  import { Icon } from "./Icon.jsx";
7
+ import { useLabels } from "./Labels.jsx";
7
8
  import { modalPopover } from "./modal-popover.js";
8
9
  import { Portal } from "./portal.jsx";
9
10
  import { createPresence } from "./presence.js";
10
- import { withStyle } from "./root.js";
11
+ import { rootAttributes, withStyle } from "./root.js";
11
12
  export function DateRangePicker(props) {
12
13
  const id = createUniqueId();
13
14
  const ids = datePickerIds(id);
14
15
  const locale = () => datePickerLocale(props.locale);
16
+ const labels = useLabels();
15
17
  const [draft, setDraft] = createSignal(null);
16
18
  const [months, setMonths] = createSignal(1);
17
19
  const shown = createMemo(() => shownRange(props.value, draft()));
18
- const service = useMachine(datePicker.machine, () => dateRangeMachineProps(props, shown(), {
19
- id,
20
- locale: locale(),
21
- months: months(),
22
- onDraft: (next) => setDraft(() => next),
23
- onChange: (value) => props.onChange(value),
24
- gutter: readCssPx(null, "--xds-space-1", space[1]),
20
+ const service = useMachine(datePicker.machine, () => ({
21
+ ...dateRangeMachineProps(props, shown(), {
22
+ id,
23
+ locale: locale(),
24
+ months: months(),
25
+ onDraft: (next) => setDraft(() => next),
26
+ onChange: (value) => props.onChange(value),
27
+ gutter: readCssPx(null, "--xds-space-1", space[1]),
28
+ labels: labels(),
29
+ }),
30
+ ids: { root: props.id },
25
31
  }));
26
32
  const api = createMemo(() => datePicker.connect(service, normalizeProps));
27
- const root = withStyle(() => api().getRootProps(), () => props.style);
33
+ const root = withStyle(() => api().getRootProps(), () => props.style, rootAttributes(props));
28
34
  let positioner;
29
35
  let surface;
30
36
  modalPopover(() => api().open, () => positioner);
@@ -35,7 +41,7 @@ export function DateRangePicker(props) {
35
41
  createEffect(() => [open(), focused(), month()], ([isOpen]) => keepDayFocused(isOpen, surface));
36
42
  createEffect(open, (isOpen) => endRangeChoiceOnClose(service, isOpen));
37
43
  createEffect(focused, () => keepRangePreview(service, shown(), open()));
38
- const summary = createMemo(() => rangeSummary(shown(), props, locale()));
44
+ const summary = createMemo(() => rangeSummary(shown(), props, locale(), labels()));
39
45
  const views = createMemo(() => rangeMonthViews(api(), months()));
40
46
  const invalid = () => props.error !== undefined;
41
47
  return (<div {...root} class={classes("xds-date-picker xds-date-range-picker", props.class)}>
@@ -4,7 +4,7 @@ import { normalizeProps, useMachine } from "@zag-js/solid";
4
4
  import { createMemo, createUniqueId, Show } from "solid-js";
5
5
  import { Portal } from "./portal.jsx";
6
6
  import { createPresence } from "./presence.js";
7
- import { withStyle } from "./root.js";
7
+ import { rootAttributes, withStyle } from "./root.js";
8
8
  import { TriggerContext } from "./trigger.js";
9
9
  export function Dialog(props) {
10
10
  const id = createUniqueId();
@@ -13,6 +13,7 @@ export function Dialog(props) {
13
13
  let content;
14
14
  const service = useMachine(dialog.machine, () => ({
15
15
  id,
16
+ ids: { content: props.id },
16
17
  open: props.open,
17
18
  onOpenChange: (details) => {
18
19
  if (!details.open)
@@ -24,7 +25,7 @@ export function Dialog(props) {
24
25
  initialFocusEl: () => content ?? null,
25
26
  }));
26
27
  const api = createMemo(() => dialog.connect(service, normalizeProps));
27
- const contentProps = withStyle(() => api().getContentProps(), () => props.style);
28
+ const contentProps = withStyle(() => api().getContentProps(), () => props.style, rootAttributes(props));
28
29
  const present = createPresence(() => api().open, () => [backdrop, positioner]);
29
30
  return (<Show when={present()}>
30
31
  <Portal>
@@ -1,4 +1,4 @@
1
- import type { RootProps } from "./root.ts";
1
+ import { type RootProps } from "./root.ts";
2
2
  export type DividerProps = RootProps;
3
3
  /** A line between groups of content. Decorative lines use the low-contrast border color. */
4
4
  export declare function Divider(props: DividerProps): import("@solidjs/web").JSX.Element;
@@ -1,5 +1,6 @@
1
1
  import { classes, dividerClass, rootPart } from "@xds/core";
2
+ import { rootAttributes } from "./root.js";
2
3
  const ROOT = rootPart("Divider");
3
4
  export function Divider(props) {
4
- return <hr class={classes(ROOT, dividerClass, props.class)} style={props.style}/>;
5
+ return (<hr {...rootAttributes(props)} class={classes(ROOT, dividerClass, props.class)} style={props.style}/>);
5
6
  }
@@ -1,6 +1,6 @@
1
1
  import { type EmptyStateBaseProps } from "@xds/core";
2
2
  import { type Element } from "solid-js";
3
- import type { RootProps } from "./root.ts";
3
+ import { type RootProps } from "./root.ts";
4
4
  export type EmptyStateProps = EmptyStateBaseProps & RootProps & {
5
5
  /** The one thing to do about it, usually a Button. */
6
6
  action?: Element;
@@ -1,9 +1,10 @@
1
1
  import { classes, EMPTY_STATE_PARTS, rootPart } from "@xds/core";
2
2
  import { Show } from "solid-js";
3
3
  import { Icon } from "./Icon.jsx";
4
+ import { rootAttributes } from "./root.js";
4
5
  const ROOT = rootPart("EmptyState");
5
6
  export function EmptyState(props) {
6
- return (<div class={classes(ROOT, EMPTY_STATE_PARTS.root, props.class)} style={props.style}>
7
+ return (<div {...rootAttributes(props)} class={classes(ROOT, EMPTY_STATE_PARTS.root, props.class)} style={props.style}>
7
8
  <Icon name={props.icon} size="xl" class={EMPTY_STATE_PARTS.icon}/>
8
9
  <p class={EMPTY_STATE_PARTS.title}>{props.title}</p>
9
10
  <Show when={props.description}>
@@ -1,5 +1,5 @@
1
1
  import { type IconBaseProps } from "@xds/core";
2
- import type { RootProps } from "./root.ts";
2
+ import { type RootProps } from "./root.ts";
3
3
  export type IconProps = IconBaseProps & RootProps;
4
4
  /**
5
5
  * An icon from design/icons. It takes the color of the text around it. An arrow or a chevron
@@ -2,10 +2,11 @@ import { icons } from "@xds/tokens";
2
2
  import { classes, iconClass, rootPart } from "@xds/core";
3
3
  import { For } from "solid-js";
4
4
  import { useDefaults } from "./Defaults.jsx";
5
+ import { rootAttributes } from "./root.js";
5
6
  const ROOT = rootPart("Icon");
6
7
  export function Icon(props) {
7
8
  const defaults = useDefaults("Icon");
8
- return (<svg viewBox="0 0 24 24" fill={props.filled ? "currentColor" : "none"} stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class={classes(ROOT, iconClass(props.size ?? defaults().size), props.class)} style={props.style} role={props.label ? "img" : undefined} aria-label={props.label || undefined} aria-hidden={props.label ? undefined : "true"}>
9
+ return (<svg {...rootAttributes(props)} viewBox="0 0 24 24" fill={props.filled ? "currentColor" : "none"} stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class={classes(ROOT, iconClass(props.size ?? defaults().size), props.class)} style={props.style} role={props.label ? "img" : undefined} aria-label={props.label || undefined} aria-hidden={props.label ? undefined : "true"}>
9
10
  <For each={icons[props.name]}>{(path) => <path d={path}/>}</For>
10
11
  </svg>);
11
12
  }
@@ -1,8 +1,12 @@
1
1
  import { type IconButtonBaseProps } from "@xds/core";
2
2
  import type { JSX } from "@solidjs/web";
3
- import type { RootProps } from "./root.ts";
3
+ import { type RootProps } from "./root.ts";
4
4
  export type IconButtonProps = IconButtonBaseProps & RootProps & {
5
5
  onPress?: () => void;
6
+ onFocus?: JSX.FocusEventHandler<HTMLButtonElement, FocusEvent>;
7
+ onBlur?: JSX.FocusEventHandler<HTMLButtonElement, FocusEvent>;
8
+ /** The native button. */
9
+ ref?: JSX.Ref<HTMLButtonElement>;
6
10
  };
7
11
  /**
8
12
  * A button that holds only an icon, in Button's variants, sizes and states. It is a square as
@@ -2,6 +2,7 @@ import { buttonClass, classes, ICON_BUTTON_BOX, isHeld, } from "@xds/core";
2
2
  import { createMemo, Show } from "solid-js";
3
3
  import { useDefaults } from "./Defaults.jsx";
4
4
  import { Icon } from "./Icon.jsx";
5
+ import { rootAttributes } from "./root.js";
5
6
  import { Spinner } from "./Spinner.jsx";
6
7
  import { withTrigger } from "./trigger.js";
7
8
  export function IconButton(props) {
@@ -21,8 +22,10 @@ export function IconButton(props) {
21
22
  if (!props.loading)
22
23
  props.onPress?.();
23
24
  },
24
- })), () => props.loading === true);
25
- return (<button {...attributes}>
25
+ onFocus: (event) => props.onFocus?.(event),
26
+ onBlur: (event) => props.onBlur?.(event),
27
+ })), () => props.loading === true, rootAttributes(props));
28
+ return (<button ref={props.ref} {...attributes}>
26
29
  <Show when={!props.loading} fallback={<span class={ICON_BUTTON_BOX[size()]}>
27
30
  <Spinner size="sm"/>
28
31
  </span>}>
@@ -0,0 +1,17 @@
1
+ import { type ComponentLabels } from "@xds/core";
2
+ import { type Accessor, type Element } from "solid-js";
3
+ export type { ComponentLabels } from "@xds/core";
4
+ export type LabelsProps = {
5
+ /** The labels the components give their own parts, by key: `{ dismiss: "닫기" }`. */
6
+ value: Partial<ComponentLabels>;
7
+ children: Element;
8
+ };
9
+ /**
10
+ * Gives the components inside it the names of 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
12
+ * a component wins. A Labels inside another keeps the outer one's labels and replaces those it
13
+ * names; a change of `value` reaches every component inside.
14
+ */
15
+ export declare function Labels(props: LabelsProps): import("@solidjs/web").JSX.Element;
16
+ /** The labels the closest Labels gives, read where a label is read so that a change updates it. */
17
+ export declare function useLabels(): Accessor<ComponentLabels>;
@@ -0,0 +1,11 @@
1
+ import { DEFAULT_LABELS, mergeLabels } from "@xds/core";
2
+ import { createContext, createMemo, useContext } from "solid-js";
3
+ const LabelsContext = createContext(() => DEFAULT_LABELS);
4
+ export function Labels(props) {
5
+ const outer = useContext(LabelsContext);
6
+ const merged = createMemo(() => mergeLabels(outer(), props.value));
7
+ return <LabelsContext value={merged}>{props.children}</LabelsContext>;
8
+ }
9
+ export function useLabels() {
10
+ return useContext(LabelsContext);
11
+ }
@@ -1,6 +1,6 @@
1
1
  import { type ListRowBaseProps } from "@xds/core";
2
2
  import { type Element } from "solid-js";
3
- import type { RootProps } from "./root.ts";
3
+ import { type RootProps } from "./root.ts";
4
4
  export type ListRowProps = ListRowBaseProps & RootProps & {
5
5
  /** In front of the title: an avatar or an icon. */
6
6
  leading?: Element;
@@ -1,6 +1,7 @@
1
1
  import { classes, LIST_ROW_PARTS, listRowClass, listRowDescriptionClass, listRowTitleClass, rootPart, } from "@xds/core";
2
2
  import { Show } from "solid-js";
3
3
  import { Icon } from "./Icon.jsx";
4
+ import { rootAttributes } from "./root.js";
4
5
  const ROOT = rootPart("ListRow");
5
6
  export function ListRow(props) {
6
7
  return <PlaceRow {...props} current="true"/>;
@@ -28,10 +29,10 @@ export function PlaceRow(props) {
28
29
  <Icon name="chevron-right" size="sm" class={LIST_ROW_PARTS.chevron}/>
29
30
  </Show>
30
31
  </>);
31
- return (<Show when={pressable()} fallback={<div aria-current={current()} class={row()} style={props.style}>
32
+ return (<Show when={pressable()} fallback={<div {...rootAttributes(props)} aria-current={current()} class={row()} style={props.style}>
32
33
  {content()}
33
34
  </div>}>
34
- <button aria-current={current()} type="button" disabled={props.disabled} onClick={() => props.onPress?.()} class={row()} style={props.style}>
35
+ <button {...rootAttributes(props)} aria-current={current()} type="button" disabled={props.disabled} onClick={() => props.onPress?.()} class={row()} style={props.style}>
35
36
  {content()}
36
37
  </button>
37
38
  </Show>);
@@ -1,6 +1,6 @@
1
1
  import { type MediaCardBaseProps } from "@xds/core";
2
2
  import { type Element } from "solid-js";
3
- import type { RootProps } from "./root.ts";
3
+ import { type RootProps } from "./root.ts";
4
4
  export type MediaCardProps = MediaCardBaseProps & RootProps & {
5
5
  /** Before the text in the vertical layout, such as an Avatar. */
6
6
  leading?: Element;
@@ -1,6 +1,7 @@
1
1
  import { classes, MEDIA_CARD_PARTS, mediaCardContentClass, mediaCardIds, mediaCardThumbnailClass, rootPart, } from "@xds/core";
2
2
  import { createMemo, createUniqueId, For, Show } from "solid-js";
3
3
  import { useDefaults } from "./Defaults.jsx";
4
+ import { rootAttributes } from "./root.js";
4
5
  import { Thumbnail } from "./Thumbnail.jsx";
5
6
  const ROOT = rootPart("MediaCard");
6
7
  export function MediaCard(props) {
@@ -36,10 +37,10 @@ export function MediaCard(props) {
36
37
  </Show>
37
38
  </div>
38
39
  </div>);
39
- return (<Show when={pressable()} fallback={<div role="group" aria-labelledby={ids().names} class={classes(ROOT, MEDIA_CARD_PARTS.group, props.class)} style={props.style}>
40
+ return (<Show when={pressable()} fallback={<div {...rootAttributes(props)} role="group" aria-labelledby={ids().names} class={classes(ROOT, MEDIA_CARD_PARTS.group, props.class)} style={props.style}>
40
41
  {content()}
41
42
  </div>}>
42
- <div class={classes(ROOT, MEDIA_CARD_PARTS.pressable, props.class)} style={props.style}>
43
+ <div {...rootAttributes(props)} class={classes(ROOT, MEDIA_CARD_PARTS.pressable, props.class)} style={props.style}>
43
44
  <button type="button" onClick={() => props.onPress?.()} aria-labelledby={ids().names} class={MEDIA_CARD_PARTS.button}/>
44
45
  {content()}
45
46
  </div>
@@ -1,6 +1,6 @@
1
1
  import { type MenuBaseProps } from "@xds/core";
2
2
  import { type Element } from "solid-js";
3
- import type { RootProps } from "./root.ts";
3
+ import { type RootProps } from "./root.ts";
4
4
  export type { MenuItem } from "@xds/core";
5
5
  export type MenuProps = MenuBaseProps & RootProps & {
6
6
  /** The control that opens the menu: a Button or an IconButton. */
@@ -7,11 +7,13 @@ import { Icon } from "./Icon.jsx";
7
7
  import { modalPopover } from "./modal-popover.js";
8
8
  import { Portal } from "./portal.jsx";
9
9
  import { createPresence } from "./presence.js";
10
+ import { rootAttributes } from "./root.js";
10
11
  import { provideTrigger, TriggerContext } from "./trigger.js";
11
12
  export function Menu(props) {
12
13
  const id = createUniqueId();
13
14
  const service = useMachine(menu.machine, () => ({
14
15
  id,
16
+ ids: { content: props.id },
15
17
  "aria-label": props.label,
16
18
  positioning: {
17
19
  placement: `bottom-${props.align ?? "start"}`,
@@ -60,7 +62,7 @@ export function Menu(props) {
60
62
  let surface;
61
63
  modalPopover(() => api().open, () => positioner);
62
64
  const present = createPresence(() => api().open, () => [surface]);
63
- const content = mergeProps(() => api().getContentProps(), {
65
+ const content = mergeProps(() => api().getContentProps(), rootAttributes(props), {
64
66
  onKeyDown: (event) => keepListKeys(event, surface, ".xds-menu__item:not([data-disabled])", (value) => api().setHighlightedValue(value)),
65
67
  get style() {
66
68
  return props.style;
@@ -1,5 +1,5 @@
1
1
  import { type ProgressBarBaseProps } from "@xds/core";
2
- import type { RootProps } from "./root.ts";
2
+ import { type RootProps } from "./root.ts";
3
3
  export type ProgressBarProps = ProgressBarBaseProps & RootProps;
4
4
  /**
5
5
  * How far along something is, from 0 to 1. For work of unknown length use a Spinner.
@@ -1,8 +1,9 @@
1
1
  import { classes, progressBarClass, progressBarFillClass, progressPercent, rootPart, } from "@xds/core";
2
+ import { rootAttributes } from "./root.js";
2
3
  const ROOT = rootPart("ProgressBar");
3
4
  export function ProgressBar(props) {
4
5
  const percent = () => progressPercent(props.value);
5
- return (<div role="progressbar" aria-label={props.label} aria-valuemin={0} aria-valuemax={100} aria-valuenow={percent()} class={classes(ROOT, progressBarClass, props.class)} style={props.style}>
6
+ return (<div {...rootAttributes(props)} role="progressbar" aria-label={props.label} aria-valuemin={0} aria-valuemax={100} aria-valuenow={percent()} class={classes(ROOT, progressBarClass, props.class)} style={props.style}>
6
7
  <div class={progressBarFillClass} style={{ width: `${percent()}%` }}/>
7
8
  </div>);
8
9
  }
@@ -1,8 +1,8 @@
1
1
  import { type RadioGroupBaseProps } from "@xds/core";
2
- import type { RootProps } from "./root.ts";
2
+ import { type RootProps } from "./root.ts";
3
3
  export type { RadioOption } from "@xds/core";
4
4
  export type RadioGroupProps<Value extends string = string> = RadioGroupBaseProps<Value> & RootProps & {
5
- onChange: (value: Value) => void;
5
+ onChange?: (value: Value) => void;
6
6
  };
7
7
  /**
8
8
  * One choice among a few, applied later with the form it belongs to. For a choice that takes
@@ -11,5 +11,8 @@ export type RadioGroupProps<Value extends string = string> = RadioGroupBaseProps
11
11
  * The chosen option has a dot and a thicker ring, so the choice does not depend on color. The
12
12
  * options are native radio buttons, hidden and drawn beside, in a group named by the legend:
13
13
  * the arrow keys move between them, and the error is tied to the group and announced.
14
+ *
15
+ * Without `value` it keeps its own choice, from `defaultValue`. Given `value`, even as
16
+ * `undefined`, it shows that.
14
17
  */
15
18
  export declare function RadioGroup<Value extends string = string>(props: RadioGroupProps<Value>): import("@solidjs/web").JSX.Element;
@@ -1,28 +1,41 @@
1
- import { classes } from "@xds/core";
1
+ import { classes, isControlled } from "@xds/core";
2
2
  import { createUniqueId, For, Show } from "solid-js";
3
+ import { createControllable, resetWithForm } from "./controllable.js";
3
4
  import { keepChecked } from "./controlled.js";
5
+ import { rootAttributes } from "./root.js";
4
6
  export function RadioGroup(props) {
5
7
  const id = createUniqueId();
6
8
  const labelId = `${id}-label`;
7
9
  const errorId = `${id}-error`;
8
10
  const invalid = () => props.error !== undefined;
9
11
  let group;
10
- return (<div ref={(element) => (group = element)} role="radiogroup" aria-labelledby={labelId} aria-describedby={invalid() ? errorId : undefined} aria-invalid={invalid() ? "true" : undefined} aria-disabled={props.disabled ? "true" : undefined} aria-orientation="vertical" class={classes("xds-radio-group", props.class)} style={props.style}>
12
+ const controlled = () => isControlled(props, "value");
13
+ const value = createControllable({
14
+ controlled,
15
+ value: () => props.value,
16
+ defaultValue: () => props.defaultValue,
17
+ onChange: (next) => {
18
+ if (next !== undefined)
19
+ props.onChange?.(next);
20
+ },
21
+ });
22
+ resetWithForm(() => group, controlled, value.reset);
23
+ return (<div {...rootAttributes(props)} ref={(element) => (group = element)} role="radiogroup" aria-labelledby={labelId} aria-describedby={invalid() ? errorId : undefined} aria-invalid={invalid() ? "true" : undefined} aria-disabled={props.disabled ? "true" : undefined} aria-orientation="vertical" class={classes("xds-radio-group", props.class)} style={props.style}>
11
24
  <span id={labelId} class="xds-radio-group__label">
12
25
  {props.label}
13
26
  </span>
14
27
  <div class="xds-radio-group__options">
15
28
  <For each={props.options}>
16
29
  {(option, index) => (<label class="xds-radio-group__option">
17
- <input type="radio" class="xds-radio-group__input sr-only" name={props.name ?? id} value={option.value} checked={option.value === props.value} defaultChecked={option.value === props.value} disabled={props.disabled} aria-labelledby={`${id}-${index()}`} aria-describedby={[
30
+ <input type="radio" class="xds-radio-group__input sr-only" name={props.name ?? id} value={option.value} checked={option.value === value.value()} defaultChecked={option.value === (controlled() ? value.value() : props.defaultValue)} disabled={props.disabled} aria-labelledby={`${id}-${index()}`} aria-describedby={[
18
31
  option.description ? `${id}-${index()}-description` : undefined,
19
32
  invalid() ? errorId : undefined,
20
33
  ]
21
34
  .filter(Boolean)
22
35
  .join(" ") || undefined} aria-invalid={invalid() ? "true" : undefined} onChange={() => {
23
- props.onChange(option.value);
36
+ value.set(option.value);
24
37
  for (const input of group.querySelectorAll("input")) {
25
- keepChecked(input, () => input.value === props.value);
38
+ keepChecked(input, () => input.value === value.value());
26
39
  }
27
40
  }}/>
28
41
  <span class="xds-radio-group__row">