@manakind/ui-core 0.33.0 → 0.34.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.
@@ -0,0 +1,65 @@
1
+ import { type ElementType, type ReactNode, type RefObject } from 'react';
2
+ /**
3
+ * Puts the native inputs under `root` back on a controlled value after Ark
4
+ * has reported a change.
5
+ *
6
+ * Ark renders its hidden inputs uncontrolled (`defaultChecked`) and syncs
7
+ * them only when its own state changes. A controlled parent that declines a
8
+ * change therefore leaves the native input flipped while the control shows
9
+ * the old state, and the native input is what assistive tech reads. Ark
10
+ * reports the change after reading the input, so restoring the parent's
11
+ * value in the change handler is safe: a parent that accepts re-renders, and
12
+ * Ark syncs the input again from its new state.
13
+ *
14
+ * `value` is the component's controlled prop: a boolean for a single
15
+ * checkable (Checkbox, Switch), the chosen item's value or `null` for a
16
+ * group of radios (SegmentGroup, RadioGroup). `undefined` is uncontrolled,
17
+ * and leaves the inputs to Ark. Other inputs under `root`, such as
18
+ * SegmentGroup's custom text field, are left alone.
19
+ */
20
+ export declare function restoreNativeInputs(root: HTMLElement | null, value: boolean | string | null | undefined): void;
21
+ /**
22
+ * The change handler of a radio group (SegmentGroup, RadioGroup): reports the
23
+ * chosen item, then restores the native inputs to the controlled value.
24
+ *
25
+ * Zag reports `null` only when the value is cleared through its own API,
26
+ * which these wrappers never call, so a user's change always names an item.
27
+ */
28
+ export declare function radioGroupChangeHandler(root: RefObject<HTMLElement | null>, value: string | null | undefined, onValueChange: ((value: string) => void) | undefined): (details: {
29
+ value: string | null;
30
+ }) => void;
31
+ /**
32
+ * Ids of a single checkable's own (Checkbox, Switch).
33
+ *
34
+ * Ark hands a checkable inside a Field the field's control and label ids, so
35
+ * two in one field would share an id and both be named by the field's label.
36
+ * A checkbox or switch names itself, so it keeps its own ids and takes only
37
+ * the states from a field around it.
38
+ */
39
+ export declare function useOwnCheckableIds(): {
40
+ hiddenInput: string;
41
+ label: string;
42
+ };
43
+ export interface VisibleLabelProps {
44
+ /** The visible label, if any. */
45
+ label: ReactNode;
46
+ /** The accessible name the caller gave alongside it, if any. */
47
+ ariaLabel: string | undefined;
48
+ /** The class the label renders with either way. */
49
+ className: string;
50
+ }
51
+ /**
52
+ * The visible label of an Ark control that also takes an `aria-label`.
53
+ *
54
+ * Zag always names the control (the hidden input, or a group's root) by its
55
+ * label part's id, which would outrank an `aria-label`. With both given, the
56
+ * visible label is plain text instead of the Ark `Label` part, so that id
57
+ * resolves to nothing and the `aria-label` is what is announced. The text
58
+ * keeps its place and its class, and where the root is the `<label>`
59
+ * (Checkbox, Switch) it stays the click target.
60
+ */
61
+ export declare function renderVisibleLabel(Label: ElementType<{
62
+ className?: string;
63
+ children?: ReactNode;
64
+ }>, { label, ariaLabel, className }: VisibleLabelProps): ReactNode;
65
+ //# sourceMappingURL=ark-native-input.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ark-native-input.d.ts","sourceRoot":"","sources":["../src/ark-native-input.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAS,MAAM,OAAO,CAAC;AAEhF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,WAAW,GAAG,IAAI,EACxB,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GACzC,IAAI,CAQN;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EACnC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAChC,aAAa,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,GACnD,CAAC,OAAO,EAAE;IAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,KAAK,IAAI,CAK7C;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,IAAI;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAG3E;AAED,MAAM,WAAW,iBAAiB;IAChC,iCAAiC;IACjC,KAAK,EAAE,SAAS,CAAC;IACjB,gEAAgE;IAChE,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,WAAW,CAAC;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC,EAChE,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,iBAAiB,GACjD,SAAS,CAIX"}
@@ -0,0 +1,72 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useId } from 'react';
3
+ /**
4
+ * Puts the native inputs under `root` back on a controlled value after Ark
5
+ * has reported a change.
6
+ *
7
+ * Ark renders its hidden inputs uncontrolled (`defaultChecked`) and syncs
8
+ * them only when its own state changes. A controlled parent that declines a
9
+ * change therefore leaves the native input flipped while the control shows
10
+ * the old state, and the native input is what assistive tech reads. Ark
11
+ * reports the change after reading the input, so restoring the parent's
12
+ * value in the change handler is safe: a parent that accepts re-renders, and
13
+ * Ark syncs the input again from its new state.
14
+ *
15
+ * `value` is the component's controlled prop: a boolean for a single
16
+ * checkable (Checkbox, Switch), the chosen item's value or `null` for a
17
+ * group of radios (SegmentGroup, RadioGroup). `undefined` is uncontrolled,
18
+ * and leaves the inputs to Ark. Other inputs under `root`, such as
19
+ * SegmentGroup's custom text field, are left alone.
20
+ */
21
+ export function restoreNativeInputs(root, value) {
22
+ if (value === undefined || !root)
23
+ return;
24
+ const inputs = root.querySelectorAll('input[type="checkbox"], input[type="radio"]');
25
+ for (const input of inputs) {
26
+ input.checked = typeof value === 'boolean' ? value : input.value === value;
27
+ }
28
+ }
29
+ /**
30
+ * The change handler of a radio group (SegmentGroup, RadioGroup): reports the
31
+ * chosen item, then restores the native inputs to the controlled value.
32
+ *
33
+ * Zag reports `null` only when the value is cleared through its own API,
34
+ * which these wrappers never call, so a user's change always names an item.
35
+ */
36
+ export function radioGroupChangeHandler(root, value, onValueChange) {
37
+ return (details) => {
38
+ if (details.value !== null)
39
+ onValueChange?.(details.value);
40
+ restoreNativeInputs(root.current, value);
41
+ };
42
+ }
43
+ /**
44
+ * Ids of a single checkable's own (Checkbox, Switch).
45
+ *
46
+ * Ark hands a checkable inside a Field the field's control and label ids, so
47
+ * two in one field would share an id and both be named by the field's label.
48
+ * A checkbox or switch names itself, so it keeps its own ids and takes only
49
+ * the states from a field around it.
50
+ */
51
+ export function useOwnCheckableIds() {
52
+ const id = useId();
53
+ return { hiddenInput: `${id}:input`, label: `${id}:label` };
54
+ }
55
+ /**
56
+ * The visible label of an Ark control that also takes an `aria-label`.
57
+ *
58
+ * Zag always names the control (the hidden input, or a group's root) by its
59
+ * label part's id, which would outrank an `aria-label`. With both given, the
60
+ * visible label is plain text instead of the Ark `Label` part, so that id
61
+ * resolves to nothing and the `aria-label` is what is announced. The text
62
+ * keeps its place and its class, and where the root is the `<label>`
63
+ * (Checkbox, Switch) it stays the click target.
64
+ */
65
+ export function renderVisibleLabel(Label, { label, ariaLabel, className }) {
66
+ if (!label)
67
+ return null;
68
+ if (ariaLabel)
69
+ return _jsx("span", { className: className, children: label });
70
+ return _jsx(Label, { className: className, children: label });
71
+ }
72
+ //# sourceMappingURL=ark-native-input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ark-native-input.js","sourceRoot":"","sources":["../src/ark-native-input.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAoD,KAAK,EAAE,MAAM,OAAO,CAAC;AAEhF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,mBAAmB,CACjC,IAAwB,EACxB,KAA0C;IAE1C,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,IAAI;QAAE,OAAO;IACzC,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,CAClC,6CAA6C,CAC9C,CAAC;IACF,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,KAAK,CAAC,OAAO,GAAG,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,KAAK,KAAK,CAAC;IAC7E,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CACrC,IAAmC,EACnC,KAAgC,EAChC,aAAoD;IAEpD,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,IAAI,OAAO,CAAC,KAAK,KAAK,IAAI;YAAE,aAAa,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC3D,mBAAmB,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB;IAChC,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC;IACnB,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;AAC9D,CAAC;AAWD;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAAgE,EAChE,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAqB;IAElD,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,IAAI,SAAS;QAAE,OAAO,eAAM,SAAS,EAAE,SAAS,YAAG,KAAK,GAAQ,CAAC;IACjE,OAAO,KAAC,KAAK,IAAC,SAAS,EAAE,SAAS,YAAG,KAAK,GAAS,CAAC;AACtD,CAAC","sourcesContent":["import { type ElementType, type ReactNode, type RefObject, useId } from 'react';\n\n/**\n * Puts the native inputs under `root` back on a controlled value after Ark\n * has reported a change.\n *\n * Ark renders its hidden inputs uncontrolled (`defaultChecked`) and syncs\n * them only when its own state changes. A controlled parent that declines a\n * change therefore leaves the native input flipped while the control shows\n * the old state, and the native input is what assistive tech reads. Ark\n * reports the change after reading the input, so restoring the parent's\n * value in the change handler is safe: a parent that accepts re-renders, and\n * Ark syncs the input again from its new state.\n *\n * `value` is the component's controlled prop: a boolean for a single\n * checkable (Checkbox, Switch), the chosen item's value or `null` for a\n * group of radios (SegmentGroup, RadioGroup). `undefined` is uncontrolled,\n * and leaves the inputs to Ark. Other inputs under `root`, such as\n * SegmentGroup's custom text field, are left alone.\n */\nexport function restoreNativeInputs(\n root: HTMLElement | null,\n value: boolean | string | null | undefined,\n): void {\n if (value === undefined || !root) return;\n const inputs = root.querySelectorAll<HTMLInputElement>(\n 'input[type=\"checkbox\"], input[type=\"radio\"]',\n );\n for (const input of inputs) {\n input.checked = typeof value === 'boolean' ? value : input.value === value;\n }\n}\n\n/**\n * The change handler of a radio group (SegmentGroup, RadioGroup): reports the\n * chosen item, then restores the native inputs to the controlled value.\n *\n * Zag reports `null` only when the value is cleared through its own API,\n * which these wrappers never call, so a user's change always names an item.\n */\nexport function radioGroupChangeHandler(\n root: RefObject<HTMLElement | null>,\n value: string | null | undefined,\n onValueChange: ((value: string) => void) | undefined,\n): (details: { value: string | null }) => void {\n return (details) => {\n if (details.value !== null) onValueChange?.(details.value);\n restoreNativeInputs(root.current, value);\n };\n}\n\n/**\n * Ids of a single checkable's own (Checkbox, Switch).\n *\n * Ark hands a checkable inside a Field the field's control and label ids, so\n * two in one field would share an id and both be named by the field's label.\n * A checkbox or switch names itself, so it keeps its own ids and takes only\n * the states from a field around it.\n */\nexport function useOwnCheckableIds(): { hiddenInput: string; label: string } {\n const id = useId();\n return { hiddenInput: `${id}:input`, label: `${id}:label` };\n}\n\nexport interface VisibleLabelProps {\n /** The visible label, if any. */\n label: ReactNode;\n /** The accessible name the caller gave alongside it, if any. */\n ariaLabel: string | undefined;\n /** The class the label renders with either way. */\n className: string;\n}\n\n/**\n * The visible label of an Ark control that also takes an `aria-label`.\n *\n * Zag always names the control (the hidden input, or a group's root) by its\n * label part's id, which would outrank an `aria-label`. With both given, the\n * visible label is plain text instead of the Ark `Label` part, so that id\n * resolves to nothing and the `aria-label` is what is announced. The text\n * keeps its place and its class, and where the root is the `<label>`\n * (Checkbox, Switch) it stays the click target.\n */\nexport function renderVisibleLabel(\n Label: ElementType<{ className?: string; children?: ReactNode }>,\n { label, ariaLabel, className }: VisibleLabelProps,\n): ReactNode {\n if (!label) return null;\n if (ariaLabel) return <span className={className}>{label}</span>;\n return <Label className={className}>{label}</Label>;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"checkbox.d.ts","sourceRoot":"","sources":["../../src/checkbox/checkbox.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAiB,MAAM,OAAO,CAAC;AACtD,OAAO,gBAAgB,CAAC;AAExB,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAGrD,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE9C;;;;GAIG;AACH,KAAK,YAAY,GACb;IACE,0DAA0D;IAC1D,KAAK,EAAE,SAAS,CAAC;IACjB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GACD;IACE,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,8GAA8G;IAC9G,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEN,MAAM,MAAM,aAAa,GAAG,YAAY,GAAG;IACzC,6EAA6E;IAC7E,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,uCAAuC;IACvC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,uEAAuE;IACvE,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IAC7C,yCAAyC;IACzC,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,oEAAoE;IACpE,QAAQ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AAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEN,MAAM,MAAM,aAAa,GAAG,YAAY,GAAG;IACzC,6EAA6E;IAC7E,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,uCAAuC;IACvC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,uEAAuE;IACvE,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IAC7C,yCAAyC;IACzC,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,oEAAoE;IACpE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,8EAA8E;IAC9E,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,yDAAyD;IACzD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,kEAAkE;IAClE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,QAAQ,CAAC,EACvB,KAAK,EACL,OAAO,EACP,cAAc,EACd,eAAe,EACf,IAAW,EACX,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,SAAS,EAAE,aAAa,EACxB,SAAS,EACT,YAAY,EAAE,SAAS,EACvB,kBAAkB,EAAE,eAAe,GACpC,EAAE,aAAa,2CA8Cf"}
@@ -1,7 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Checkbox as ArkCheckbox } from '@ark-ui/react/checkbox';
3
- import { useId, useRef } from 'react';
3
+ import { useRef } from 'react';
4
4
  import './checkbox.css';
5
+ import { renderVisibleLabel, restoreNativeInputs, useOwnCheckableIds } from '../ark-native-input';
5
6
  import { cx } from '../cx';
6
7
  import { Icon } from '../icon/icon';
7
8
  import { useIconDefaults } from '../icon-defaults';
@@ -25,34 +26,17 @@ import { useIconDefaults } from '../icon-defaults';
25
26
  export function Checkbox({ label, checked, defaultChecked, onCheckedChange, size = 'md', disabled, invalid, readOnly, required, name, value, indicator: indicatorProp, className, 'aria-label': ariaLabel, 'aria-describedby': ariaDescribedBy, }) {
26
27
  const icons = useIconDefaults();
27
28
  const indicator = indicatorProp ?? icons.check;
28
- const inputRef = useRef(null);
29
- /*
30
- * Zag always names the hidden input by its label part's id, which would
31
- * outrank an `aria-label`. With both given, the visible label is plain
32
- * text instead, so that id resolves to nothing and the `aria-label` wins;
33
- * the root is still the `<label>`, so the text stays the click target.
34
- */
35
- /*
36
- * Ark hands a checkbox inside a Field the field's control and label ids,
37
- * so two checkboxes in one field would share an id and both be named by
38
- * the field's label. A checkbox names itself, so it keeps its own ids and
39
- * takes only the states from a field around it.
40
- */
41
- const ownId = useId();
42
- const ids = { hiddenInput: `${ownId}:input`, label: `${ownId}:label` };
43
- /*
44
- * Ark renders the hidden input uncontrolled and syncs it only when its own
45
- * state changes, so a controlled parent that declines a toggle would leave
46
- * the native input flipped while the box shows the old state. Restoring
47
- * the parent's value after Ark has read the input keeps the two agreeing,
48
- * as Switch does.
49
- */
29
+ const rootRef = useRef(null);
30
+ const ids = useOwnCheckableIds();
50
31
  const handleCheckedChange = (details) => {
51
32
  onCheckedChange?.(details.checked === true);
52
- if (checked !== undefined && inputRef.current)
53
- inputRef.current.checked = checked;
33
+ restoreNativeInputs(rootRef.current, checked);
54
34
  };
55
- return (_jsxs(ArkCheckbox.Root, { ids: ids, className: cx('ds-checkbox', `ds-checkbox--${size}`, className), checked: checked, defaultChecked: defaultChecked, onCheckedChange: handleCheckedChange, disabled: disabled, invalid: invalid, readOnly: readOnly, required: required, name: name, value: value, children: [_jsx(ArkCheckbox.Control, { className: "ds-checkbox__control", children: _jsx(ArkCheckbox.Indicator, { className: "ds-checkbox__indicator", children: _jsx(Icon, { source: indicator, size: "sm", decorative: true }) }) }), label &&
56
- (ariaLabel ? (_jsx("span", { className: "ds-checkbox__label", children: label })) : (_jsx(ArkCheckbox.Label, { className: "ds-checkbox__label", children: label }))), _jsx(ArkCheckbox.HiddenInput, { ref: inputRef, "aria-label": ariaLabel, "aria-describedby": ariaDescribedBy, "aria-readonly": readOnly || undefined })] }));
35
+ const visibleLabel = renderVisibleLabel(ArkCheckbox.Label, {
36
+ label,
37
+ ariaLabel,
38
+ className: 'ds-checkbox__label',
39
+ });
40
+ return (_jsxs(ArkCheckbox.Root, { ref: rootRef, ids: ids, className: cx('ds-checkbox', `ds-checkbox--${size}`, className), checked: checked, defaultChecked: defaultChecked, onCheckedChange: handleCheckedChange, disabled: disabled, invalid: invalid, readOnly: readOnly, required: required, name: name, value: value, children: [_jsx(ArkCheckbox.Control, { className: "ds-checkbox__control", children: _jsx(ArkCheckbox.Indicator, { className: "ds-checkbox__indicator", children: _jsx(Icon, { source: indicator, size: "sm", decorative: true }) }) }), visibleLabel, _jsx(ArkCheckbox.HiddenInput, { "aria-label": ariaLabel, "aria-describedby": ariaDescribedBy, "aria-readonly": readOnly || undefined })] }));
57
41
  }
58
42
  //# sourceMappingURL=checkbox.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"checkbox.js","sourceRoot":"","sources":["../../src/checkbox/checkbox.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,IAAI,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAkB,KAAK,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,gBAAgB,CAAC;AACxB,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,IAAI,EAAmB,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,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,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,KAAK,aAEZ,KAAC,WAAW,CAAC,OAAO,IAAC,SAAS,EAAC,sBAAsB,YACnD,KAAC,WAAW,CAAC,SAAS,IAAC,SAAS,EAAC,wBAAwB,YACvD,KAAC,IAAI,IAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAC,IAAI,EAAC,UAAU,SAAG,GAC1B,GACJ,EACrB,KAAK;gBACJ,CAAC,SAAS,CAAC,CAAC,CAAC,CACX,eAAM,SAAS,EAAC,oBAAoB,YAAE,KAAK,GAAQ,CACpD,CAAC,CAAC,CAAC,CACF,KAAC,WAAW,CAAC,KAAK,IAAC,SAAS,EAAC,oBAAoB,YAAE,KAAK,GAAqB,CAC9E,CAAC,EACJ,KAAC,WAAW,CAAC,WAAW,IACtB,GAAG,EAAE,QAAQ,gBACD,SAAS,sBACH,eAAe,mBAClB,QAAQ,IAAI,SAAS,GACpC,IACe,CACpB,CAAC;AACJ,CAAC","sourcesContent":["import { Checkbox as ArkCheckbox } from '@ark-ui/react/checkbox';\nimport { type ReactNode, useId, useRef } from 'react';\nimport './checkbox.css';\nimport { cx } from '../cx';\nimport { Icon, type IconSource } from '../icon/icon';\nimport { useIconDefaults } from '../icon-defaults';\n\nexport type CheckboxSize = 'sm' | 'md' | 'lg';\n\n/**\n * A checkbox has to have a name. A visible `label` is the one to reach for:\n * the whole label is the click target. Expressed as a union so an unnamed\n * checkbox is a compile error rather than an axe finding, as `Switch` does.\n */\ntype CheckboxName =\n | {\n /** Visible label. The whole label is the click target. */\n label: ReactNode;\n /**\n * A different accessible name when the visible label alone would not\n * say what the control is. Keep the visible words in it, so a voice\n * user can still say what they see.\n */\n 'aria-label'?: string;\n }\n | {\n label?: undefined;\n /** Accessible name when no visible label fits, such as a row whose text already says what the checkbox is. */\n 'aria-label': string;\n };\n\nexport type CheckboxProps = CheckboxName & {\n /** Controlled checked state. Leave undefined to let the component own it. */\n checked?: boolean;\n /** Initial state when uncontrolled. */\n defaultChecked?: boolean;\n /** Fired with the new state whenever the user toggles the checkbox. */\n onCheckedChange?: (checked: boolean) => void;\n /** Control size and label type scale. */\n size?: CheckboxSize;\n /** Disable the control. It keeps its state and stops responding. */\n disabled?: boolean;\n /**\n * Marks the control invalid for assistive tech and styling (`data-invalid`).\n * Pair it with a message the control points at through `aria-describedby`;\n * a red border alone is not an accessible error.\n */\n invalid?: boolean;\n /** Id of the element that describes the control, such as an error message. */\n 'aria-describedby'?: string;\n /** Show the state without letting the user change it. */\n readOnly?: boolean;\n /** Marks the hidden input required for native form validation. */\n required?: boolean;\n /** Name for native form participation. */\n name?: string;\n /** Value submitted under `name` while checked. Defaults to `on`. */\n value?: string;\n /**\n * Glyph shown in the box while checked.\n *\n * Defaults to the `IconDefaultsProvider`'s `check`, or a plain built-in one.\n */\n indicator?: IconSource;\n /** Extra class names appended after the `ds-checkbox` modifiers. */\n className?: string;\n};\n\n/**\n * A choice that is saved with the form, built on Ark UI's Checkbox.\n *\n * Ark owns the behaviour: a hidden checkbox carries the state, the root is\n * the `<label>` that names it, and Space and pointer toggling come for free.\n * This wrapper contributes `ds-` classes, the `--ds-checkbox-*` bindings, a\n * flat prop API, and the check glyph.\n *\n * ```tsx\n * <Checkbox label=\"Health\" checked={chosen} onCheckedChange={setChosen} />\n * ```\n *\n * A checkbox is for a choice that is submitted later, alone or as one of\n * several that can all be on. A setting that takes effect at once is a\n * `Switch`; a choice between values of which exactly one applies is a\n * `Select`.\n */\nexport function Checkbox({\n label,\n checked,\n defaultChecked,\n onCheckedChange,\n size = 'md',\n disabled,\n invalid,\n readOnly,\n required,\n name,\n value,\n indicator: indicatorProp,\n className,\n 'aria-label': ariaLabel,\n 'aria-describedby': ariaDescribedBy,\n}: CheckboxProps) {\n const icons = useIconDefaults();\n const indicator = indicatorProp ?? icons.check;\n const inputRef = useRef<HTMLInputElement>(null);\n\n /*\n * Zag always names the hidden input by its label part's id, which would\n * outrank an `aria-label`. With both given, the visible label is plain\n * text instead, so that id resolves to nothing and the `aria-label` wins;\n * the root is still the `<label>`, so the text stays the click target.\n */\n\n /*\n * Ark hands a checkbox inside a Field the field's control and label ids,\n * so two checkboxes in one field would share an id and both be named by\n * the field's label. A checkbox names itself, so it keeps its own ids and\n * takes only the states from a field around it.\n */\n const ownId = useId();\n const ids = { hiddenInput: `${ownId}:input`, label: `${ownId}:label` };\n\n /*\n * Ark renders the hidden input uncontrolled and syncs it only when its own\n * state changes, so a controlled parent that declines a toggle would leave\n * the native input flipped while the box shows the old state. Restoring\n * the parent's value after Ark has read the input keeps the two agreeing,\n * as Switch does.\n */\n const handleCheckedChange = (details: { checked: boolean | 'indeterminate' }) => {\n onCheckedChange?.(details.checked === true);\n if (checked !== undefined && inputRef.current) inputRef.current.checked = checked;\n };\n\n return (\n <ArkCheckbox.Root\n ids={ids}\n className={cx('ds-checkbox', `ds-checkbox--${size}`, className)}\n checked={checked}\n defaultChecked={defaultChecked}\n onCheckedChange={handleCheckedChange}\n disabled={disabled}\n invalid={invalid}\n readOnly={readOnly}\n required={required}\n name={name}\n value={value}\n >\n <ArkCheckbox.Control className=\"ds-checkbox__control\">\n <ArkCheckbox.Indicator className=\"ds-checkbox__indicator\">\n <Icon source={indicator} size=\"sm\" decorative />\n </ArkCheckbox.Indicator>\n </ArkCheckbox.Control>\n {label &&\n (ariaLabel ? (\n <span className=\"ds-checkbox__label\">{label}</span>\n ) : (\n <ArkCheckbox.Label className=\"ds-checkbox__label\">{label}</ArkCheckbox.Label>\n ))}\n <ArkCheckbox.HiddenInput\n ref={inputRef}\n aria-label={ariaLabel}\n aria-describedby={ariaDescribedBy}\n aria-readonly={readOnly || undefined}\n />\n </ArkCheckbox.Root>\n );\n}\n"]}
1
+ {"version":3,"file":"checkbox.js","sourceRoot":"","sources":["../../src/checkbox/checkbox.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,IAAI,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAk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,aAAa,EAAE,gBAAgB,IAAI,EAAE,EAAE,SAAS,CAAC,EAC/D,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,cAAc,EAC9B,eAAe,EAAE,mBAAmB,EACpC,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,KAAK,aAEZ,KAAC,WAAW,CAAC,OAAO,IAAC,SAAS,EAAC,sBAAsB,YACnD,KAAC,WAAW,CAAC,SAAS,IAAC,SAAS,EAAC,wBAAwB,YACvD,KAAC,IAAI,IAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAC,IAAI,EAAC,UAAU,SAAG,GAC1B,GACJ,EACrB,YAAY,EACb,KAAC,WAAW,CAAC,WAAW,kBACV,SAAS,sBACH,eAAe,mBAClB,QAAQ,IAAI,SAAS,GACpC,IACe,CACpB,CAAC;AACJ,CAAC","sourcesContent":["import { Checkbox as ArkCheckbox } from '@ark-ui/react/checkbox';\nimport { type ReactNode, useRef } from 'react';\nimport './checkbox.css';\nimport { renderVisibleLabel, restoreNativeInputs, useOwnCheckableIds } from '../ark-native-input';\nimport { cx } from '../cx';\nimport { Icon, type IconSource } from '../icon/icon';\nimport { useIconDefaults } from '../icon-defaults';\n\nexport type CheckboxSize = 'sm' | 'md' | 'lg';\n\n/**\n * A checkbox has to have a name. A visible `label` is the one to reach for:\n * the whole label is the click target. Expressed as a union so an unnamed\n * checkbox is a compile error rather than an axe finding, as `Switch` does.\n */\ntype CheckboxName =\n | {\n /** Visible label. The whole label is the click target. */\n label: ReactNode;\n /**\n * A different accessible name when the visible label alone would not\n * say what the control is. Keep the visible words in it, so a voice\n * user can still say what they see.\n */\n 'aria-label'?: string;\n }\n | {\n label?: undefined;\n /** Accessible name when no visible label fits, such as a row whose text already says what the checkbox is. */\n 'aria-label': string;\n };\n\nexport type CheckboxProps = CheckboxName & {\n /** Controlled checked state. Leave undefined to let the component own it. */\n checked?: boolean;\n /** Initial state when uncontrolled. */\n defaultChecked?: boolean;\n /** Fired with the new state whenever the user toggles the checkbox. */\n onCheckedChange?: (checked: boolean) => void;\n /** Control size and label type scale. */\n size?: CheckboxSize;\n /** Disable the control. It keeps its state and stops responding. */\n disabled?: boolean;\n /**\n * Marks the control invalid for assistive tech and styling (`data-invalid`).\n * Pair it with a message the control points at through `aria-describedby`;\n * a red border alone is not an accessible error.\n */\n invalid?: boolean;\n /** Id of the element that describes the control, such as an error message. */\n 'aria-describedby'?: string;\n /** Show the state without letting the user change it. */\n readOnly?: boolean;\n /** Marks the hidden input required for native form validation. */\n required?: boolean;\n /** Name for native form participation. */\n name?: string;\n /** Value submitted under `name` while checked. Defaults to `on`. */\n value?: string;\n /**\n * Glyph shown in the box while checked.\n *\n * Defaults to the `IconDefaultsProvider`'s `check`, or a plain built-in one.\n */\n indicator?: IconSource;\n /** Extra class names appended after the `ds-checkbox` modifiers. */\n className?: string;\n};\n\n/**\n * A choice that is saved with the form, built on Ark UI's Checkbox.\n *\n * Ark owns the behaviour: a hidden checkbox carries the state, the root is\n * the `<label>` that names it, and Space and pointer toggling come for free.\n * This wrapper contributes `ds-` classes, the `--ds-checkbox-*` bindings, a\n * flat prop API, and the check glyph.\n *\n * ```tsx\n * <Checkbox label=\"Health\" checked={chosen} onCheckedChange={setChosen} />\n * ```\n *\n * A checkbox is for a choice that is submitted later, alone or as one of\n * several that can all be on. A setting that takes effect at once is a\n * `Switch`; a choice between values of which exactly one applies is a\n * `Select`.\n */\nexport function Checkbox({\n label,\n checked,\n defaultChecked,\n onCheckedChange,\n size = 'md',\n disabled,\n invalid,\n readOnly,\n required,\n name,\n value,\n indicator: indicatorProp,\n className,\n 'aria-label': ariaLabel,\n 'aria-describedby': ariaDescribedBy,\n}: CheckboxProps) {\n const icons = useIconDefaults();\n const indicator = indicatorProp ?? icons.check;\n const rootRef = useRef<HTMLLabelElement>(null);\n\n const ids = useOwnCheckableIds();\n\n const handleCheckedChange = (details: { checked: boolean | 'indeterminate' }) => {\n onCheckedChange?.(details.checked === true);\n restoreNativeInputs(rootRef.current, checked);\n };\n\n const visibleLabel = renderVisibleLabel(ArkCheckbox.Label, {\n label,\n ariaLabel,\n className: 'ds-checkbox__label',\n });\n\n return (\n <ArkCheckbox.Root\n ref={rootRef}\n ids={ids}\n className={cx('ds-checkbox', `ds-checkbox--${size}`, className)}\n checked={checked}\n defaultChecked={defaultChecked}\n onCheckedChange={handleCheckedChange}\n disabled={disabled}\n invalid={invalid}\n readOnly={readOnly}\n required={required}\n name={name}\n value={value}\n >\n <ArkCheckbox.Control className=\"ds-checkbox__control\">\n <ArkCheckbox.Indicator className=\"ds-checkbox__indicator\">\n <Icon source={indicator} size=\"sm\" decorative />\n </ArkCheckbox.Indicator>\n </ArkCheckbox.Control>\n {visibleLabel}\n <ArkCheckbox.HiddenInput\n aria-label={ariaLabel}\n aria-describedby={ariaDescribedBy}\n aria-readonly={readOnly || undefined}\n />\n </ArkCheckbox.Root>\n );\n}\n"]}
@@ -7,7 +7,7 @@ import type { IconSource } from './icon/icon';
7
7
  * direction turns the one it is given.
8
8
  */
9
9
  export interface IconDefaults {
10
- /** Select's and Menu's indicator, Calendar's next month, Accordion's indicator. */
10
+ /** Select's and Menu's indicator, Calendar's next month, Accordion's indicator, Table's sort arrows. */
11
11
  chevronRight: IconSource;
12
12
  /** Calendar's previous month. */
13
13
  chevronLeft: IconSource;
@@ -1 +1 @@
1
- {"version":3,"file":"icon-defaults.d.ts","sourceRoot":"","sources":["../src/icon-defaults.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAiB,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAE3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,mFAAmF;IACnF,YAAY,EAAE,UAAU,CAAC;IACzB,iCAAiC;IACjC,WAAW,EAAE,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aults.js","sourceRoot":"","sources":["../src/icon-defaults.tsx"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,mFAAmF;AACnF,YAAY,CAAC;;AAEb,OAAO,EAAE,aAAa,EAAkB,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAC3E,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAsBjF,MAAM,SAAS,GAAiB;IAC9B,YAAY,EAAE,YAAY;IAC1B,WAAW,EAAE,WAAW;IACxB,KAAK,EAAE,KAAK;IACZ,KAAK,EAAE,KAAK;IACZ,GAAG,EAAE,GAAG;CACT,CAAC;AAEF,MAAM,mBAAmB,GAAG,aAAa,CAAe,SAAS,CAAC,CAAC;AAQnE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,oBAAoB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAA6B;IACjF,MAAM,KAAK,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE;QACzB,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;QAC7E,OAAO,EAAE,GAAG,KAAK,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;IACpD,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IACnB,OAAO,KAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAgC,CAAC;AAC/F,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,eAAe;IAC7B,OAAO,UAAU,CAAC,mBAAmB,CAAC,CAAC;AACzC,CAAC","sourcesContent":["// A client boundary, so a React Server Component can import the provider:\n// React's server build has no createContext. See docs/decisions/icon-defaults.mdx.\n'use client';\n\nimport { createContext, type ReactNode, useContext, useMemo } from 'react';\nimport { Check, ChevronLeft, ChevronRight, Cross, Pin } from './fallback-glyphs';\nimport type { IconSource } from './icon/icon';\n\n/**\n * The glyphs ui-core draws when a component's icon prop is left out, by\n * shape: a select's and a menu's chevron, a checkbox's check, a dialog's\n * close cross. Chevrons point right, and a component that needs another\n * direction turns the one it is given.\n */\nexport interface IconDefaults {\n /** Select's and Menu's indicator, Calendar's next month, Accordion's indicator. */\n chevronRight: IconSource;\n /** Calendar's previous month. */\n chevronLeft: IconSource;\n /** Checkbox's check, and the chosen option in Select and the menus. */\n check: IconSource;\n /** Dialog's close button and Combobox's remove. */\n cross: IconSource;\n /** Combobox's pin. */\n pin: IconSource;\n}\n\nconst FALLBACKS: IconDefaults = {\n chevronRight: ChevronRight,\n chevronLeft: ChevronLeft,\n check: Check,\n cross: Cross,\n pin: Pin,\n};\n\nconst IconDefaultsContext = createContext<IconDefaults>(FALLBACKS);\n\nexport interface IconDefaultsProviderProps {\n /** The product's glyphs. A shape left out keeps the one around it, or the built-in fallback. */\n icons: Partial<IconDefaults>;\n children: ReactNode;\n}\n\n/**\n * Sets the glyphs every ui-core component below it draws by default, so a\n * product puts its own icon set in once, at its root, instead of passing\n * `indicator`, `itemIndicator` or `closeIcon` at every call. A prop passed to\n * one component still wins.\n *\n * The icons are functions, which a Next.js Server Component cannot pass to a\n * client one, so a Next.js app mounts the provider from a client component of\n * its own.\n *\n * ```tsx\n * <IconDefaultsProvider icons={{ chevronRight: ChevronRight, check: Check }}>\n * <App />\n * </IconDefaultsProvider>\n * ```\n */\nexport function IconDefaultsProvider({ icons, children }: IconDefaultsProviderProps) {\n const outer = useContext(IconDefaultsContext);\n const value = useMemo(() => {\n const given = Object.entries(icons).filter(([, icon]) => icon !== undefined);\n return { ...outer, ...Object.fromEntries(given) };\n }, [outer, icons]);\n return <IconDefaultsContext.Provider value={value}>{children}</IconDefaultsContext.Provider>;\n}\n\n/** The glyphs in force here: the nearest provider's, or the built-in fallbacks. */\nexport function useIconDefaults(): IconDefaults {\n return useContext(IconDefaultsContext);\n}\n"]}
1
+ {"version":3,"file":"icon-defaults.js","sourceRoot":"","sources":["../src/icon-defaults.tsx"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,mFAAmF;AACnF,YAAY,CAAC;;AAEb,OAAO,EAAE,aAAa,EAAkB,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAC3E,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAsBjF,MAAM,SAAS,GAAiB;IAC9B,YAAY,EAAE,YAAY;IAC1B,WAAW,EAAE,WAAW;IACxB,KAAK,EAAE,KAAK;IACZ,KAAK,EAAE,KAAK;IACZ,GAAG,EAAE,GAAG;CACT,CAAC;AAEF,MAAM,mBAAmB,GAAG,aAAa,CAAe,SAAS,CAAC,CAAC;AAQnE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,oBAAoB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAA6B;IACjF,MAAM,KAAK,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE;QACzB,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;QAC7E,OAAO,EAAE,GAAG,KAAK,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;IACpD,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IACnB,OAAO,KAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAgC,CAAC;AAC/F,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,eAAe;IAC7B,OAAO,UAAU,CAAC,mBAAmB,CAAC,CAAC;AACzC,CAAC","sourcesContent":["// A client boundary, so a React Server Component can import the provider:\n// React's server build has no createContext. See docs/decisions/icon-defaults.mdx.\n'use client';\n\nimport { createContext, type ReactNode, useContext, useMemo } from 'react';\nimport { Check, ChevronLeft, ChevronRight, Cross, Pin } from './fallback-glyphs';\nimport type { IconSource } from './icon/icon';\n\n/**\n * The glyphs ui-core draws when a component's icon prop is left out, by\n * shape: a select's and a menu's chevron, a checkbox's check, a dialog's\n * close cross. Chevrons point right, and a component that needs another\n * direction turns the one it is given.\n */\nexport interface IconDefaults {\n /** Select's and Menu's indicator, Calendar's next month, Accordion's indicator, Table's sort arrows. */\n chevronRight: IconSource;\n /** Calendar's previous month. */\n chevronLeft: IconSource;\n /** Checkbox's check, and the chosen option in Select and the menus. */\n check: IconSource;\n /** Dialog's close button and Combobox's remove. */\n cross: IconSource;\n /** Combobox's pin. */\n pin: IconSource;\n}\n\nconst FALLBACKS: IconDefaults = {\n chevronRight: ChevronRight,\n chevronLeft: ChevronLeft,\n check: Check,\n cross: Cross,\n pin: Pin,\n};\n\nconst IconDefaultsContext = createContext<IconDefaults>(FALLBACKS);\n\nexport interface IconDefaultsProviderProps {\n /** The product's glyphs. A shape left out keeps the one around it, or the built-in fallback. */\n icons: Partial<IconDefaults>;\n children: ReactNode;\n}\n\n/**\n * Sets the glyphs every ui-core component below it draws by default, so a\n * product puts its own icon set in once, at its root, instead of passing\n * `indicator`, `itemIndicator` or `closeIcon` at every call. A prop passed to\n * one component still wins.\n *\n * The icons are functions, which a Next.js Server Component cannot pass to a\n * client one, so a Next.js app mounts the provider from a client component of\n * its own.\n *\n * ```tsx\n * <IconDefaultsProvider icons={{ chevronRight: ChevronRight, check: Check }}>\n * <App />\n * </IconDefaultsProvider>\n * ```\n */\nexport function IconDefaultsProvider({ icons, children }: IconDefaultsProviderProps) {\n const outer = useContext(IconDefaultsContext);\n const value = useMemo(() => {\n const given = Object.entries(icons).filter(([, icon]) => icon !== undefined);\n return { ...outer, ...Object.fromEntries(given) };\n }, [outer, icons]);\n return <IconDefaultsContext.Provider value={value}>{children}</IconDefaultsContext.Provider>;\n}\n\n/** The glyphs in force here: the nearest provider's, or the built-in fallbacks. */\nexport function useIconDefaults(): IconDefaults {\n return useContext(IconDefaultsContext);\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -41,6 +41,7 @@ export * from './spinner';
41
41
  export * from './split-layout';
42
42
  export * from './sticky';
43
43
  export * from './switch';
44
+ export * from './table';
44
45
  export * from './tabs';
45
46
  export * from './text';
46
47
  export * from './tooltip';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,OAAO,EACL,KAAK,IAAI,aAAa,EACtB,WAAW,IAAI,mBAAmB,EAClC,YAAY,IAAI,oBAAoB,EACpC,KAAK,IAAI,aAAa,EACtB,GAAG,IAAI,WAAW,GACnB,MAAM,mBAAmB,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc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ClC,YAAY,IAAI,oBAAoB,EACpC,KAAK,IAAI,aAAa,EACtB,GAAG,IAAI,WAAW,GACnB,MAAM,mBAAmB,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC"}
package/dist/index.js CHANGED
@@ -40,6 +40,7 @@ export * from './spinner';
40
40
  export * from './split-layout';
41
41
  export * from './sticky';
42
42
  export * from './switch';
43
+ export * from './table';
43
44
  export * from './tabs';
44
45
  export * from './text';
45
46
  export * from './tooltip';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAA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CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC","sourcesContent":["export * from './accordion';\nexport * from './alert';\nexport * from './avatar';\nexport * from './badge';\nexport * from './breadcrumb';\nexport * from './button';\nexport * from './calendar';\nexport * from './card';\nexport * from './centered-layout';\nexport * from './checkbox';\nexport * from './combobox';\nexport { cx } from './cx';\nexport * from './date-input';\nexport * from './dialog';\nexport * from './divider';\nexport * from './empty-state';\nexport {\n Check as FallbackCheck,\n ChevronLeft as FallbackChevronLeft,\n ChevronRight as FallbackChevronRight,\n Cross as FallbackCross,\n Pin as FallbackPin,\n} from './fallback-glyphs';\nexport * from './field';\nexport * from './form-layout';\nexport * from './icon';\nexport * from './icon-defaults';\nexport * from './illustration';\nexport * from './layout';\nexport * from './link';\nexport type { LinkComponentProps } from './link-component';\nexport * from './menu';\nexport * from './page-layout';\nexport * from './popover';\nexport * from './progress';\nexport * from './radio-group';\nexport * from './reorder-control';\nexport * from './scroll-area';\nexport * from './section';\nexport * from './segment-group';\nexport * from './select';\nexport * from './show';\nexport * from './side-panel-layout';\nexport * from './skeleton';\nexport * from './slider';\nexport * from './spinner';\nexport * from './split-layout';\nexport * from './sticky';\nexport * from './switch';\nexport * from './tabs';\nexport * from './text';\nexport * from './tooltip';\nexport * from './visually-hidden';\nexport * from './wizard-layout';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,OAAO,EACL,KAAK,IAAI,aAAa,EACtB,WAAW,IAAI,mBAAmB,EAClC,YAAY,IAAI,oBAAoB,EACpC,KAAK,IAAI,aAAa,EACtB,GAAG,IAAI,WAAW,GACnB,MAAM,mBAAmB,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AAEvB,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC","sourcesContent":["export * from './accordion';\nexport * from './alert';\nexport * from './avatar';\nexport * from './badge';\nexport * from './breadcrumb';\nexport * from './button';\nexport * from './calendar';\nexport * from './card';\nexport * from './centered-layout';\nexport * from './checkbox';\nexport * from './combobox';\nexport { cx } from './cx';\nexport * from './date-input';\nexport * from './dialog';\nexport * from './divider';\nexport * from './empty-state';\nexport {\n Check as FallbackCheck,\n ChevronLeft as FallbackChevronLeft,\n ChevronRight as FallbackChevronRight,\n Cross as FallbackCross,\n Pin as FallbackPin,\n} from './fallback-glyphs';\nexport * from './field';\nexport * from './form-layout';\nexport * from './icon';\nexport * from './icon-defaults';\nexport * from './illustration';\nexport * from './layout';\nexport * from './link';\nexport type { LinkComponentProps } from './link-component';\nexport * from './menu';\nexport * from './page-layout';\nexport * from './popover';\nexport * from './progress';\nexport * from './radio-group';\nexport * from './reorder-control';\nexport * from './scroll-area';\nexport * from './section';\nexport * from './segment-group';\nexport * from './select';\nexport * from './show';\nexport * from './side-panel-layout';\nexport * from './skeleton';\nexport * from './slider';\nexport * from './spinner';\nexport * from './split-layout';\nexport * from './sticky';\nexport * from './switch';\nexport * from './table';\nexport * from './tabs';\nexport * from './text';\nexport * from './tooltip';\nexport * from './visually-hidden';\nexport * from './wizard-layout';\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"radio-group.d.ts","sourceRoot":"","sources":["../../src/radio-group/radio-group.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAU,MAAM,OAAO,CAAC;AAC/C,OAAO,mBAAmB,CAAC;AAG3B,MAAM,WAAW,cAAc;IAC7B,0EAA0E;IAC1E,KAAK,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;GAGG;AACH,KAAK,cAAc,GACf;IACE,0DAA0D;IAC1D,KAAK,EAAE,SAAS,CAAC;IACjB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GACD;IACE,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,mGAAmG;IACnG,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEN,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG;IAC7C,kDAAkD;IAClD,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,uCAAuC;IACvC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qFAAqF;IACrF,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,uEAAuE;IACvE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,mEAAmE;IACnE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,KAAK,EACL,KAAK,EACL,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,IAAI,EACJ,SAAS,EACT,YAAY,EAAE,SAAS,GACxB,EAAE,eAAe,2CA0DjB"}
1
+ {"version":3,"file":"radio-group.d.ts","sourceRoot":"","sources":["../../src/radio-group/radio-group.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAU,MAAM,OAAO,CAAC;AAC/C,OAAO,mBAAmB,CAAC;AAI3B,MAAM,WAAW,cAAc;IAC7B,0EAA0E;IAC1E,KAAK,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;GAGG;AACH,KAAK,cAAc,GACf;IACE,0DAA0D;IAC1D,KAAK,EAAE,SAAS,CAAC;IACjB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GACD;IACE,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,mGAAmG;IACnG,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEN,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG;IAC7C,kDAAkD;IAClD,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,uCAAuC;IACvC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qFAAqF;IACrF,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,uEAAuE;IACvE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,mEAAmE;IACnE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,KAAK,EACL,KAAK,EACL,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,IAAI,EACJ,SAAS,EACT,YAAY,EAAE,SAAS,GACxB,EAAE,eAAe,2CAwCjB"}
@@ -2,6 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { RadioGroup as ArkRadioGroup } from '@ark-ui/react/radio-group';
3
3
  import { useRef } from 'react';
4
4
  import './radio-group.css';
5
+ import { radioGroupChangeHandler, renderVisibleLabel } from '../ark-native-input';
5
6
  import { cx } from '../cx';
6
7
  /**
7
8
  * One choice among several, as a column of radios, built on Ark UI's
@@ -30,27 +31,12 @@ import { cx } from '../cx';
30
31
  */
31
32
  export function RadioGroup({ label, items, value, defaultValue, onValueChange, disabled, name, className, 'aria-label': ariaLabel, }) {
32
33
  const rootRef = useRef(null);
33
- /*
34
- * As in SegmentGroup: Ark leaves the native radios uncontrolled, so a
35
- * controlled parent that declines a choice would leave the input checked
36
- * while the control shows the old one. Restoring the parent's value after
37
- * Ark has read the inputs keeps the two agreeing.
38
- */
39
- const handleValueChange = (details) => {
40
- if (details.value !== null)
41
- onValueChange?.(details.value);
42
- if (value === undefined || !rootRef.current)
43
- return;
44
- for (const input of rootRef.current.querySelectorAll('input[type="radio"]')) {
45
- input.checked = input.value === value;
46
- }
47
- };
48
- /*
49
- * Zag names the root by its label part's id, which would outrank an
50
- * `aria-label`; with both given the visible label is plain text instead.
51
- */
52
- const visibleLabel = label &&
53
- (ariaLabel ? (_jsx("span", { className: "ds-radio-group__label", children: label })) : (_jsx(ArkRadioGroup.Label, { className: "ds-radio-group__label", children: label })));
34
+ const handleValueChange = radioGroupChangeHandler(rootRef, value, onValueChange);
35
+ const visibleLabel = renderVisibleLabel(ArkRadioGroup.Label, {
36
+ label,
37
+ ariaLabel,
38
+ className: 'ds-radio-group__label',
39
+ });
54
40
  const renderItem = (item) => (_jsxs(ArkRadioGroup.Item, { value: item.value, disabled: item.disabled, className: "ds-radio-group__item", children: [_jsx(ArkRadioGroup.ItemControl, { className: "ds-radio-group__control" }), _jsx(ArkRadioGroup.ItemText, { className: "ds-radio-group__text", children: item.label }), _jsx(ArkRadioGroup.ItemHiddenInput, {})] }, item.value));
55
41
  return (_jsxs(ArkRadioGroup.Root, { ref: rootRef, className: cx('ds-radio-group', className), value: value, defaultValue: defaultValue, onValueChange: handleValueChange, disabled: disabled, name: name, orientation: "vertical", "aria-label": ariaLabel, children: [visibleLabel, items.map(renderItem)] }));
56
42
  }
@@ -1 +1 @@
1
- {"version":3,"file":"radio-group.js","sourceRoot":"","sources":["../../src/radio-group/radio-group.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,IAAI,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAkB,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,mBAAmB,CAAC;AAC3B,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAmD3B;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,UAAU,CAAC,EACzB,KAAK,EACL,KAAK,EACL,KAAK,EACL,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,IAAI,EACJ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ACjB,GAAG,EAAE,OAAO,EACZ,SAAS,EAAE,EAAE,CAAC,gBAAgB,EAAE,SAAS,CAAC,EAC1C,KAAK,EAAE,KAAK,EACZ,YAAY,EAAE,YAAY,EAC1B,aAAa,EAAE,iBAAiB,EAChC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,WAAW,EAAC,UAAU,gBACV,SAAS,aAEpB,YAAY,EACZ,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,IACH,CACtB,CAAC;AACJ,CAAC","sourcesContent":["import { RadioGroup as ArkRadioGroup } from '@ark-ui/react/radio-group';\nimport { type ReactNode, useRef } from 'react';\nimport './radio-group.css';\nimport { cx } from '../cx';\n\nexport interface RadioGroupItem {\n /** Stable value reported by `onValueChange` and compared with `value`. */\n value: string;\n /** Text beside the radio. The whole row is its click target. */\n label: string;\n /** Individually disable this choice without removing it. */\n disabled?: boolean;\n}\n\n/**\n * A radio group has to have a name, expressed as a union so an unnamed group\n * is a compile error rather than an axe finding, as `SegmentGroup` does.\n */\ntype RadioGroupName =\n | {\n /** Visible label, above the choices, naming the group. */\n label: ReactNode;\n /**\n * A different accessible name when the visible label alone would not\n * say what the choice is. Keep the visible words in it.\n */\n 'aria-label'?: string;\n }\n | {\n label?: undefined;\n /** Accessible name when a heading or a section title around it already says what the choice is. */\n 'aria-label': string;\n };\n\nexport type RadioGroupProps = RadioGroupName & {\n /** The choices, in order, one under the other. */\n items: RadioGroupItem[];\n /**\n * Controlled value. `null` is controlled with nothing chosen; `undefined`\n * leaves the component to own its value from `defaultValue` onward.\n */\n value?: string | null;\n /** Initial value when uncontrolled. */\n defaultValue?: string;\n /** Fired with the newly chosen value. Choosing the chosen one again does nothing. */\n onValueChange?: (value: string) => void;\n /** Disable every choice. The chosen one keeps showing which is set. */\n disabled?: boolean;\n /** Name for native form participation through the radio inputs. */\n name?: string;\n /** Extra class names appended after `ds-radio-group`. */\n className?: string;\n};\n\n/**\n * One choice among several, as a column of radios, built on Ark UI's\n * RadioGroup: a filter's period, a setting with a handful of options whose\n * labels are worth reading side by side.\n *\n * Ark owns the behaviour: native radio inputs carry the state, the arrow keys\n * move the choice and Tab leaves the group in one step. This wrapper\n * contributes `ds-` classes, the `--ds-radio-group-*` bindings and a flat\n * `items` API.\n *\n * ```tsx\n * <RadioGroup\n * aria-label=\"Scheduled in\"\n * items={[\n * { value: 'any', label: 'Any time' },\n * { value: 'this-week', label: 'This week' },\n * ]}\n * value={when}\n * onValueChange={setWhen}\n * />\n * ```\n *\n * A few short choices seen at once in a row are a `SegmentGroup`; a long\n * list, or one in a form row, is a `Select`.\n */\nexport function RadioGroup({\n label,\n items,\n value,\n defaultValue,\n onValueChange,\n disabled,\n name,\n className,\n 'aria-label': ariaLabel,\n}: RadioGroupProps) {\n const rootRef = useRef<HTMLDivElement>(null);\n\n /*\n * As in SegmentGroup: Ark leaves the native radios uncontrolled, so a\n * controlled parent that declines a choice would leave the input checked\n * while the control shows the old one. Restoring the parent's value after\n * Ark has read the inputs keeps the two agreeing.\n */\n const handleValueChange = (details: { value: string | null }) => {\n if (details.value !== null) onValueChange?.(details.value);\n if (value === undefined || !rootRef.current) return;\n for (const input of rootRef.current.querySelectorAll<HTMLInputElement>('input[type=\"radio\"]')) {\n input.checked = input.value === value;\n }\n };\n\n /*\n * Zag names the root by its label part's id, which would outrank an\n * `aria-label`; with both given the visible label is plain text instead.\n */\n const visibleLabel =\n label &&\n (ariaLabel ? (\n <span className=\"ds-radio-group__label\">{label}</span>\n ) : (\n <ArkRadioGroup.Label className=\"ds-radio-group__label\">{label}</ArkRadioGroup.Label>\n ));\n\n const renderItem = (item: RadioGroupItem) => (\n <ArkRadioGroup.Item\n key={item.value}\n value={item.value}\n disabled={item.disabled}\n className=\"ds-radio-group__item\"\n >\n <ArkRadioGroup.ItemControl className=\"ds-radio-group__control\" />\n <ArkRadioGroup.ItemText className=\"ds-radio-group__text\">{item.label}</ArkRadioGroup.ItemText>\n <ArkRadioGroup.ItemHiddenInput />\n </ArkRadioGroup.Item>\n );\n\n return (\n <ArkRadioGroup.Root\n ref={rootRef}\n className={cx('ds-radio-group', className)}\n value={value}\n defaultValue={defaultValue}\n onValueChange={handleValueChange}\n disabled={disabled}\n name={name}\n orientation=\"vertical\"\n aria-label={ariaLabel}\n >\n {visibleLabel}\n {items.map(renderItem)}\n </ArkRadioGroup.Root>\n );\n}\n"]}
1
+ {"version":3,"file":"radio-group.js","sourceRoot":"","sources":["../../src/radio-group/radio-group.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,IAAI,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAkB,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,mBAAmB,CAAC;AAC3B,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAmD3B;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,UAAU,CAAC,EACzB,KAAK,EACL,KAAK,EACL,KAAK,EACL,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,IAAI,EACJ,SAAS,EACT,YAAY,EAAE,SAAS,GACP;IAChB,MAAM,OAAO,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAE7C,MAAM,iBAAiB,GAAG,uBAAuB,CAAC,OAAO,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC;IAEjF,MAAM,YAAY,GAAG,kBAAkB,CAAC,aAAa,CAAC,KAAK,EAAE;QAC3D,KAAK;QACL,SAAS;QACT,SAAS,EAAE,uBAAuB;KACnC,CAAC,CAAC;IAEH,MAAM,UAAU,GAAG,CAAC,IAAoB,EAAE,EAAE,CAAC,CAC3C,MAAC,aAAa,CAAC,IAAI,IAEjB,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EACvB,SAAS,EAAC,sBAAsB,aAEhC,KAAC,aAAa,CAAC,WAAW,IAAC,SAAS,EAAC,yBAAyB,GAAG,EACjE,KAAC,aAAa,CAAC,QAAQ,IAAC,SAAS,EAAC,sBAAsB,YAAE,IAAI,CAAC,KAAK,GAA0B,EAC9F,KAAC,aAAa,CAAC,eAAe,KAAG,KAP5B,IAAI,CAAC,KAAK,CAQI,CACtB,CAAC;IAEF,OAAO,CACL,MAAC,aAAa,CAAC,IAAI,IACjB,GAAG,EAAE,OAAO,EACZ,SAAS,EAAE,EAAE,CAAC,gBAAgB,EAAE,SAAS,CAAC,EAC1C,KAAK,EAAE,KAAK,EACZ,YAAY,EAAE,YAAY,EAC1B,aAAa,EAAE,iBAAiB,EAChC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,WAAW,EAAC,UAAU,gBACV,SAAS,aAEpB,YAAY,EACZ,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,IACH,CACtB,CAAC;AACJ,CAAC","sourcesContent":["import { RadioGroup as ArkRadioGroup } from '@ark-ui/react/radio-group';\nimport { type ReactNode, useRef } from 'react';\nimport './radio-group.css';\nimport { radioGroupChangeHandler, renderVisibleLabel } from '../ark-native-input';\nimport { cx } from '../cx';\n\nexport interface RadioGroupItem {\n /** Stable value reported by `onValueChange` and compared with `value`. */\n value: string;\n /** Text beside the radio. The whole row is its click target. */\n label: string;\n /** Individually disable this choice without removing it. */\n disabled?: boolean;\n}\n\n/**\n * A radio group has to have a name, expressed as a union so an unnamed group\n * is a compile error rather than an axe finding, as `SegmentGroup` does.\n */\ntype RadioGroupName =\n | {\n /** Visible label, above the choices, naming the group. */\n label: ReactNode;\n /**\n * A different accessible name when the visible label alone would not\n * say what the choice is. Keep the visible words in it.\n */\n 'aria-label'?: string;\n }\n | {\n label?: undefined;\n /** Accessible name when a heading or a section title around it already says what the choice is. */\n 'aria-label': string;\n };\n\nexport type RadioGroupProps = RadioGroupName & {\n /** The choices, in order, one under the other. */\n items: RadioGroupItem[];\n /**\n * Controlled value. `null` is controlled with nothing chosen; `undefined`\n * leaves the component to own its value from `defaultValue` onward.\n */\n value?: string | null;\n /** Initial value when uncontrolled. */\n defaultValue?: string;\n /** Fired with the newly chosen value. Choosing the chosen one again does nothing. */\n onValueChange?: (value: string) => void;\n /** Disable every choice. The chosen one keeps showing which is set. */\n disabled?: boolean;\n /** Name for native form participation through the radio inputs. */\n name?: string;\n /** Extra class names appended after `ds-radio-group`. */\n className?: string;\n};\n\n/**\n * One choice among several, as a column of radios, built on Ark UI's\n * RadioGroup: a filter's period, a setting with a handful of options whose\n * labels are worth reading side by side.\n *\n * Ark owns the behaviour: native radio inputs carry the state, the arrow keys\n * move the choice and Tab leaves the group in one step. This wrapper\n * contributes `ds-` classes, the `--ds-radio-group-*` bindings and a flat\n * `items` API.\n *\n * ```tsx\n * <RadioGroup\n * aria-label=\"Scheduled in\"\n * items={[\n * { value: 'any', label: 'Any time' },\n * { value: 'this-week', label: 'This week' },\n * ]}\n * value={when}\n * onValueChange={setWhen}\n * />\n * ```\n *\n * A few short choices seen at once in a row are a `SegmentGroup`; a long\n * list, or one in a form row, is a `Select`.\n */\nexport function RadioGroup({\n label,\n items,\n value,\n defaultValue,\n onValueChange,\n disabled,\n name,\n className,\n 'aria-label': ariaLabel,\n}: RadioGroupProps) {\n const rootRef = useRef<HTMLDivElement>(null);\n\n const handleValueChange = radioGroupChangeHandler(rootRef, value, onValueChange);\n\n const visibleLabel = renderVisibleLabel(ArkRadioGroup.Label, {\n label,\n ariaLabel,\n className: 'ds-radio-group__label',\n });\n\n const renderItem = (item: RadioGroupItem) => (\n <ArkRadioGroup.Item\n key={item.value}\n value={item.value}\n disabled={item.disabled}\n className=\"ds-radio-group__item\"\n >\n <ArkRadioGroup.ItemControl className=\"ds-radio-group__control\" />\n <ArkRadioGroup.ItemText className=\"ds-radio-group__text\">{item.label}</ArkRadioGroup.ItemText>\n <ArkRadioGroup.ItemHiddenInput />\n </ArkRadioGroup.Item>\n );\n\n return (\n <ArkRadioGroup.Root\n ref={rootRef}\n className={cx('ds-radio-group', className)}\n value={value}\n defaultValue={defaultValue}\n onValueChange={handleValueChange}\n disabled={disabled}\n name={name}\n orientation=\"vertical\"\n aria-label={ariaLabel}\n >\n {visibleLabel}\n {items.map(renderItem)}\n </ArkRadioGroup.Root>\n );\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"segment-group.d.ts","sourceRoot":"","sources":["../../src/segment-group/segment-group.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAU,MAAM,OAAO,CAAC;AAC/C,OAAO,qBAAqB,CAAC;AAG7B,MAAM,MAAM,gBAAgB,GAAG,IAAI,GAAG,IAAI,CAAC;AAE3C,MAAM,WAAW,gBAAgB;IAC/B,0EAA0E;IAC1E,KAAK,EAAE,MAAM,CAAC;IACd,kGAAkG;IAClG,KAAK,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,+FAA+F;IAC/F,YAAY,EAAE,MAAM,CAAC;IACrB,sCAAsC;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mGAAmG;IACnG,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,SAAS,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC;CAC5C;AAED;;;;GAIG;AACH,KAAK,gBAAgB,GACjB;IACE,oEAAoE;IACpE,KAAK,EAAE,SAAS,CAAC;IACjB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GACD;IACE,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,2FAA2F;IAC3F,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEN,MAAM,MAAM,iBAAiB,GAAG,gBAAgB,GAAG;IACjD,qDAAqD;IACrD,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,uCAAuC;IACvC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,4EAA4E;IAC5E,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB;;;;;;OAMG;IACH,GAAG,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC1B;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;IAC9B;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;OAIG;IACH,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,yEAAyE;IACzE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,0EAA0E;IAC1E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,KAAK,EACL,KAAK,EACL,YAAY,EACZ,aAAa,EACb,IAAW,EACX,GAAa,EACb,OAAmB,EACnB,SAAiB,EACjB,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,SAAS,EACT,YAAY,EAAE,SAAS,GACxB,EAAE,iBAAiB,2CA8GnB"}
1
+ {"version":3,"file":"segment-group.d.ts","sourceRoot":"","sources":["../../src/segment-group/segment-group.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAU,MAAM,OAAO,CAAC;AAC/C,OAAO,qBAAqB,CAAC;AAI7B,MAAM,MAAM,gBAAgB,GAAG,IAAI,GAAG,IAAI,CAA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ACH,OAAO,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;IAC9B;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;OAIG;IACH,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,yEAAyE;IACzE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,0EAA0E;IAC1E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,KAAK,EACL,KAAK,EACL,YAAY,EACZ,aAAa,EACb,IAAW,EACX,GAAa,EACb,OAAmB,EACnB,SAAiB,EACjB,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,SAAS,EACT,YAAY,EAAE,SAAS,GACxB,EAAE,iBAAiB,2CAuFnB"}
@@ -2,6 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { SegmentGroup as ArkSegmentGroup } from '@ark-ui/react/segment-group';
3
3
  import { useRef } from 'react';
4
4
  import './segment-group.css';
5
+ import { radioGroupChangeHandler, renderVisibleLabel } from '../ark-native-input';
5
6
  import { cx } from '../cx';
6
7
  /**
7
8
  * One choice among a few, shown as a row of segments, built on Ark UI's
@@ -32,32 +33,12 @@ import { cx } from '../cx';
32
33
  */
33
34
  export function SegmentGroup({ label, items, value, defaultValue, onValueChange, size = 'md', fit = 'equal', density = 'default', fullWidth = false, custom, disabled, name, className, 'aria-label': ariaLabel, }) {
34
35
  const rootRef = useRef(null);
35
- /*
36
- * Zag reports `null` only when the value is cleared through its API, which
37
- * this wrapper never calls; a user can only move the choice to a segment.
38
- *
39
- * Ark renders the hidden radios uncontrolled and syncs them only when its
40
- * own state changes, so a controlled parent that declines a choice would
41
- * leave the native radio checked while the segment shows the old one.
42
- * Restoring the parent's value after Ark has read the radios keeps the two
43
- * agreeing, as Checkbox and Switch do.
44
- */
45
- const handleValueChange = (details) => {
46
- if (details.value !== null)
47
- onValueChange?.(details.value);
48
- if (value === undefined || !rootRef.current)
49
- return;
50
- for (const input of rootRef.current.querySelectorAll('input[type="radio"]')) {
51
- input.checked = input.value === value;
52
- }
53
- };
54
- /*
55
- * Zag always names the root by its label part's id, which would outrank an
56
- * `aria-label`. With both given, the visible label is plain text instead,
57
- * so that id resolves to nothing and the `aria-label` is what is announced.
58
- */
59
- const visibleLabel = label &&
60
- (ariaLabel ? (_jsx("span", { className: "ds-segment-group__label", children: label })) : (_jsx(ArkSegmentGroup.Label, { className: "ds-segment-group__label", children: label })));
36
+ const handleValueChange = radioGroupChangeHandler(rootRef, value, onValueChange);
37
+ const visibleLabel = renderVisibleLabel(ArkSegmentGroup.Label, {
38
+ label,
39
+ ariaLabel,
40
+ className: 'ds-segment-group__label',
41
+ });
61
42
  const renderItem = (item) => (_jsxs(ArkSegmentGroup.Item, { value: item.value, disabled: item.disabled, className: "ds-segment-group__item", children: [_jsx(ArkSegmentGroup.ItemText, { className: "ds-segment-group__item-text", children: item.label }), _jsx(ArkSegmentGroup.ItemHiddenInput, {})] }, item.value));
62
43
  /*
63
44
  * The field is the choice while it holds a value no segment has. That is
@@ -1 +1 @@
1
- {"version":3,"file":"segment-group.js","sourceRoot":"","sources":["../../src/segment-group/segment-group.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,IAAI,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,EAAkB,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,qBAAqB,CAAC;AAC7B,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AA0G3B;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,YAAY,CAAC,EAC3B,KAAK,EACL,KAAK,EACL,KAAK,EACL,YAAY,EACZ,aAAa,EACb,IAAI,GAAG,IAAI,EACX,GAAG,GAA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,EAC1B,aAAa,EAAE,iBAAiB,EAChC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,WAAW,EAAC,YAAY,gBACZ,SAAS,aAEpB,YAAY,EACb,eAAK,SAAS,EAAC,yBAAyB,aACrC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,EACrB,MAAM,IAAI,CACT,KAAC,eAAe,CAAC,OAAO,cACrB,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,GACrB,CAC3B,IACG,IACe,CACxB,CAAC;AACJ,CAAC","sourcesContent":["import { SegmentGroup as ArkSegmentGroup } from '@ark-ui/react/segment-group';\nimport { type ReactNode, useRef } from 'react';\nimport './segment-group.css';\nimport { cx } from '../cx';\n\nexport type SegmentGroupSize = 'sm' | 'md';\n\nexport interface SegmentGroupItem {\n /** Stable value reported by `onValueChange` and compared with `value`. */\n value: string;\n /** Text shown on the segment. Keep it to a word or two; a longer one wraps inside its segment. */\n label: string;\n /** Individually disable this choice without removing it. */\n disabled?: boolean;\n}\n\n/**\n * A value typed beside the segments, for one no segment offers: the minutes\n * of a duration whose presets are 30 minutes and an hour. The consumer owns\n * both values and keeps them agreeing: a typed value that matches a segment\n * checks that segment, and choosing a segment fills the field with its value.\n */\nexport interface SegmentGroupCustom {\n /** What the field holds, `''` when empty. */\n value: string;\n /** Fired with the field's text on every change. */\n onValueChange: (value: string) => void;\n /** The field's accessible name (\"Duration in minutes\"); it has no visible label of its own. */\n 'aria-label': string;\n /** Shown while the field is empty. */\n placeholder?: string;\n /** A unit written after the value, such as `min`. Decorative: put the unit in `aria-label` too. */\n unit?: string;\n /** The keyboard a phone shows for the field. */\n inputMode?: 'numeric' | 'decimal' | 'text';\n}\n\n/**\n * A segment group has to have a name. A visible `label` is the one to reach\n * for; expressed as a union so an unnamed group is a compile error rather\n * than an axe finding, as `Checkbox` and `Switch` do.\n */\ntype SegmentGroupName =\n | {\n /** Visible label, rendered above the track and naming the group. */\n label: ReactNode;\n /**\n * A different accessible name when the visible label alone would not\n * say what the choice is. Keep the visible words in it (\"Period\" →\n * \"Reporting period\"), so a voice user can still say what they see.\n */\n 'aria-label'?: string;\n }\n | {\n label?: undefined;\n /** Accessible name when the surrounding heading or row already says what the choice is. */\n 'aria-label': string;\n };\n\nexport type SegmentGroupProps = SegmentGroupName & {\n /** The choices, in order. Exactly one is checked. */\n items: SegmentGroupItem[];\n /**\n * Controlled value. `null` is controlled with nothing checked, for a form\n * that starts without a choice; `undefined` leaves the component to own\n * its value from `defaultValue` onward, as `Select` does.\n */\n value?: string | null;\n /** Initial value when uncontrolled. */\n defaultValue?: string;\n /**\n * Fired with the newly checked value. Choosing the checked segment again\n * does nothing, so a consumer that saves on change never writes twice.\n */\n onValueChange?: (value: string) => void;\n /** Segment height and type scale. `sm` suits a toolbar or a card header. */\n size?: SegmentGroupSize;\n /**\n * How the segments share the track. `equal` (default): every segment as\n * wide as the widest, and a word longer than its column breaks inside it.\n * `content`: each segment as wide as its own label, the spare width shared\n * out, so a group of labels of uneven length fits a narrow container\n * without breaking a word.\n */\n fit?: 'equal' | 'content';\n /**\n * `dense` tightens each segment's inline padding, for a group of many\n * short items (six t-shirt sizes) that has to fit a phone.\n */\n density?: 'default' | 'dense';\n /**\n * Whether the group takes the whole width of its row, the track with it:\n * a state or effort choice in a form, level with the fields above it.\n */\n fullWidth?: boolean;\n /**\n * A field at the end of the track for a value no segment offers. While it\n * holds a value and no segment is checked, it is drawn as the choice and\n * submits under `name`.\n */\n custom?: SegmentGroupCustom;\n /** Disable every segment. The checked one keeps showing which is set. */\n disabled?: boolean;\n /** Name for native form participation through the hidden radio inputs. */\n name?: string;\n /** Extra class names appended after the `ds-segment-group` modifiers. */\n className?: string;\n};\n\n/**\n * One choice among a few, shown as a row of segments, built on Ark UI's\n * SegmentGroup: a radio group whose radios are drawn as one control.\n *\n * Ark owns the behaviour: hidden radio inputs carry the state, the arrow keys\n * move the choice, and the whole segment is its radio's label. This wrapper\n * contributes `ds-` classes, the `--ds-segment-group-*` bindings and a flat\n * `items` API in place of Ark's anatomy.\n *\n * ```tsx\n * <SegmentGroup\n * label=\"Period\"\n * items={[\n * { value: 'today', label: 'Today' },\n * { value: 'week', label: 'Week' },\n * { value: 'month', label: 'Month' },\n * ]}\n * value={period}\n * onValueChange={setPeriod}\n * />\n * ```\n *\n * Reach for it when the choices are few, short and all worth seeing at once:\n * a period, a size, a view. More than five, or labels that need a sentence,\n * want a `Select`. Panels that change with the choice are `Tabs`; a segment\n * group changes a value, not what is on the page.\n */\nexport function SegmentGroup({\n label,\n items,\n value,\n defaultValue,\n onValueChange,\n size = 'md',\n fit = 'equal',\n density = 'default',\n fullWidth = false,\n custom,\n disabled,\n name,\n className,\n 'aria-label': ariaLabel,\n}: SegmentGroupProps) {\n const rootRef = useRef<HTMLDivElement>(null);\n\n /*\n * Zag reports `null` only when the value is cleared through its API, which\n * this wrapper never calls; a user can only move the choice to a segment.\n *\n * Ark renders the hidden radios uncontrolled and syncs them only when its\n * own state changes, so a controlled parent that declines a choice would\n * leave the native radio checked while the segment shows the old one.\n * Restoring the parent's value after Ark has read the radios keeps the two\n * agreeing, as Checkbox and Switch do.\n */\n const handleValueChange = (details: { value: string | null }) => {\n if (details.value !== null) onValueChange?.(details.value);\n if (value === undefined || !rootRef.current) return;\n for (const input of rootRef.current.querySelectorAll<HTMLInputElement>('input[type=\"radio\"]')) {\n input.checked = input.value === value;\n }\n };\n\n /*\n * Zag always names the root by its label part's id, which would outrank an\n * `aria-label`. With both given, the visible label is plain text instead,\n * so that id resolves to nothing and the `aria-label` is what is announced.\n */\n const visibleLabel =\n label &&\n (ariaLabel ? (\n <span className=\"ds-segment-group__label\">{label}</span>\n ) : (\n <ArkSegmentGroup.Label className=\"ds-segment-group__label\">{label}</ArkSegmentGroup.Label>\n ));\n\n const renderItem = (item: SegmentGroupItem) => (\n <ArkSegmentGroup.Item\n key={item.value}\n value={item.value}\n disabled={item.disabled}\n className=\"ds-segment-group__item\"\n >\n <ArkSegmentGroup.ItemText className=\"ds-segment-group__item-text\">\n {item.label}\n </ArkSegmentGroup.ItemText>\n <ArkSegmentGroup.ItemHiddenInput />\n </ArkSegmentGroup.Item>\n );\n\n /*\n * The field is the choice while it holds a value no segment has. That is\n * read from Ark's own value, so an uncontrolled group draws it right too,\n * and it submits under `name` only then, when no radio is checked.\n */\n const renderCustom = (custom: SegmentGroupCustom, current: string | null) => {\n const chosen = custom.value !== '' && !items.some((item) => item.value === current);\n return (\n <label\n className=\"ds-segment-group__custom\"\n data-state={chosen ? 'checked' : 'unchecked'}\n data-disabled={disabled ? '' : undefined}\n >\n <input\n className=\"ds-segment-group__custom-input\"\n value={custom.value}\n onChange={(event) => custom.onValueChange(event.target.value)}\n aria-label={custom['aria-label']}\n placeholder={custom.placeholder}\n inputMode={custom.inputMode}\n name={chosen ? name : undefined}\n disabled={disabled}\n />\n {custom.unit && (\n <span className=\"ds-segment-group__custom-unit\" aria-hidden=\"true\">\n {custom.unit}\n </span>\n )}\n </label>\n );\n };\n\n return (\n <ArkSegmentGroup.Root\n ref={rootRef}\n className={cx(\n 'ds-segment-group',\n `ds-segment-group--${size}`,\n fit === 'content' && 'ds-segment-group--fit-content',\n density === 'dense' && 'ds-segment-group--dense',\n fullWidth && 'ds-segment-group--full-width',\n className,\n )}\n value={value}\n defaultValue={defaultValue}\n onValueChange={handleValueChange}\n disabled={disabled}\n name={name}\n orientation=\"horizontal\"\n aria-label={ariaLabel}\n >\n {visibleLabel}\n <div className=\"ds-segment-group__track\">\n {items.map(renderItem)}\n {custom && (\n <ArkSegmentGroup.Context>\n {(group) => renderCustom(custom, group.value)}\n </ArkSegmentGroup.Context>\n )}\n </div>\n </ArkSegmentGroup.Root>\n );\n}\n"]}
1
+ {"version":3,"file":"segment-group.js","sourceRoot":"","sources":["../../src/segment-group/segment-group.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,IAAI,eAAe,EAAE,MAAM,6BAA6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,YAAY,gBACZ,SAAS,aAEpB,YAAY,EACb,eAAK,SAAS,EAAC,yBAAyB,aACrC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,EACrB,MAAM,IAAI,CACT,KAAC,eAAe,CAAC,OAAO,cACrB,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,GACrB,CAC3B,IACG,IACe,CACxB,CAAC;AACJ,CAAC","sourcesContent":["import { SegmentGroup as ArkSegmentGroup } from '@ark-ui/react/segment-group';\nimport { type ReactNode, useRef } from 'react';\nimport './segment-group.css';\nimport { radioGroupChangeHandler, renderVisibleLabel } from '../ark-native-input';\nimport { cx } from '../cx';\n\nexport type SegmentGroupSize = 'sm' | 'md';\n\nexport interface SegmentGroupItem {\n /** Stable value reported by `onValueChange` and compared with `value`. */\n value: string;\n /** Text shown on the segment. Keep it to a word or two; a longer one wraps inside its segment. */\n label: string;\n /** Individually disable this choice without removing it. */\n disabled?: boolean;\n}\n\n/**\n * A value typed beside the segments, for one no segment offers: the minutes\n * of a duration whose presets are 30 minutes and an hour. The consumer owns\n * both values and keeps them agreeing: a typed value that matches a segment\n * checks that segment, and choosing a segment fills the field with its value.\n */\nexport interface SegmentGroupCustom {\n /** What the field holds, `''` when empty. */\n value: string;\n /** Fired with the field's text on every change. */\n onValueChange: (value: string) => void;\n /** The field's accessible name (\"Duration in minutes\"); it has no visible label of its own. */\n 'aria-label': string;\n /** Shown while the field is empty. */\n placeholder?: string;\n /** A unit written after the value, such as `min`. Decorative: put the unit in `aria-label` too. */\n unit?: string;\n /** The keyboard a phone shows for the field. */\n inputMode?: 'numeric' | 'decimal' | 'text';\n}\n\n/**\n * A segment group has to have a name. A visible `label` is the one to reach\n * for; expressed as a union so an unnamed group is a compile error rather\n * than an axe finding, as `Checkbox` and `Switch` do.\n */\ntype SegmentGroupName =\n | {\n /** Visible label, rendered above the track and naming the group. */\n label: ReactNode;\n /**\n * A different accessible name when the visible label alone would not\n * say what the choice is. Keep the visible words in it (\"Period\" →\n * \"Reporting period\"), so a voice user can still say what they see.\n */\n 'aria-label'?: string;\n }\n | {\n label?: undefined;\n /** Accessible name when the surrounding heading or row already says what the choice is. */\n 'aria-label': string;\n };\n\nexport type SegmentGroupProps = SegmentGroupName & {\n /** The choices, in order. Exactly one is checked. */\n items: SegmentGroupItem[];\n /**\n * Controlled value. `null` is controlled with nothing checked, for a form\n * that starts without a choice; `undefined` leaves the component to own\n * its value from `defaultValue` onward, as `Select` does.\n */\n value?: string | null;\n /** Initial value when uncontrolled. */\n defaultValue?: string;\n /**\n * Fired with the newly checked value. Choosing the checked segment again\n * does nothing, so a consumer that saves on change never writes twice.\n */\n onValueChange?: (value: string) => void;\n /** Segment height and type scale. `sm` suits a toolbar or a card header. */\n size?: SegmentGroupSize;\n /**\n * How the segments share the track. `equal` (default): every segment as\n * wide as the widest, and a word longer than its column breaks inside it.\n * `content`: each segment as wide as its own label, the spare width shared\n * out, so a group of labels of uneven length fits a narrow container\n * without breaking a word.\n */\n fit?: 'equal' | 'content';\n /**\n * `dense` tightens each segment's inline padding, for a group of many\n * short items (six t-shirt sizes) that has to fit a phone.\n */\n density?: 'default' | 'dense';\n /**\n * Whether the group takes the whole width of its row, the track with it:\n * a state or effort choice in a form, level with the fields above it.\n */\n fullWidth?: boolean;\n /**\n * A field at the end of the track for a value no segment offers. While it\n * holds a value and no segment is checked, it is drawn as the choice and\n * submits under `name`.\n */\n custom?: SegmentGroupCustom;\n /** Disable every segment. The checked one keeps showing which is set. */\n disabled?: boolean;\n /** Name for native form participation through the hidden radio inputs. */\n name?: string;\n /** Extra class names appended after the `ds-segment-group` modifiers. */\n className?: string;\n};\n\n/**\n * One choice among a few, shown as a row of segments, built on Ark UI's\n * SegmentGroup: a radio group whose radios are drawn as one control.\n *\n * Ark owns the behaviour: hidden radio inputs carry the state, the arrow keys\n * move the choice, and the whole segment is its radio's label. This wrapper\n * contributes `ds-` classes, the `--ds-segment-group-*` bindings and a flat\n * `items` API in place of Ark's anatomy.\n *\n * ```tsx\n * <SegmentGroup\n * label=\"Period\"\n * items={[\n * { value: 'today', label: 'Today' },\n * { value: 'week', label: 'Week' },\n * { value: 'month', label: 'Month' },\n * ]}\n * value={period}\n * onValueChange={setPeriod}\n * />\n * ```\n *\n * Reach for it when the choices are few, short and all worth seeing at once:\n * a period, a size, a view. More than five, or labels that need a sentence,\n * want a `Select`. Panels that change with the choice are `Tabs`; a segment\n * group changes a value, not what is on the page.\n */\nexport function SegmentGroup({\n label,\n items,\n value,\n defaultValue,\n onValueChange,\n size = 'md',\n fit = 'equal',\n density = 'default',\n fullWidth = false,\n custom,\n disabled,\n name,\n className,\n 'aria-label': ariaLabel,\n}: SegmentGroupProps) {\n const rootRef = useRef<HTMLDivElement>(null);\n\n const handleValueChange = radioGroupChangeHandler(rootRef, value, onValueChange);\n\n const visibleLabel = renderVisibleLabel(ArkSegmentGroup.Label, {\n label,\n ariaLabel,\n className: 'ds-segment-group__label',\n });\n\n const renderItem = (item: SegmentGroupItem) => (\n <ArkSegmentGroup.Item\n key={item.value}\n value={item.value}\n disabled={item.disabled}\n className=\"ds-segment-group__item\"\n >\n <ArkSegmentGroup.ItemText className=\"ds-segment-group__item-text\">\n {item.label}\n </ArkSegmentGroup.ItemText>\n <ArkSegmentGroup.ItemHiddenInput />\n </ArkSegmentGroup.Item>\n );\n\n /*\n * The field is the choice while it holds a value no segment has. That is\n * read from Ark's own value, so an uncontrolled group draws it right too,\n * and it submits under `name` only then, when no radio is checked.\n */\n const renderCustom = (custom: SegmentGroupCustom, current: string | null) => {\n const chosen = custom.value !== '' && !items.some((item) => item.value === current);\n return (\n <label\n className=\"ds-segment-group__custom\"\n data-state={chosen ? 'checked' : 'unchecked'}\n data-disabled={disabled ? '' : undefined}\n >\n <input\n className=\"ds-segment-group__custom-input\"\n value={custom.value}\n onChange={(event) => custom.onValueChange(event.target.value)}\n aria-label={custom['aria-label']}\n placeholder={custom.placeholder}\n inputMode={custom.inputMode}\n name={chosen ? name : undefined}\n disabled={disabled}\n />\n {custom.unit && (\n <span className=\"ds-segment-group__custom-unit\" aria-hidden=\"true\">\n {custom.unit}\n </span>\n )}\n </label>\n );\n };\n\n return (\n <ArkSegmentGroup.Root\n ref={rootRef}\n className={cx(\n 'ds-segment-group',\n `ds-segment-group--${size}`,\n fit === 'content' && 'ds-segment-group--fit-content',\n density === 'dense' && 'ds-segment-group--dense',\n fullWidth && 'ds-segment-group--full-width',\n className,\n )}\n value={value}\n defaultValue={defaultValue}\n onValueChange={handleValueChange}\n disabled={disabled}\n name={name}\n orientation=\"horizontal\"\n aria-label={ariaLabel}\n >\n {visibleLabel}\n <div className=\"ds-segment-group__track\">\n {items.map(renderItem)}\n {custom && (\n <ArkSegmentGroup.Context>\n {(group) => renderCustom(custom, group.value)}\n </ArkSegmentGroup.Context>\n )}\n </div>\n </ArkSegmentGroup.Root>\n );\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"switch.d.ts","sourceRoot":"","sources":["../../src/switch/switch.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAiB,MAAM,OAAO,CAAC;AACtD,OAAO,cAAc,CAAC;AAGtB,MAAM,MAAM,UAAU,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE5C,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,KAAK,CAAC;AAEnD;;;;;GAKG;AACH,KAAK,UAAU,GACX;IACE,0DAA0D;IAC1D,KAAK,EAAE,SAAS,CAAC;IACjB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GACD;IACE,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,kHAAkH;IAClH,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEN,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG;IACrC;;;;OAIG;IACH,cAAc,CAAC,EAAE,oBAAoB,CAAC;IACtC,6EAA6E;IAC7E,OAAO,CAAC,EAAE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7 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Switch as ArkSwitch } from '@ark-ui/react/switch';
3
- import { useId, useRef } from 'react';
3
+ import { useRef } from 'react';
4
4
  import './switch.css';
5
+ import { renderVisibleLabel, restoreNativeInputs, useOwnCheckableIds } from '../ark-native-input';
5
6
  import { cx } from '../cx';
6
7
  /**
7
8
  * On/off control for a setting that takes effect at once, built on Ark UI.
@@ -22,31 +23,17 @@ import { cx } from '../cx';
22
23
  * or a segmented control.
23
24
  */
24
25
  export function Switch({ label, labelPlacement = 'end', checked, defaultChecked, onCheckedChange, size = 'md', disabled, invalid, readOnly, required, name, value, className, 'aria-label': ariaLabel, 'aria-describedby': ariaDescribedBy, }) {
25
- /*
26
- * Zag always names the hidden input by its label part's id, which would
27
- * outrank an `aria-label`. With both given, the visible label is plain
28
- * text instead, so that id resolves to nothing and the `aria-label` wins;
29
- * the root is still the `<label>`, so the text stays the click target.
30
- */
31
- const labelNode = label ? (ariaLabel ? (_jsx("span", { className: "ds-switch__label", children: label })) : (_jsx(ArkSwitch.Label, { className: "ds-switch__label", children: label }))) : null;
32
- const inputRef = useRef(null);
33
- // Own ids, as Checkbox: a switch names itself, and two switches in one
34
- // Field must not share the field's control id.
35
- const ownId = useId();
36
- const ids = { hiddenInput: `${ownId}:input`, label: `${ownId}:label` };
37
- /*
38
- * Ark renders the hidden input uncontrolled (`defaultChecked`) and syncs it
39
- * only when its own state changes. A controlled parent that declines a
40
- * toggle therefore leaves the native input flipped while the control shows
41
- * the old state, and assistive tech reads the input. Ark reports the toggle
42
- * after reading the input, so restoring the parent's value here is safe:
43
- * a parent that accepts re-renders, and Ark syncs the input again.
44
- */
26
+ const labelNode = renderVisibleLabel(ArkSwitch.Label, {
27
+ label,
28
+ ariaLabel,
29
+ className: 'ds-switch__label',
30
+ });
31
+ const rootRef = useRef(null);
32
+ const ids = useOwnCheckableIds();
45
33
  const handleCheckedChange = (details) => {
46
34
  onCheckedChange?.(details.checked);
47
- if (checked !== undefined && inputRef.current)
48
- inputRef.current.checked = checked;
35
+ restoreNativeInputs(rootRef.current, checked);
49
36
  };
50
- return (_jsxs(ArkSwitch.Root, { ids: ids, className: cx('ds-switch', `ds-switch--${size}`, className), checked: checked, defaultChecked: defaultChecked, onCheckedChange: handleCheckedChange, disabled: disabled, invalid: invalid, readOnly: readOnly, required: required, name: name, value: value, children: [labelPlacement === 'start' && labelNode, _jsx(ArkSwitch.Control, { className: "ds-switch__control", children: _jsx(ArkSwitch.Thumb, { className: "ds-switch__thumb" }) }), labelPlacement === 'end' && labelNode, _jsx(ArkSwitch.HiddenInput, { ref: inputRef, role: "switch", "aria-label": ariaLabel, "aria-describedby": ariaDescribedBy, "aria-readonly": readOnly || undefined })] }));
37
+ return (_jsxs(ArkSwitch.Root, { ref: rootRef, ids: ids, className: cx('ds-switch', `ds-switch--${size}`, className), checked: checked, defaultChecked: defaultChecked, onCheckedChange: handleCheckedChange, disabled: disabled, invalid: invalid, readOnly: readOnly, required: required, name: name, value: value, children: [labelPlacement === 'start' && labelNode, _jsx(ArkSwitch.Control, { className: "ds-switch__control", children: _jsx(ArkSwitch.Thumb, { className: "ds-switch__thumb" }) }), labelPlacement === 'end' && labelNode, _jsx(ArkSwitch.HiddenInput, { role: "switch", "aria-label": ariaLabel, "aria-describedby": ariaDescribedBy, "aria-readonly": readOnly || undefined })] }));
51
38
  }
52
39
  //# sourceMappingURL=switch.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"switch.js","sourceRoot":"","sources":["../../src/switch/switch.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAkB,KAAK,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAkE3B;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,U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mBAAmB,EACpC,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,KAAK,aAEX,cAAc,KAAK,OAAO,IAAI,SAAS,EACxC,KAAC,SAAS,CAAC,OAAO,IAAC,SAAS,EAAC,oBAAoB,YAC/C,KAAC,SAAS,CAAC,KAAK,IAAC,SAAS,EAAC,kBAAkB,GAAG,GAC9B,EACnB,cAAc,KAAK,KAAK,IAAI,SAAS,EACtC,KAAC,SAAS,CAAC,WAAW,IACpB,GAAG,EAAE,QAAQ,EACb,IAAI,EAAC,QAAQ,gBACD,SAAS,sBACH,eAAe,mBAClB,QAAQ,IAAI,SAAS,GACpC,IACa,CAClB,CAAC;AACJ,CAAC","sourcesContent":["import { Switch as ArkSwitch } from '@ark-ui/react/switch';\nimport { type ReactNode, useId, useRef } from 'react';\nimport './switch.css';\nimport { cx } from '../cx';\n\nexport type SwitchSize = 'sm' | 'md' | 'lg';\n\nexport type SwitchLabelPlacement = 'start' | 'end';\n\n/**\n * A switch has to have a name. A visible `label` is the one to reach for: the\n * whole label is the click target, so it also enlarges the hit area. Expressed\n * as a union so an unnamed switch is a compile error rather than an axe\n * finding, the way `IconProps` pairs label and decorative.\n */\ntype SwitchName =\n | {\n /** Visible label. The whole label is the click target. */\n label: ReactNode;\n /**\n * A different accessible name when the visible label alone would not\n * say what the control is. Keep the visible words in it, so a voice\n * user can still say what they see.\n */\n 'aria-label'?: string;\n }\n | {\n label?: undefined;\n /** Accessible name when no visible label fits, such as a table cell whose row already says what the switch is. */\n 'aria-label': string;\n };\n\nexport type SwitchProps = SwitchName & {\n /**\n * Which side of the control the label sits on. `end` (default) reads\n * \"control, then what it does\"; `start` puts the label first, for a\n * settings row. Only the order changes; the row's layout is the caller's.\n */\n labelPlacement?: SwitchLabelPlacement;\n /** Controlled checked state. Leave undefined to let the component own it. */\n checked?: boolean;\n /** Initial state when uncontrolled. */\n defaultChecked?: boolean;\n /** Fired with the new state whenever the user toggles the switch. */\n onCheckedChange?: (checked: boolean) => void;\n /** Control size and label type scale. */\n size?: SwitchSize;\n /** Disable the control. It keeps its state and stops responding. */\n disabled?: boolean;\n /**\n * Marks the control invalid for assistive tech and styling (`data-invalid`).\n * Pair it with a message the control points at through `aria-describedby`;\n * a red border alone is not an accessible error.\n */\n invalid?: boolean;\n /** Id of the element that describes the control, such as an error message. */\n 'aria-describedby'?: string;\n /** Show the state without letting the user change it. */\n readOnly?: boolean;\n /** Marks the hidden input required for native form validation. */\n required?: boolean;\n /** Name for native form participation. */\n name?: string;\n /** Value submitted under `name` while checked. Defaults to `on`. */\n value?: string;\n /** Extra class names appended after the `ds-switch` modifiers. */\n className?: string;\n};\n\n/**\n * On/off control for a setting that takes effect at once, built on Ark UI.\n *\n * Ark owns the behaviour: a hidden checkbox carries the checked state, the\n * root is the `<label>` that names it, and keyboard (Space) and pointer\n * toggling come for free. The input is given `role=\"switch\"` and\n * `aria-readonly` here, which Ark leaves off, so it is announced as a switch\n * rather than a checkbox, and a read-only one says so. This wrapper contributes `ds-`\n * classes, the `--ds-switch-*` bindings, and a flat prop API.\n *\n * ```tsx\n * <Switch label=\"Gap view\" checked={gapView} onCheckedChange={setGapView} />\n * ```\n *\n * A switch is for a setting that applies immediately. A choice that is only\n * saved on submit is a checkbox; a choice between several values is a select\n * or a segmented control.\n */\nexport function Switch({\n label,\n labelPlacement = 'end',\n checked,\n defaultChecked,\n onCheckedChange,\n size = 'md',\n disabled,\n invalid,\n readOnly,\n required,\n name,\n value,\n className,\n 'aria-label': ariaLabel,\n 'aria-describedby': ariaDescribedBy,\n}: SwitchProps) {\n /*\n * Zag always names the hidden input by its label part's id, which would\n * outrank an `aria-label`. With both given, the visible label is plain\n * text instead, so that id resolves to nothing and the `aria-label` wins;\n * the root is still the `<label>`, so the text stays the click target.\n */\n const labelNode = label ? (\n ariaLabel ? (\n <span className=\"ds-switch__label\">{label}</span>\n ) : (\n <ArkSwitch.Label className=\"ds-switch__label\">{label}</ArkSwitch.Label>\n )\n ) : null;\n\n const inputRef = useRef<HTMLInputElement>(null);\n\n // Own ids, as Checkbox: a switch names itself, and two switches in one\n // Field must not share the field's control id.\n const ownId = useId();\n const ids = { hiddenInput: `${ownId}:input`, label: `${ownId}:label` };\n\n /*\n * Ark renders the hidden input uncontrolled (`defaultChecked`) and syncs it\n * only when its own state changes. A controlled parent that declines a\n * toggle therefore leaves the native input flipped while the control shows\n * the old state, and assistive tech reads the input. Ark reports the toggle\n * after reading the input, so restoring the parent's value here is safe:\n * a parent that accepts re-renders, and Ark syncs the input again.\n */\n const handleCheckedChange = (details: { checked: boolean }) => {\n onCheckedChange?.(details.checked);\n if (checked !== undefined && inputRef.current) inputRef.current.checked = checked;\n };\n\n return (\n <ArkSwitch.Root\n ids={ids}\n className={cx('ds-switch', `ds-switch--${size}`, className)}\n checked={checked}\n defaultChecked={defaultChecked}\n onCheckedChange={handleCheckedChange}\n disabled={disabled}\n invalid={invalid}\n readOnly={readOnly}\n required={required}\n name={name}\n value={value}\n >\n {labelPlacement === 'start' && labelNode}\n <ArkSwitch.Control className=\"ds-switch__control\">\n <ArkSwitch.Thumb className=\"ds-switch__thumb\" />\n </ArkSwitch.Control>\n {labelPlacement === 'end' && labelNode}\n <ArkSwitch.HiddenInput\n ref={inputRef}\n role=\"switch\"\n aria-label={ariaLabel}\n aria-describedby={ariaDescribedBy}\n aria-readonly={readOnly || undefined}\n />\n </ArkSwitch.Root>\n );\n}\n"]}
1
+ {"version":3,"file":"switch.js","sourceRoot":"","sources":["../../src/switch/switch.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAkB,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,kBAAkB,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CAAC,OAAO,IAAC,SAAS,EAAC,oBAAoB,YAC/C,KAAC,SAAS,CAAC,KAAK,IAAC,SAAS,EAAC,kBAAkB,GAAG,GAC9B,EACnB,cAAc,KAAK,KAAK,IAAI,SAAS,EACtC,KAAC,SAAS,CAAC,WAAW,IACpB,IAAI,EAAC,QAAQ,gBACD,SAAS,sBACH,eAAe,mBAClB,QAAQ,IAAI,SAAS,GACpC,IACa,CAClB,CAAC;AACJ,CAAC","sourcesContent":["import { Switch as ArkSwitch } from '@ark-ui/react/switch';\nimport { type ReactNode, useRef } from 'react';\nimport './switch.css';\nimport { renderVisibleLabel, restoreNativeInputs, useOwnCheckableIds } from '../ark-native-input';\nimport { cx } from '../cx';\n\nexport type SwitchSize = 'sm' | 'md' | 'lg';\n\nexport type SwitchLabelPlacement = 'start' | 'end';\n\n/**\n * A switch has to have a name. A visible `label` is the one to reach for: the\n * whole label is the click target, so it also enlarges the hit area. Expressed\n * as a union so an unnamed switch is a compile error rather than an axe\n * finding, the way `IconProps` pairs label and decorative.\n */\ntype SwitchName =\n | {\n /** Visible label. The whole label is the click target. */\n label: ReactNode;\n /**\n * A different accessible name when the visible label alone would not\n * say what the control is. Keep the visible words in it, so a voice\n * user can still say what they see.\n */\n 'aria-label'?: string;\n }\n | {\n label?: undefined;\n /** Accessible name when no visible label fits, such as a table cell whose row already says what the switch is. */\n 'aria-label': string;\n };\n\nexport type SwitchProps = SwitchName & {\n /**\n * Which side of the control the label sits on. `end` (default) reads\n * \"control, then what it does\"; `start` puts the label first, for a\n * settings row. Only the order changes; the row's layout is the caller's.\n */\n labelPlacement?: SwitchLabelPlacement;\n /** Controlled checked state. Leave undefined to let the component own it. */\n checked?: boolean;\n /** Initial state when uncontrolled. */\n defaultChecked?: boolean;\n /** Fired with the new state whenever the user toggles the switch. */\n onCheckedChange?: (checked: boolean) => void;\n /** Control size and label type scale. */\n size?: SwitchSize;\n /** Disable the control. It keeps its state and stops responding. */\n disabled?: boolean;\n /**\n * Marks the control invalid for assistive tech and styling (`data-invalid`).\n * Pair it with a message the control points at through `aria-describedby`;\n * a red border alone is not an accessible error.\n */\n invalid?: boolean;\n /** Id of the element that describes the control, such as an error message. */\n 'aria-describedby'?: string;\n /** Show the state without letting the user change it. */\n readOnly?: boolean;\n /** Marks the hidden input required for native form validation. */\n required?: boolean;\n /** Name for native form participation. */\n name?: string;\n /** Value submitted under `name` while checked. Defaults to `on`. */\n value?: string;\n /** Extra class names appended after the `ds-switch` modifiers. */\n className?: string;\n};\n\n/**\n * On/off control for a setting that takes effect at once, built on Ark UI.\n *\n * Ark owns the behaviour: a hidden checkbox carries the checked state, the\n * root is the `<label>` that names it, and keyboard (Space) and pointer\n * toggling come for free. The input is given `role=\"switch\"` and\n * `aria-readonly` here, which Ark leaves off, so it is announced as a switch\n * rather than a checkbox, and a read-only one says so. This wrapper contributes `ds-`\n * classes, the `--ds-switch-*` bindings, and a flat prop API.\n *\n * ```tsx\n * <Switch label=\"Gap view\" checked={gapView} onCheckedChange={setGapView} />\n * ```\n *\n * A switch is for a setting that applies immediately. A choice that is only\n * saved on submit is a checkbox; a choice between several values is a select\n * or a segmented control.\n */\nexport function Switch({\n label,\n labelPlacement = 'end',\n checked,\n defaultChecked,\n onCheckedChange,\n size = 'md',\n disabled,\n invalid,\n readOnly,\n required,\n name,\n value,\n className,\n 'aria-label': ariaLabel,\n 'aria-describedby': ariaDescribedBy,\n}: SwitchProps) {\n const labelNode = renderVisibleLabel(ArkSwitch.Label, {\n label,\n ariaLabel,\n className: 'ds-switch__label',\n });\n\n const rootRef = useRef<HTMLLabelElement>(null);\n\n const ids = useOwnCheckableIds();\n\n const handleCheckedChange = (details: { checked: boolean }) => {\n onCheckedChange?.(details.checked);\n restoreNativeInputs(rootRef.current, checked);\n };\n\n return (\n <ArkSwitch.Root\n ref={rootRef}\n ids={ids}\n className={cx('ds-switch', `ds-switch--${size}`, className)}\n checked={checked}\n defaultChecked={defaultChecked}\n onCheckedChange={handleCheckedChange}\n disabled={disabled}\n invalid={invalid}\n readOnly={readOnly}\n required={required}\n name={name}\n value={value}\n >\n {labelPlacement === 'start' && labelNode}\n <ArkSwitch.Control className=\"ds-switch__control\">\n <ArkSwitch.Thumb className=\"ds-switch__thumb\" />\n </ArkSwitch.Control>\n {labelPlacement === 'end' && labelNode}\n <ArkSwitch.HiddenInput\n role=\"switch\"\n aria-label={ariaLabel}\n aria-describedby={ariaDescribedBy}\n aria-readonly={readOnly || undefined}\n />\n </ArkSwitch.Root>\n );\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export type { TableActionsCellProps, TableAlign, TableBodyProps, TableCellProps, TableEmptyProps, TableFootProps, TableHeaderCellProps, TableHeadProps, TableProps, TableRowProps, TableSort, TableToolbarProps, } from './table';
2
+ export { Table, TableActionsCell, TableBody, TableCell, TableEmpty, TableFoot, TableHead, TableHeaderCell, TableRow, TableToolbar, } from './table';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/table/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,qBAAqB,EACrB,UAAU,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,cAAc,EACd,oBAAoB,EACpB,cAAc,EACd,UAAU,EACV,aAAa,EACb,SAAS,EACT,iBAAiB,GAClB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,KAAK,EACL,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,UAAU,EACV,SAAS,EACT,SAAS,EACT,eAAe,EACf,QAAQ,EACR,YAAY,GACb,MAAM,SAAS,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { Table, TableActionsCell, TableBody, TableCell, TableEmpty, TableFoot, TableHead, TableHeaderCell, TableRow, TableToolbar, } from './table';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/table/index.ts"],"names":[],"mappings":"AAcA,OAAO,EACL,KAAK,EACL,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,UAAU,EACV,SAAS,EACT,SAAS,EACT,eAAe,EACf,QAAQ,EACR,YAAY,GACb,MAAM,SAAS,CAAC","sourcesContent":["export type {\n TableActionsCellProps,\n TableAlign,\n TableBodyProps,\n TableCellProps,\n TableEmptyProps,\n TableFootProps,\n TableHeaderCellProps,\n TableHeadProps,\n TableProps,\n TableRowProps,\n TableSort,\n TableToolbarProps,\n} from './table';\nexport {\n Table,\n TableActionsCell,\n TableBody,\n TableCell,\n TableEmpty,\n TableFoot,\n TableHead,\n TableHeaderCell,\n TableRow,\n TableToolbar,\n} from './table';\n"]}
@@ -0,0 +1,189 @@
1
+ @layer components {
2
+ .ds-table {
3
+ display: flex;
4
+ flex-direction: column;
5
+ gap: var(--ds-layout-gap);
6
+ min-width: 0;
7
+ color: var(--ds-table-text);
8
+ overflow-wrap: anywhere;
9
+
10
+ & .ds-table__toolbar {
11
+ display: flex;
12
+ flex-wrap: wrap;
13
+ align-items: center;
14
+ gap: var(--ds-layout-gap);
15
+ }
16
+
17
+ & .ds-table__toolbar-start {
18
+ display: flex;
19
+ flex-wrap: wrap;
20
+ align-items: center;
21
+ gap: var(--ds-layout-gap);
22
+ min-width: 0;
23
+ }
24
+
25
+ /* The actions keep to the end of the row whether or not a start slot is there. */
26
+ & .ds-table__toolbar-actions {
27
+ display: flex;
28
+ flex-wrap: wrap;
29
+ align-items: center;
30
+ gap: var(--ds-layout-gap);
31
+ margin-inline-start: auto;
32
+ }
33
+
34
+ & .ds-table__scroll {
35
+ border: 1px solid var(--ds-table-border);
36
+ border-radius: var(--ds-table-radius);
37
+ background-color: var(--ds-table-bg);
38
+ }
39
+
40
+ /*
41
+ * Words stay whole inside a table: a column too narrow for its longest
42
+ * word widens and the table scrolls sideways, which the long-words rule
43
+ * allows a sideways scroller, rather than breaking an id or an amount
44
+ * letter by letter.
45
+ */
46
+ & .ds-table__table {
47
+ width: 100%;
48
+ border-collapse: collapse;
49
+ font-size: var(--ds-table-font-size);
50
+ overflow-wrap: normal;
51
+ }
52
+
53
+ & .ds-table__header-cell,
54
+ & .ds-table__cell {
55
+ padding-block: var(--ds-table-cell-padding-block);
56
+ padding-inline: var(--ds-table-cell-padding-inline);
57
+ text-align: start;
58
+ vertical-align: middle;
59
+ }
60
+
61
+ /* The column heads are labels: the product's small-caps label style. */
62
+ & .ds-table__header-cell {
63
+ border-block-end: 1px solid var(--ds-table-border);
64
+ background-color: var(--ds-table-header-bg);
65
+ color: var(--ds-table-text-muted);
66
+ font-family: var(--ds-text-caps-font-family);
67
+ font-size: var(--ds-text-size-xs-font-size);
68
+ font-weight: var(--ds-text-caps-font-weight);
69
+ line-height: var(--ds-text-size-xs-line-height);
70
+ letter-spacing: var(--ds-text-caps-letter-spacing);
71
+ text-transform: uppercase;
72
+ }
73
+
74
+ & .ds-table__header-content {
75
+ display: inline-flex;
76
+ align-items: center;
77
+ gap: var(--ds-layout-gap-tight);
78
+ max-width: 100%;
79
+ }
80
+
81
+ & .ds-table__sort {
82
+ display: inline-flex;
83
+ align-items: center;
84
+ gap: var(--ds-layout-gap-tight);
85
+ max-width: 100%;
86
+ padding: 0;
87
+ border: 0;
88
+ background-color: transparent;
89
+ color: inherit;
90
+ font: inherit;
91
+ letter-spacing: inherit;
92
+ text-align: inherit;
93
+ text-transform: inherit;
94
+ cursor: pointer;
95
+
96
+ &:hover,
97
+ &[data-sort="ascending"],
98
+ &[data-sort="descending"] {
99
+ color: var(--ds-table-text);
100
+ }
101
+
102
+ &:focus-visible {
103
+ outline: 2px solid var(--ds-table-focus-ring);
104
+ outline-offset: 2px;
105
+ }
106
+ }
107
+
108
+ /*
109
+ * One glyph, the product's right chevron, turned to point up for
110
+ * ascending and down for descending. An unsorted sortable column shows
111
+ * both, at three-quarter size, so it reads as sortable before it is pressed.
112
+ */
113
+ & .ds-table__sort-indicator {
114
+ display: inline-grid;
115
+ place-items: center;
116
+ color: var(--ds-table-text-muted);
117
+
118
+ & > * {
119
+ grid-area: 1 / 1;
120
+ }
121
+ }
122
+
123
+ & .ds-table__sort[data-sort="ascending"] .ds-table__sort-indicator > * {
124
+ transform: rotate(-90deg);
125
+ }
126
+
127
+ & .ds-table__sort[data-sort="descending"] .ds-table__sort-indicator > * {
128
+ transform: rotate(90deg);
129
+ }
130
+
131
+ & .ds-table__sort[data-sort="none"] .ds-table__sort-indicator {
132
+ & > :first-child {
133
+ transform: translateY(-30%) rotate(-90deg) scale(0.75);
134
+ }
135
+
136
+ & > :last-child {
137
+ transform: translateY(30%) rotate(90deg) scale(0.75);
138
+ }
139
+ }
140
+
141
+ & .ds-table__cell--end {
142
+ text-align: end;
143
+ }
144
+
145
+ /* Figures line up digit under digit; a number never breaks across lines in the sideways scroller. */
146
+ & .ds-table__cell--numeric {
147
+ font-variant-numeric: tabular-nums;
148
+ white-space: nowrap;
149
+ }
150
+
151
+ & .ds-table__cell--row-header {
152
+ font-weight: inherit;
153
+ }
154
+
155
+ /* As narrow as its buttons, at the end of the row. */
156
+ & .ds-table__cell--actions {
157
+ width: 1%;
158
+ text-align: end;
159
+ white-space: nowrap;
160
+ }
161
+
162
+ & .ds-table__actions {
163
+ display: inline-flex;
164
+ align-items: center;
165
+ gap: var(--ds-layout-gap-tight);
166
+ }
167
+
168
+ & .ds-table__body .ds-table__row + .ds-table__row {
169
+ border-block-start: 1px solid var(--ds-table-border);
170
+ }
171
+
172
+ &.ds-table--striped .ds-table__body .ds-table__row:nth-child(even) {
173
+ background-color: var(--ds-table-row-bg-striped);
174
+ }
175
+
176
+ /*
177
+ * A layer over the row's own fill rather than a replacement for it, so a
178
+ * translucent highlight tints a striped row instead of matching its stripe.
179
+ */
180
+ &.ds-table--row-hover .ds-table__body .ds-table__row:not(.ds-table__empty):hover {
181
+ background-image: linear-gradient(var(--ds-table-row-bg-hover), var(--ds-table-row-bg-hover));
182
+ }
183
+
184
+ & .ds-table__foot {
185
+ border-block-start: 1px solid var(--ds-table-border);
186
+ font-weight: var(--ds-table-footer-font-weight);
187
+ }
188
+ }
189
+ }
@@ -0,0 +1,2 @@
1
+ /* AUTOGENERATED: types for the stylesheet beside it. */
2
+ export {};
@@ -0,0 +1,144 @@
1
+ import { type ComponentProps, type ReactNode } from 'react';
2
+ import './table.css';
3
+ /** Where a column's content sits: text at the start, numbers at the end. */
4
+ export type TableAlign = 'start' | 'end';
5
+ /** A sortable column's state. `none` is sortable but not the sort in force. */
6
+ export type TableSort = 'ascending' | 'descending' | 'none';
7
+ export interface TableProps extends ComponentProps<'div'> {
8
+ /**
9
+ * The table's name, required: it names the table for a screen reader and
10
+ * the scroll region around it, which takes keyboard focus so a table wider
11
+ * than its column can be scrolled with the arrow keys.
12
+ */
13
+ label: string;
14
+ /** Tint every other body row, so a long row is easier to follow across. */
15
+ striped?: boolean;
16
+ /**
17
+ * Highlight the body row under the pointer, to read it across or compare
18
+ * it with its neighbours. Not a sign that the row is clickable: a row that
19
+ * opens something puts a link in its first cell.
20
+ */
21
+ rowHover?: boolean;
22
+ /**
23
+ * What sits above the table: a {@link TableToolbar} with the table's
24
+ * actions (add a row, history), and optionally a search or filter at its
25
+ * start.
26
+ */
27
+ toolbar?: ReactNode;
28
+ /** The rows are loading: marks the table busy while skeleton rows stand in. */
29
+ busy?: boolean;
30
+ }
31
+ /**
32
+ * Rows and columns of data in a real `<table>`, so a screen reader can move
33
+ * by row and column and announce each cell's column.
34
+ *
35
+ * A structural primitive, styled against the `--ds-table-*` contract. It
36
+ * holds no data and no sorting of its own: the product passes the rows in
37
+ * the order it wants and owns the sort and filter state, which on a server-
38
+ * paged list is the only place it can live.
39
+ *
40
+ * Compose with {@link TableHead}, {@link TableBody} and {@link TableFoot},
41
+ * made of {@link TableRow}s holding {@link TableHeaderCell}s and
42
+ * {@link TableCell}s; {@link TableActionsCell} holds a row's icon buttons and
43
+ * {@link TableEmpty} stands in for the rows when there are none.
44
+ *
45
+ * The table scrolls sideways inside its box when its columns don't fit, so a
46
+ * phone keeps every column instead of squeezing them. `className` and the
47
+ * other props go to that box, which holds the toolbar and the table.
48
+ */
49
+ export declare function Table({ label, striped, rowHover, toolbar, busy, className, children, ...props }: TableProps): import("react/jsx-runtime").JSX.Element;
50
+ export interface TableToolbarProps extends ComponentProps<'div'> {
51
+ /** What sits at the start of the row: a search or a filter for the whole table. */
52
+ start?: ReactNode;
53
+ }
54
+ /**
55
+ * The row above a table: its actions at the end (add a row, history,
56
+ * export), and optionally a search or filter at the start. Pass it to
57
+ * {@link Table}'s `toolbar`.
58
+ */
59
+ export declare function TableToolbar({ start, className, children, ...props }: TableToolbarProps): import("react/jsx-runtime").JSX.Element;
60
+ export type TableHeadProps = ComponentProps<'thead'>;
61
+ /** The column heads: a {@link TableRow} of {@link TableHeaderCell}s. */
62
+ export declare function TableHead({ className, children, ...props }: TableHeadProps): import("react/jsx-runtime").JSX.Element;
63
+ export type TableBodyProps = ComponentProps<'tbody'>;
64
+ /** The data rows. */
65
+ export declare function TableBody({ className, children, ...props }: TableBodyProps): import("react/jsx-runtime").JSX.Element;
66
+ export type TableFootProps = ComponentProps<'tfoot'>;
67
+ /** A totals row under the data, set apart by a rule and the footer weight. */
68
+ export declare function TableFoot({ className, children, ...props }: TableFootProps): import("react/jsx-runtime").JSX.Element;
69
+ export type TableRowProps = ComponentProps<'tr'>;
70
+ /** One row of cells. */
71
+ export declare function TableRow({ className, children, ...props }: TableRowProps): import("react/jsx-runtime").JSX.Element;
72
+ /** A sortable column's state and its handler, which come together or not at all. */
73
+ type TableHeaderCellSorting = {
74
+ sort?: undefined;
75
+ onSortChange?: undefined;
76
+ } | {
77
+ /**
78
+ * Makes the column sortable and says how it is sorted now. The head
79
+ * becomes a button, and the sorted column carries `aria-sort`.
80
+ */
81
+ sort: TableSort;
82
+ /**
83
+ * Called with the direction a press asks for: `ascending` from an
84
+ * unsorted or descending column, `descending` from an ascending one.
85
+ * The product sorts its rows and passes the new `sort` back.
86
+ */
87
+ onSortChange: (next: Exclude<TableSort, 'none'>) => void;
88
+ };
89
+ export type TableHeaderCellProps = Omit<ComponentProps<'th'>, 'align'> & TableHeaderCellSorting & {
90
+ /** Where the head sits: at the end over a column of numbers. Defaults to `start`. */
91
+ align?: TableAlign;
92
+ /**
93
+ * A control after the label that filters this column, typically an
94
+ * `IconButton` opening a `Popover`. It stays outside the sort button, so
95
+ * opening the filter never re-sorts, and out of the column's name.
96
+ */
97
+ filter?: ReactNode;
98
+ };
99
+ /**
100
+ * A column's head, a `th` scoped to its column, in the small-caps label
101
+ * style. With `sort` it is a button that re-sorts the column; with `filter`
102
+ * it carries the column's filter control beside the label. The column is
103
+ * named by its label alone, so each of its cells is announced with that.
104
+ */
105
+ export declare function TableHeaderCell({ align, sort, onSortChange, filter, className, children, ...props }: TableHeaderCellProps): import("react/jsx-runtime").JSX.Element;
106
+ export interface TableCellProps extends Omit<ComponentProps<'td'>, 'align'> {
107
+ /** Where the content sits. Defaults to `start`; `numeric` puts it at the end. */
108
+ align?: TableAlign;
109
+ /**
110
+ * A number: set at the end of the cell with tabular figures, so a column
111
+ * of amounts lines up digit under digit. Format it (currency, decimals)
112
+ * before passing it in.
113
+ */
114
+ numeric?: boolean;
115
+ /**
116
+ * The cell that names its row, rendered as a `th` scoped to the row, so a
117
+ * screen reader announces it with each of the row's other cells.
118
+ */
119
+ rowHeader?: boolean;
120
+ }
121
+ /**
122
+ * One cell of data: text by default, a number with `numeric`, or the row's
123
+ * name with `rowHeader`. A date, a status (`Badge`) or a link to the row's
124
+ * page (`Link`) goes inside as content.
125
+ */
126
+ export declare function TableCell({ align, numeric, rowHeader, className, children, ...props }: TableCellProps): import("react/jsx-runtime").JSX.Element;
127
+ export type TableActionsCellProps = Omit<TableCellProps, 'align' | 'numeric' | 'rowHeader'>;
128
+ /**
129
+ * The row's actions at the end of the row: up to two `IconButton`s, and an
130
+ * `ActionMenu` for any more, so the column stays narrow. Name each button
131
+ * after its row ("Delete Stratechery"), since the column head can't.
132
+ */
133
+ export declare function TableActionsCell({ className, children, ...props }: TableActionsCellProps): import("react/jsx-runtime").JSX.Element;
134
+ export interface TableEmptyProps extends ComponentProps<'tr'> {
135
+ /** How many columns the table has, so the message spans all of them. */
136
+ colSpan: number;
137
+ }
138
+ /**
139
+ * Stands in for the body's rows when there are none: one row whose single
140
+ * cell spans every column, holding an `EmptyState` that says why.
141
+ */
142
+ export declare function TableEmpty({ colSpan, className, children, ...props }: TableEmptyProps): import("react/jsx-runtime").JSX.Element;
143
+ export {};
144
+ //# sourceMappingURL=table.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../src/table/table.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,SAAS,EAAS,MAAM,OAAO,CAAC;AACnE,OAAO,aAAa,CAAC;AAMrB,4EAA4E;AAC5E,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,KAAK,CAAC;AAEzC,+EAA+E;AAC/E,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG,YAAY,GAAG,MAAM,CAAC;AAE5D,MAAM,WAAW,UAAW,SAAQ,cAAc,CAAC,KAAK,CAAC;IACvD;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,2EAA2E;IAC3E,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,+EAA+E;IAC/E,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,KAAK,CAAC,EACpB,KAAK,EACL,OAAe,EACf,QAAgB,EAChB,OAAO,EACP,IAAY,EACZ,SAAS,EACT,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,UAAU,2CAmBZ;AAED,MAAM,WAAW,iBAAkB,SAAQ,cAAc,CAAC,KAAK,CAAC;IAC9D,mFAAmF;IACnF,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;A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AE,UAAU,CAAC;IACnB;;;;OAIG;IACH,MAAM,CAAC,EAAE,SAAS,CAAC;CACpB,CAAC;AAIJ;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,EAC9B,KAAe,EACf,IAAI,EACJ,YAAY,EACZ,MAAM,EACN,SAAS,EACT,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,oBAAoB,2CAuCtB;AAED,MAAM,WAAW,cAAe,SAAQ,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACzE,iFAAiF;IACjF,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,EACxB,KAAK,EACL,OAAe,EACf,SAAiB,EACjB,SAAS,EACT,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,cAAc,2CAqBhB;AAED,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,cAAc,EAAE,OAAO,GAAG,SAAS,GAAG,WAAW,CAAC,CAAC;AAE5F;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,qBAAqB,2CAMxF;AAED,MAAM,WAAW,eAAgB,SAAQ,cAAc,CAAC,IAAI,CAAC;IAC3D,wEAAwE;IACxE,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,eAAe,2CAQrF"}
@@ -0,0 +1,95 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId } from 'react';
3
+ import './table.css';
4
+ import { cx } from '../cx';
5
+ import { Icon } from '../icon/icon';
6
+ import { useIconDefaults } from '../icon-defaults';
7
+ import { ScrollArea } from '../scroll-area/scroll-area';
8
+ /**
9
+ * Rows and columns of data in a real `<table>`, so a screen reader can move
10
+ * by row and column and announce each cell's column.
11
+ *
12
+ * A structural primitive, styled against the `--ds-table-*` contract. It
13
+ * holds no data and no sorting of its own: the product passes the rows in
14
+ * the order it wants and owns the sort and filter state, which on a server-
15
+ * paged list is the only place it can live.
16
+ *
17
+ * Compose with {@link TableHead}, {@link TableBody} and {@link TableFoot},
18
+ * made of {@link TableRow}s holding {@link TableHeaderCell}s and
19
+ * {@link TableCell}s; {@link TableActionsCell} holds a row's icon buttons and
20
+ * {@link TableEmpty} stands in for the rows when there are none.
21
+ *
22
+ * The table scrolls sideways inside its box when its columns don't fit, so a
23
+ * phone keeps every column instead of squeezing them. `className` and the
24
+ * other props go to that box, which holds the toolbar and the table.
25
+ */
26
+ export function Table({ label, striped = false, rowHover = false, toolbar, busy = false, className, children, ...props }) {
27
+ return (_jsxs("div", { className: cx('ds-table', striped && 'ds-table--striped', rowHover && 'ds-table--row-hover', className), ...props, children: [toolbar, _jsx(ScrollArea, { axis: "x", className: "ds-table__scroll", label: label, children: _jsx("table", { "aria-busy": busy || undefined, "aria-label": label, className: "ds-table__table", children: children }) })] }));
28
+ }
29
+ /**
30
+ * The row above a table: its actions at the end (add a row, history,
31
+ * export), and optionally a search or filter at the start. Pass it to
32
+ * {@link Table}'s `toolbar`.
33
+ */
34
+ export function TableToolbar({ start, className, children, ...props }) {
35
+ return (_jsxs("div", { className: cx('ds-table__toolbar', className), ...props, children: [start ? _jsx("div", { className: "ds-table__toolbar-start", children: start }) : null, _jsx("div", { className: "ds-table__toolbar-actions", children: children })] }));
36
+ }
37
+ /** The column heads: a {@link TableRow} of {@link TableHeaderCell}s. */
38
+ export function TableHead({ className, children, ...props }) {
39
+ return (_jsx("thead", { className: cx('ds-table__head', className), ...props, children: children }));
40
+ }
41
+ /** The data rows. */
42
+ export function TableBody({ className, children, ...props }) {
43
+ return (_jsx("tbody", { className: cx('ds-table__body', className), ...props, children: children }));
44
+ }
45
+ /** A totals row under the data, set apart by a rule and the footer weight. */
46
+ export function TableFoot({ className, children, ...props }) {
47
+ return (_jsx("tfoot", { className: cx('ds-table__foot', className), ...props, children: children }));
48
+ }
49
+ /** One row of cells. */
50
+ export function TableRow({ className, children, ...props }) {
51
+ return (_jsx("tr", { className: cx('ds-table__row', className), ...props, children: children }));
52
+ }
53
+ const ARIA_SORT = { ascending: 'ascending', descending: 'descending', none: undefined };
54
+ /**
55
+ * A column's head, a `th` scoped to its column, in the small-caps label
56
+ * style. With `sort` it is a button that re-sorts the column; with `filter`
57
+ * it carries the column's filter control beside the label. The column is
58
+ * named by its label alone, so each of its cells is announced with that.
59
+ */
60
+ export function TableHeaderCell({ align = 'start', sort, onSortChange, filter, className, children, ...props }) {
61
+ const icons = useIconDefaults();
62
+ const labelId = useId();
63
+ const text = (_jsx("span", { className: "ds-table__header-label", id: labelId, children: children }));
64
+ const label = sort === undefined ? (text) : (_jsxs("button", { className: "ds-table__sort", "data-sort": sort, onClick: () => onSortChange(sort === 'ascending' ? 'descending' : 'ascending'), type: "button", children: [text, _jsxs("span", { "aria-hidden": "true", className: "ds-table__sort-indicator", children: [_jsx(Icon, { decorative: true, size: "sm", source: icons.chevronRight }), sort === 'none' ? _jsx(Icon, { decorative: true, size: "sm", source: icons.chevronRight }) : null] })] }));
65
+ return (_jsx("th", { "aria-labelledby": labelId, "aria-sort": sort === undefined ? undefined : ARIA_SORT[sort], className: cx('ds-table__header-cell', align === 'end' && 'ds-table__cell--end', className), scope: "col", ...props, children: _jsxs("span", { className: "ds-table__header-content", children: [label, filter] }) }));
66
+ }
67
+ /**
68
+ * One cell of data: text by default, a number with `numeric`, or the row's
69
+ * name with `rowHeader`. A date, a status (`Badge`) or a link to the row's
70
+ * page (`Link`) goes inside as content.
71
+ */
72
+ export function TableCell({ align, numeric = false, rowHeader = false, className, children, ...props }) {
73
+ const end = (align ?? (numeric ? 'end' : 'start')) === 'end';
74
+ const classes = cx('ds-table__cell', end && 'ds-table__cell--end', numeric && 'ds-table__cell--numeric', rowHeader && 'ds-table__cell--row-header', className);
75
+ if (rowHeader) {
76
+ return (_jsx("th", { className: classes, scope: "row", ...props, children: children }));
77
+ }
78
+ return (_jsx("td", { className: classes, ...props, children: children }));
79
+ }
80
+ /**
81
+ * The row's actions at the end of the row: up to two `IconButton`s, and an
82
+ * `ActionMenu` for any more, so the column stays narrow. Name each button
83
+ * after its row ("Delete Stratechery"), since the column head can't.
84
+ */
85
+ export function TableActionsCell({ className, children, ...props }) {
86
+ return (_jsx("td", { className: cx('ds-table__cell', 'ds-table__cell--actions', className), ...props, children: _jsx("span", { className: "ds-table__actions", children: children }) }));
87
+ }
88
+ /**
89
+ * Stands in for the body's rows when there are none: one row whose single
90
+ * cell spans every column, holding an `EmptyState` that says why.
91
+ */
92
+ export function TableEmpty({ colSpan, className, children, ...props }) {
93
+ return (_jsx("tr", { className: cx('ds-table__row', 'ds-table__empty', className), ...props, children: _jsx("td", { className: "ds-table__cell", colSpan: colSpan, children: children }) }));
94
+ }
95
+ //# sourceMappingURL=table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table.js","sourceRoot":"","sources":["../../src/table/table.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAuC,KAAK,EAAE,MAAM,OAAO,CAAC;AACnE,OAAO,aAAa,CAAC;AACrB,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAiCxD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,KAAK,CAAC,EACpB,KAAK,EACL,OAAO,GAAG,KAAK,EACf,QAAQ,GAAG,KAAK,EAChB,OAAO,EACP,IAAI,GAAG,KAAK,EACZ,SAAS,EACT,QAAQ,EACR,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AAC;AACJ,CAAC;AAID;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAyB;IACvF,OAAO,CACL,aAAI,SAAS,EAAE,EAAE,CAAC,gBAAgB,EAAE,yBAAyB,EAAE,SAAS,CAAC,KAAM,KAAK,YAClF,eAAM,SAAS,EAAC,mBAAmB,YAAE,QAAQ,GAAQ,GAClD,CACN,CAAC;AACJ,CAAC;AAOD;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAmB;IACpF,OAAO,CACL,aAAI,SAAS,EAAE,EAAE,CAAC,eAAe,EAAE,iBAAiB,EAAE,SAAS,CAAC,KAAM,KAAK,YACzE,aAAI,SAAS,EAAC,gBAAgB,EAAC,OAAO,EAAE,OAAO,YAC5C,QAAQ,GACN,GACF,CACN,CAAC;AACJ,CAAC","sourcesContent":["import { type ComponentProps, type ReactNode, useId } from 'react';\nimport './table.css';\nimport { cx } from '../cx';\nimport { Icon } from '../icon/icon';\nimport { useIconDefaults } from '../icon-defaults';\nimport { ScrollArea } from '../scroll-area/scroll-area';\n\n/** Where a column's content sits: text at the start, numbers at the end. */\nexport type TableAlign = 'start' | 'end';\n\n/** A sortable column's state. `none` is sortable but not the sort in force. */\nexport type TableSort = 'ascending' | 'descending' | 'none';\n\nexport interface TableProps extends ComponentProps<'div'> {\n /**\n * The table's name, required: it names the table for a screen reader and\n * the scroll region around it, which takes keyboard focus so a table wider\n * than its column can be scrolled with the arrow keys.\n */\n label: string;\n /** Tint every other body row, so a long row is easier to follow across. */\n striped?: boolean;\n /**\n * Highlight the body row under the pointer, to read it across or compare\n * it with its neighbours. Not a sign that the row is clickable: a row that\n * opens something puts a link in its first cell.\n */\n rowHover?: boolean;\n /**\n * What sits above the table: a {@link TableToolbar} with the table's\n * actions (add a row, history), and optionally a search or filter at its\n * start.\n */\n toolbar?: ReactNode;\n /** The rows are loading: marks the table busy while skeleton rows stand in. */\n busy?: boolean;\n}\n\n/**\n * Rows and columns of data in a real `<table>`, so a screen reader can move\n * by row and column and announce each cell's column.\n *\n * A structural primitive, styled against the `--ds-table-*` contract. It\n * holds no data and no sorting of its own: the product passes the rows in\n * the order it wants and owns the sort and filter state, which on a server-\n * paged list is the only place it can live.\n *\n * Compose with {@link TableHead}, {@link TableBody} and {@link TableFoot},\n * made of {@link TableRow}s holding {@link TableHeaderCell}s and\n * {@link TableCell}s; {@link TableActionsCell} holds a row's icon buttons and\n * {@link TableEmpty} stands in for the rows when there are none.\n *\n * The table scrolls sideways inside its box when its columns don't fit, so a\n * phone keeps every column instead of squeezing them. `className` and the\n * other props go to that box, which holds the toolbar and the table.\n */\nexport function Table({\n label,\n striped = false,\n rowHover = false,\n toolbar,\n busy = false,\n className,\n children,\n ...props\n}: TableProps) {\n return (\n <div\n className={cx(\n 'ds-table',\n striped && 'ds-table--striped',\n rowHover && 'ds-table--row-hover',\n className,\n )}\n {...props}\n >\n {toolbar}\n <ScrollArea axis=\"x\" className=\"ds-table__scroll\" label={label}>\n <table aria-busy={busy || undefined} aria-label={label} className=\"ds-table__table\">\n {children}\n </table>\n </ScrollArea>\n </div>\n );\n}\n\nexport interface TableToolbarProps extends ComponentProps<'div'> {\n /** What sits at the start of the row: a search or a filter for the whole table. */\n start?: ReactNode;\n}\n\n/**\n * The row above a table: its actions at the end (add a row, history,\n * export), and optionally a search or filter at the start. Pass it to\n * {@link Table}'s `toolbar`.\n */\nexport function TableToolbar({ start, className, children, ...props }: TableToolbarProps) {\n return (\n <div className={cx('ds-table__toolbar', className)} {...props}>\n {start ? <div className=\"ds-table__toolbar-start\">{start}</div> : null}\n <div className=\"ds-table__toolbar-actions\">{children}</div>\n </div>\n );\n}\n\nexport type TableHeadProps = ComponentProps<'thead'>;\n\n/** The column heads: a {@link TableRow} of {@link TableHeaderCell}s. */\nexport function TableHead({ className, children, ...props }: TableHeadProps) {\n return (\n <thead className={cx('ds-table__head', className)} {...props}>\n {children}\n </thead>\n );\n}\n\nexport type TableBodyProps = ComponentProps<'tbody'>;\n\n/** The data rows. */\nexport function TableBody({ className, children, ...props }: TableBodyProps) {\n return (\n <tbody className={cx('ds-table__body', className)} {...props}>\n {children}\n </tbody>\n );\n}\n\nexport type TableFootProps = ComponentProps<'tfoot'>;\n\n/** A totals row under the data, set apart by a rule and the footer weight. */\nexport function TableFoot({ className, children, ...props }: TableFootProps) {\n return (\n <tfoot className={cx('ds-table__foot', className)} {...props}>\n {children}\n </tfoot>\n );\n}\n\nexport type TableRowProps = ComponentProps<'tr'>;\n\n/** One row of cells. */\nexport function TableRow({ className, children, ...props }: TableRowProps) {\n return (\n <tr className={cx('ds-table__row', className)} {...props}>\n {children}\n </tr>\n );\n}\n\n/** A sortable column's state and its handler, which come together or not at all. */\ntype TableHeaderCellSorting =\n | { sort?: undefined; onSortChange?: undefined }\n | {\n /**\n * Makes the column sortable and says how it is sorted now. The head\n * becomes a button, and the sorted column carries `aria-sort`.\n */\n sort: TableSort;\n /**\n * Called with the direction a press asks for: `ascending` from an\n * unsorted or descending column, `descending` from an ascending one.\n * The product sorts its rows and passes the new `sort` back.\n */\n onSortChange: (next: Exclude<TableSort, 'none'>) => void;\n };\n\nexport type TableHeaderCellProps = Omit<ComponentProps<'th'>, 'align'> &\n TableHeaderCellSorting & {\n /** Where the head sits: at the end over a column of numbers. Defaults to `start`. */\n align?: TableAlign;\n /**\n * A control after the label that filters this column, typically an\n * `IconButton` opening a `Popover`. It stays outside the sort button, so\n * opening the filter never re-sorts, and out of the column's name.\n */\n filter?: ReactNode;\n };\n\nconst ARIA_SORT = { ascending: 'ascending', descending: 'descending', none: undefined } as const;\n\n/**\n * A column's head, a `th` scoped to its column, in the small-caps label\n * style. With `sort` it is a button that re-sorts the column; with `filter`\n * it carries the column's filter control beside the label. The column is\n * named by its label alone, so each of its cells is announced with that.\n */\nexport function TableHeaderCell({\n align = 'start',\n sort,\n onSortChange,\n filter,\n className,\n children,\n ...props\n}: TableHeaderCellProps) {\n const icons = useIconDefaults();\n const labelId = useId();\n const text = (\n <span className=\"ds-table__header-label\" id={labelId}>\n {children}\n </span>\n );\n const label =\n sort === undefined ? (\n text\n ) : (\n <button\n className=\"ds-table__sort\"\n data-sort={sort}\n onClick={() => onSortChange(sort === 'ascending' ? 'descending' : 'ascending')}\n type=\"button\"\n >\n {text}\n <span aria-hidden=\"true\" className=\"ds-table__sort-indicator\">\n <Icon decorative size=\"sm\" source={icons.chevronRight} />\n {sort === 'none' ? <Icon decorative size=\"sm\" source={icons.chevronRight} /> : null}\n </span>\n </button>\n );\n return (\n <th\n aria-labelledby={labelId}\n aria-sort={sort === undefined ? undefined : ARIA_SORT[sort]}\n className={cx('ds-table__header-cell', align === 'end' && 'ds-table__cell--end', className)}\n scope=\"col\"\n {...props}\n >\n <span className=\"ds-table__header-content\">\n {label}\n {filter}\n </span>\n </th>\n );\n}\n\nexport interface TableCellProps extends Omit<ComponentProps<'td'>, 'align'> {\n /** Where the content sits. Defaults to `start`; `numeric` puts it at the end. */\n align?: TableAlign;\n /**\n * A number: set at the end of the cell with tabular figures, so a column\n * of amounts lines up digit under digit. Format it (currency, decimals)\n * before passing it in.\n */\n numeric?: boolean;\n /**\n * The cell that names its row, rendered as a `th` scoped to the row, so a\n * screen reader announces it with each of the row's other cells.\n */\n rowHeader?: boolean;\n}\n\n/**\n * One cell of data: text by default, a number with `numeric`, or the row's\n * name with `rowHeader`. A date, a status (`Badge`) or a link to the row's\n * page (`Link`) goes inside as content.\n */\nexport function TableCell({\n align,\n numeric = false,\n rowHeader = false,\n className,\n children,\n ...props\n}: TableCellProps) {\n const end = (align ?? (numeric ? 'end' : 'start')) === 'end';\n const classes = cx(\n 'ds-table__cell',\n end && 'ds-table__cell--end',\n numeric && 'ds-table__cell--numeric',\n rowHeader && 'ds-table__cell--row-header',\n className,\n );\n if (rowHeader) {\n return (\n <th className={classes} scope=\"row\" {...props}>\n {children}\n </th>\n );\n }\n return (\n <td className={classes} {...props}>\n {children}\n </td>\n );\n}\n\nexport type TableActionsCellProps = Omit<TableCellProps, 'align' | 'numeric' | 'rowHeader'>;\n\n/**\n * The row's actions at the end of the row: up to two `IconButton`s, and an\n * `ActionMenu` for any more, so the column stays narrow. Name each button\n * after its row (\"Delete Stratechery\"), since the column head can't.\n */\nexport function TableActionsCell({ className, children, ...props }: TableActionsCellProps) {\n return (\n <td className={cx('ds-table__cell', 'ds-table__cell--actions', className)} {...props}>\n <span className=\"ds-table__actions\">{children}</span>\n </td>\n );\n}\n\nexport interface TableEmptyProps extends ComponentProps<'tr'> {\n /** How many columns the table has, so the message spans all of them. */\n colSpan: number;\n}\n\n/**\n * Stands in for the body's rows when there are none: one row whose single\n * cell spans every column, holding an `EmptyState` that says why.\n */\nexport function TableEmpty({ colSpan, className, children, ...props }: TableEmptyProps) {\n return (\n <tr className={cx('ds-table__row', 'ds-table__empty', className)} {...props}>\n <td className=\"ds-table__cell\" colSpan={colSpan}>\n {children}\n </td>\n </tr>\n );\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manakind/ui-core",
3
- "version": "0.33.0",
3
+ "version": "0.34.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -396,7 +396,7 @@
396
396
  },
397
397
  "devDependencies": {
398
398
  "@manakind/ds-config": "*",
399
- "@manakind/manuia-tokens": "0.31.0",
399
+ "@manakind/manuia-tokens": "0.32.0",
400
400
  "@testing-library/jest-dom": "^6.9.1",
401
401
  "@testing-library/react": "^16.3.2",
402
402
  "@testing-library/user-event": "^14.6.1",