@manakind/ui-core 0.35.0 → 0.37.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.
@@ -67,4 +67,58 @@
67
67
  }
68
68
  }
69
69
  }
70
+
71
+ /*
72
+ * Cards: the label above a grid of choices that fills the width and wraps.
73
+ * Each card is the whole click target; the hidden radio inside it carries
74
+ * the state and the keyboard. Chosen, the card's border thickens into a
75
+ * ring in the checked colour, so the choice reads by weight as well as
76
+ * colour; keyboard focus is the focus ring drawn outside it.
77
+ */
78
+ .ds-radio-group--cards {
79
+ align-items: stretch;
80
+
81
+ & .ds-radio-group__cards {
82
+ display: grid;
83
+ grid-template-columns: repeat(auto-fill, minmax(var(--ds-radio-group-card-min-width), 1fr));
84
+ gap: var(--ds-radio-group-card-gap);
85
+ }
86
+
87
+ & .ds-radio-group__item {
88
+ box-sizing: border-box;
89
+ flex-direction: column;
90
+ justify-content: center;
91
+ gap: var(--ds-radio-group-card-gap);
92
+ padding: var(--ds-radio-group-card-padding);
93
+ border: 1px solid var(--ds-radio-group-card-border);
94
+ border-radius: var(--ds-radio-group-card-radius);
95
+ background-color: var(--ds-radio-group-card-bg);
96
+ text-align: center;
97
+ transition: border-color 150ms cubic-bezier(0, 0, 0.2, 1);
98
+
99
+ &[data-hover]:not([data-disabled], [data-state="checked"]) {
100
+ border-color: var(--ds-radio-group-card-border-hover);
101
+ }
102
+
103
+ /* The border thickens inward: the padding gives back what it takes, so nothing shifts. */
104
+ &[data-state="checked"] {
105
+ padding: calc(var(--ds-radio-group-card-padding) - 1px);
106
+ border: 2px solid var(--ds-radio-group-card-border-checked);
107
+ }
108
+
109
+ &[data-focus-visible] {
110
+ outline: 2px solid var(--ds-radio-group-focus-ring);
111
+ outline-offset: 2px;
112
+ }
113
+
114
+ &[data-disabled] {
115
+ opacity: var(--ds-opacity-disabled);
116
+ }
117
+ }
118
+
119
+ & .ds-radio-group__visual {
120
+ display: flex;
121
+ justify-content: center;
122
+ }
123
+ }
70
124
  }
@@ -7,7 +7,15 @@ export interface RadioGroupItem {
7
7
  label: string;
8
8
  /** Individually disable this choice without removing it. */
9
9
  disabled?: boolean;
10
+ /**
11
+ * A picture of the choice, above its label on a `cards` group: a swatch,
12
+ * a badge, a preview. Decorative: the label names the choice. A `list`
13
+ * group ignores it.
14
+ */
15
+ visual?: ReactNode;
10
16
  }
17
+ /** `list` (default) sets radios one under the other; `cards` sets each choice on a card in a wrapping grid. */
18
+ export type RadioGroupAppearance = 'list' | 'cards';
11
19
  /**
12
20
  * A radio group has to have a name, expressed as a union so an unnamed group
13
21
  * is a compile error rather than an axe finding, as `SegmentGroup` does.
@@ -26,8 +34,16 @@ type RadioGroupName = {
26
34
  'aria-label': string;
27
35
  };
28
36
  export type RadioGroupProps = RadioGroupName & {
29
- /** The choices, in order, one under the other. */
37
+ /** The choices, in order. */
30
38
  items: RadioGroupItem[];
39
+ /**
40
+ * `list` (default) sets a radio beside each label, one under the other.
41
+ * `cards` sets each choice on a card, its `visual` above its label, in a
42
+ * grid that fills the width and wraps; the chosen card carries a heavier
43
+ * ring instead of a radio. For choices told apart by how they look, such
44
+ * as colours or themes.
45
+ */
46
+ appearance?: RadioGroupAppearance;
31
47
  /**
32
48
  * Controlled value. `null` is controlled with nothing chosen; `undefined`
33
49
  * leaves the component to own its value from `defaultValue` onward.
@@ -66,9 +82,11 @@ export type RadioGroupProps = RadioGroupName & {
66
82
  * />
67
83
  * ```
68
84
  *
69
- * A few short choices seen at once in a row are a `SegmentGroup`; a long
70
- * list, or one in a form row, is a `Select`.
85
+ * Choices told apart by how they look (a colour, a theme) take
86
+ * `appearance="cards"`, each with a `visual`. A few short choices seen at
87
+ * once in a row are a `SegmentGroup`; a long list, or one in a form row, is
88
+ * a `Select`.
71
89
  */
72
- export declare function RadioGroup({ label, items, value, defaultValue, onValueChange, disabled, name, className, 'aria-label': ariaLabel, }: RadioGroupProps): import("react/jsx-runtime").JSX.Element;
90
+ export declare function RadioGroup({ label, items, value, defaultValue, onValueChange, disabled, name, appearance, className, 'aria-label': ariaLabel, }: RadioGroupProps): import("react/jsx-runtime").JSX.Element;
73
91
  export {};
74
92
  //# sourceMappingURL=radio-group.d.ts.map
@@ -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;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,EACz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EAAmE;IACnE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,KAAK,EACL,KAAK,EACL,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,IAAI,EACJ,UAAmB,EACnB,SAAS,EACT,YAAY,EAAE,SAAS,GACxB,EAAE,eAAe,2CAuDjB"}
@@ -26,10 +26,13 @@ import { cx } from '../cx';
26
26
  * />
27
27
  * ```
28
28
  *
29
- * A few short choices seen at once in a row are a `SegmentGroup`; a long
30
- * list, or one in a form row, is a `Select`.
29
+ * Choices told apart by how they look (a colour, a theme) take
30
+ * `appearance="cards"`, each with a `visual`. A few short choices seen at
31
+ * once in a row are a `SegmentGroup`; a long list, or one in a form row, is
32
+ * a `Select`.
31
33
  */
32
- export function RadioGroup({ label, items, value, defaultValue, onValueChange, disabled, name, className, 'aria-label': ariaLabel, }) {
34
+ export function RadioGroup({ label, items, value, defaultValue, onValueChange, disabled, name, appearance = 'list', className, 'aria-label': ariaLabel, }) {
35
+ const cards = appearance === 'cards';
33
36
  const rootRef = useRef(null);
34
37
  const handleValueChange = radioGroupChangeHandler(rootRef, value, onValueChange);
35
38
  const visibleLabel = renderVisibleLabel(ArkRadioGroup.Label, {
@@ -37,7 +40,9 @@ export function RadioGroup({ label, items, value, defaultValue, onValueChange, d
37
40
  ariaLabel,
38
41
  className: 'ds-radio-group__label',
39
42
  });
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));
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)] }));
43
+ const marker = (item) => cards ? (_jsx("span", { className: "ds-radio-group__visual", "aria-hidden": true, children: item.visual })) : (_jsx(ArkRadioGroup.ItemControl, { className: "ds-radio-group__control" }));
44
+ const renderItem = (item) => (_jsxs(ArkRadioGroup.Item, { value: item.value, disabled: item.disabled, className: "ds-radio-group__item", children: [marker(item), _jsx(ArkRadioGroup.ItemText, { className: "ds-radio-group__text", children: item.label }), _jsx(ArkRadioGroup.ItemHiddenInput, {})] }, item.value));
45
+ const choices = cards ? (_jsx("div", { className: "ds-radio-group__cards", children: items.map(renderItem) })) : (items.map(renderItem));
46
+ return (_jsxs(ArkRadioGroup.Root, { ref: rootRef, className: cx('ds-radio-group', cards && 'ds-radio-group--cards', className), value: value, defaultValue: defaultValue, onValueChange: handleValueChange, disabled: disabled, name: name, orientation: "vertical", "aria-label": ariaLabel, children: [visibleLabel, choices] }));
42
47
  }
43
48
  //# sourceMappingURL=radio-group.js.map
@@ -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,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
+ {"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;AAoE3B;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,UAAU,CAAC,EACzB,KAAK,EACL,KAAK,EACL,KAAK,EACL,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,IAAI,EACJ,UAAU,GAAG,MAAM,EACnB,SAAS,EACT,YAAY,EAAE,SAAS,GACP;IAChB,MAAM,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,gBAAgB,EAAE,KAAK,IAAI,uBAAuB,EAAE,SAAS,CAAC,EAC5E,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,OAAO,IACW,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 * A picture of the choice, above its label on a `cards` group: a swatch,\n * a badge, a preview. Decorative: the label names the choice. A `list`\n * group ignores it.\n */\n visual?: ReactNode;\n}\n\n/** `list` (default) sets radios one under the other; `cards` sets each choice on a card in a wrapping grid. */\nexport type RadioGroupAppearance = 'list' | 'cards';\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. */\n items: RadioGroupItem[];\n /**\n * `list` (default) sets a radio beside each label, one under the other.\n * `cards` sets each choice on a card, its `visual` above its label, in a\n * grid that fills the width and wraps; the chosen card carries a heavier\n * ring instead of a radio. For choices told apart by how they look, such\n * as colours or themes.\n */\n appearance?: RadioGroupAppearance;\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 * Choices told apart by how they look (a colour, a theme) take\n * `appearance=\"cards\"`, each with a `visual`. A few short choices seen at\n * once in a row are a `SegmentGroup`; a long list, or one in a form row, is\n * a `Select`.\n */\nexport function RadioGroup({\n label,\n items,\n value,\n defaultValue,\n onValueChange,\n disabled,\n name,\n appearance = 'list',\n className,\n 'aria-label': ariaLabel,\n}: RadioGroupProps) {\n const cards = appearance === 'cards';\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 marker = (item: RadioGroupItem) =>\n cards ? (\n <span className=\"ds-radio-group__visual\" aria-hidden>\n {item.visual}\n </span>\n ) : (\n <ArkRadioGroup.ItemControl className=\"ds-radio-group__control\" />\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 {marker(item)}\n <ArkRadioGroup.ItemText className=\"ds-radio-group__text\">{item.label}</ArkRadioGroup.ItemText>\n <ArkRadioGroup.ItemHiddenInput />\n </ArkRadioGroup.Item>\n );\n\n const choices = cards ? (\n <div className=\"ds-radio-group__cards\">{items.map(renderItem)}</div>\n ) : (\n items.map(renderItem)\n );\n\n return (\n <ArkRadioGroup.Root\n ref={rootRef}\n className={cx('ds-radio-group', cards && 'ds-radio-group--cards', 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 {choices}\n </ArkRadioGroup.Root>\n );\n}\n"]}
@@ -1,3 +1,3 @@
1
- export type { TabsContentProps, TabsListProps, TabsProps, TabsTriggerProps } from './tabs';
1
+ export type { TabsContentProps, TabsListAppearance, TabsListProps, TabsProps, TabsTriggerProps, } from './tabs';
2
2
  export { Tabs, TabsContent, TabsList, TabsTrigger } from './tabs';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tabs/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAC3F,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tabs/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,SAAS,EACT,gBAAgB,GACjB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tabs/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC","sourcesContent":["export type { TabsContentProps, TabsListProps, TabsProps, TabsTriggerProps } from './tabs';\nexport { Tabs, TabsContent, TabsList, TabsTrigger } from './tabs';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tabs/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC","sourcesContent":["export type {\n TabsContentProps,\n TabsListAppearance,\n TabsListProps,\n TabsProps,\n TabsTriggerProps,\n} from './tabs';\nexport { Tabs, TabsContent, TabsList, TabsTrigger } from './tabs';\n"]}
@@ -94,10 +94,6 @@
94
94
  }
95
95
  }
96
96
 
97
- /*
98
- * `nowrap` triggers cannot shrink below their label, so five of them used
99
- * to widen the whole page on a phone. The list scrolls them instead.
100
- */
101
97
  /*
102
98
  * `nowrap` triggers cannot shrink below their label, so five of them used
103
99
  * to widen the whole page on a phone. The scroller scrolls them instead.
@@ -205,5 +201,29 @@
205
201
  padding-inline-start: var(--ds-tabs-content-padding-block);
206
202
  }
207
203
  }
204
+
205
+ /*
206
+ * A plain list: no track, and every trigger its own shape. It wraps rather
207
+ * than scrolling, so there is no scroller to clip the focus ring and no
208
+ * `nowrap` that would need one; a trigger's label wraps as any text does.
209
+ *
210
+ * Declared last, with the list's two classes, so it outranks the segmented
211
+ * corners above, the vertical ones included, on specificity and on order.
212
+ */
213
+ & .ds-tabs__list.ds-tabs__list--plain {
214
+ flex-wrap: wrap;
215
+ gap: var(--ds-layout-gap);
216
+ min-inline-size: 0;
217
+ padding: 0;
218
+ border-radius: 0;
219
+ background-color: transparent;
220
+
221
+ & .ds-tabs__trigger {
222
+ flex-shrink: 1;
223
+ min-inline-size: 0;
224
+ border-radius: var(--ds-tabs-list-radius);
225
+ white-space: normal;
226
+ }
227
+ }
208
228
  }
209
229
  }
@@ -1,5 +1,5 @@
1
1
  import { Tabs as ArkTabs } from '@ark-ui/react/tabs';
2
- import type { ComponentProps } from 'react';
2
+ import { type ComponentProps } from 'react';
3
3
  import './tabs.css';
4
4
  export type TabsProps = ComponentProps<typeof ArkTabs.Root>;
5
5
  /**
@@ -27,13 +27,33 @@ export type TabsProps = ComponentProps<typeof ArkTabs.Root>;
27
27
  * then move focus without switching panels until Enter or Space.
28
28
  */
29
29
  export declare function Tabs({ className, children, ...props }: TabsProps): import("react/jsx-runtime").JSX.Element;
30
- export interface TabsListProps extends ComponentProps<typeof ArkTabs.List> {
30
+ /**
31
+ * `fitted` shares the width of one row, and a `plain` row wraps, so the two
32
+ * cannot be combined: the pairing is a compile error rather than a
33
+ * convention, as Badge's `BadgeLook` is.
34
+ */
35
+ type TabsListLook = {
31
36
  /**
32
- * Distribute triggers evenly across the full width instead of sizing them
33
- * to their content. Matches the segmented-control look.
37
+ * `segmented` (default) sets the triggers on a track and scrolls them
38
+ * sideways when they outgrow the list. `plain` drops the track and its
39
+ * padding: every trigger takes the list's radius as its own shape, the
40
+ * triggers sit `--ds-layout-gap` apart, and a row that outgrows the list
41
+ * wraps onto a new line instead of scrolling. For triggers that carry
42
+ * their own look, such as a row of avatars or category badges.
43
+ */
44
+ appearance?: 'segmented';
45
+ /**
46
+ * Distribute triggers evenly across the full width instead of sizing
47
+ * them to their content. Matches the segmented-control look.
34
48
  */
35
49
  fitted?: boolean;
36
- }
50
+ } | {
51
+ appearance: 'plain';
52
+ fitted?: never;
53
+ };
54
+ export type TabsListProps = ComponentProps<typeof ArkTabs.List> & TabsListLook;
55
+ /** `segmented` sets the triggers on a track; `plain` lets each stand alone and wraps the row. */
56
+ export type TabsListAppearance = NonNullable<TabsListProps['appearance']>;
37
57
  /**
38
58
  * Container for the tab triggers. Renders with `role="tablist"`.
39
59
  *
@@ -41,16 +61,24 @@ export interface TabsListProps extends ComponentProps<typeof ArkTabs.List> {
41
61
  * more than one tablist — screen reader users otherwise get several
42
62
  * indistinguishable "tab list" landmarks.
43
63
  *
44
- * When the triggers need more room than the list has, the list scrolls
45
- * sideways inside its own box instead of widening the page. Focusing a
46
- * trigger, by Tab or by arrow key, brings it into view.
64
+ * When the triggers need more room than a segmented list has, the list
65
+ * scrolls sideways inside its own box instead of widening the page. Focusing
66
+ * a trigger, by Tab or by arrow key, brings it into view. A `plain` list
67
+ * wraps instead, so it neither scrolls nor needs the elements below.
68
+ *
69
+ * The two elements around a segmented list exist for the focus ring, which
70
+ * reaches past the list's edge. The scroller is that much larger than the
71
+ * list, so scrolling does not clip the ring; the frame keeps the scroller's
72
+ * extra size from widening whatever the tabs sit in. `tabs.css` has the
73
+ * arithmetic.
47
74
  *
48
- * The two elements around the list exist for the focus ring, which reaches
49
- * past the list's edge. The scroller is that much larger than the list, so
50
- * scrolling does not clip the ring; the frame keeps the scroller's extra size
51
- * from widening whatever the tabs sit in. `tabs.css` has the arithmetic.
75
+ * Ark makes the selected trigger the list's one tab stop. While no tab is
76
+ * selected (a controlled `value` of `null`) it leaves none, so the list
77
+ * itself takes the stop and hands focus to its first enabled trigger, as the
78
+ * selected one would have had it; once focus is inside, the list steps out of
79
+ * the tab order again, so Tab and Shift+Tab leave the row in one press.
52
80
  */
53
- export declare function TabsList({ fitted, className, children, ...props }: TabsListProps): import("react/jsx-runtime").JSX.Element;
81
+ export declare function TabsList({ fitted, appearance, className, children, onFocus, onBlur, ...props }: TabsListProps): import("react/jsx-runtime").JSX.Element;
54
82
  export type TabsTriggerProps = ComponentProps<typeof ArkTabs.Trigger>;
55
83
  /**
56
84
  * A single tab. `value` must match the `value` of its {@link TabsContent}.
@@ -61,4 +89,5 @@ export declare function TabsTrigger({ className, children, ...props }: TabsTrigg
61
89
  export type TabsContentProps = ComponentProps<typeof ArkTabs.Content>;
62
90
  /** Panel for one tab. `value` must match its {@link TabsTrigger}. */
63
91
  export declare function TabsContent({ className, children, ...props }: TabsContentProps): import("react/jsx-runtime").JSX.Element;
92
+ export {};
64
93
  //# sourceMappingURL=tabs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tabs.d.ts","sourceRoot":"","sources":["../../src/tabs/tabs.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,YAAY,CAAC;AAGpB,MAAM,MAAM,SAAS,GAAG,cAAc,CAAC,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,IAAI,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,SAAS,2CAMhE;AAED,MAAM,WAAW,aAAc,SAAQ,cAAc,CAAC,OAAO,OAAO,CAAC,IAAI,CAAC;IACxE;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,CAAC,EAAE,MAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,aAAa,2CAaxF;AAED,MAAM,MAAM,gBAAgB,GAAG,cAAc,CAAC,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtE;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,gBAAgB,2CAM9E;AAED,MAAM,MAAM,gBAAgB,GAAG,cAAc,CAAC,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtE,qEAAqE;AACrE,wBAAgB,WAAW,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,gBAAgB,2CAM9E"}
1
+ {"version":3,"file":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,GAAG,cAAc,CAAC,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtE,qEAAqE;AACrE,wBAAgB,WAAW,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,gBAAgB,2CAM9E"}
package/dist/tabs/tabs.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Tabs as ArkTabs } from '@ark-ui/react/tabs';
2
+ import { Tabs as ArkTabs, useTabsContext } from '@ark-ui/react/tabs';
3
+ import { useState } from 'react';
3
4
  import './tabs.css';
4
5
  import { cx } from '../cx';
5
6
  /**
@@ -36,17 +37,43 @@ export function Tabs({ className, children, ...props }) {
36
37
  * more than one tablist — screen reader users otherwise get several
37
38
  * indistinguishable "tab list" landmarks.
38
39
  *
39
- * When the triggers need more room than the list has, the list scrolls
40
- * sideways inside its own box instead of widening the page. Focusing a
41
- * trigger, by Tab or by arrow key, brings it into view.
40
+ * When the triggers need more room than a segmented list has, the list
41
+ * scrolls sideways inside its own box instead of widening the page. Focusing
42
+ * a trigger, by Tab or by arrow key, brings it into view. A `plain` list
43
+ * wraps instead, so it neither scrolls nor needs the elements below.
42
44
  *
43
- * The two elements around the list exist for the focus ring, which reaches
44
- * past the list's edge. The scroller is that much larger than the list, so
45
- * scrolling does not clip the ring; the frame keeps the scroller's extra size
46
- * from widening whatever the tabs sit in. `tabs.css` has the arithmetic.
45
+ * The two elements around a segmented list exist for the focus ring, which
46
+ * reaches past the list's edge. The scroller is that much larger than the
47
+ * list, so scrolling does not clip the ring; the frame keeps the scroller's
48
+ * extra size from widening whatever the tabs sit in. `tabs.css` has the
49
+ * arithmetic.
50
+ *
51
+ * Ark makes the selected trigger the list's one tab stop. While no tab is
52
+ * selected (a controlled `value` of `null`) it leaves none, so the list
53
+ * itself takes the stop and hands focus to its first enabled trigger, as the
54
+ * selected one would have had it; once focus is inside, the list steps out of
55
+ * the tab order again, so Tab and Shift+Tab leave the row in one press.
47
56
  */
48
- export function TabsList({ fitted = false, className, children, ...props }) {
49
- return (_jsx("div", { className: "ds-tabs__frame", children: _jsx("div", { className: "ds-tabs__scroller", children: _jsx(ArkTabs.List, { className: cx('ds-tabs__list', fitted && 'ds-tabs__list--fitted', className), ...props, children: children }) }) }));
57
+ export function TabsList({ fitted = false, appearance = 'segmented', className, children, onFocus, onBlur, ...props }) {
58
+ const { value } = useTabsContext();
59
+ const [focusWithin, setFocusWithin] = useState(false);
60
+ const tabIndex = value == null && !focusWithin ? 0 : undefined;
61
+ const handleFocus = (event) => {
62
+ onFocus?.(event);
63
+ setFocusWithin(true);
64
+ if (event.target !== event.currentTarget)
65
+ return;
66
+ event.currentTarget.querySelector('[role="tab"]:not([disabled])')?.focus();
67
+ };
68
+ const handleBlur = (event) => {
69
+ onBlur?.(event);
70
+ if (!event.currentTarget.contains(event.relatedTarget))
71
+ setFocusWithin(false);
72
+ };
73
+ const list = (_jsx(ArkTabs.List, { className: cx('ds-tabs__list', fitted && 'ds-tabs__list--fitted', appearance === 'plain' && 'ds-tabs__list--plain', className), tabIndex: tabIndex, onFocus: handleFocus, onBlur: handleBlur, ...props, children: children }));
74
+ if (appearance === 'plain')
75
+ return list;
76
+ return (_jsx("div", { className: "ds-tabs__frame", children: _jsx("div", { className: "ds-tabs__scroller", children: list }) }));
50
77
  }
51
78
  /**
52
79
  * A single tab. `value` must match the `value` of its {@link TabsContent}.
@@ -1 +1 @@
1
- {"version":3,"file":"tabs.js","sourceRoot":"","sources":["../../src/tabs/tabs.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,YAAY,CAAC;AACpB,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAI3B;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,IAAI,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAa;IAC/D,OAAO,CACL,KAAC,OAAO,CAAC,IAAI,IAAC,SAAS,EAAE,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,KAAM,KAAK,YACzD,QAAQ,GACI,CAChB,CAAC;AACJ,CAAC;AAUD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,QAAQ,CAAC,EAAE,MAAM,GAAG,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAiB;IACvF,OAAO,CACL,cAAK,SAAS,EAAC,gBAAgB,YAC7B,cAAK,SAAS,EAAC,mBAAmB,YAChC,KAAC,OAAO,CAAC,IAAI,IACX,SAAS,EAAE,EAAE,CAAC,eAAe,EAAE,MAAM,IAAI,uBAAuB,EAAE,SAAS,CAAC,KACxE,KAAK,YAER,QAAQ,GACI,GACX,GACF,CACP,CAAC;AACJ,CAAC;AAID;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAoB;IAC7E,OAAO,CACL,KAAC,OAAO,CAAC,OAAO,IAAC,SAAS,EAAE,EAAE,CAAC,kBAAkB,EAAE,SAAS,CAAC,KAAM,KAAK,YACrE,QAAQ,GACO,CACnB,CAAC;AACJ,CAAC;AAID,qEAAqE;AACrE,MAAM,UAAU,WAAW,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAoB;IAC7E,OAAO,CACL,KAAC,OAAO,CAAC,OAAO,IAAC,SAAS,EAAE,EAAE,CAAC,kBAAkB,EAAE,SAAS,CAAC,KAAM,KAAK,YACrE,QAAQ,GACO,CACnB,CAAC;AACJ,CAAC","sourcesContent":["import { Tabs as ArkTabs } from '@ark-ui/react/tabs';\nimport type { ComponentProps } from 'react';\nimport './tabs.css';\nimport { cx } from '../cx';\n\nexport type TabsProps = ComponentProps<typeof ArkTabs.Root>;\n\n/**\n * Tabbed disclosure built on Ark UI.\n *\n * Ark supplies the behaviour that is easy to get wrong by hand: roving\n * tabindex, arrow-key navigation, `aria-controls`/`aria-labelledby` wiring\n * between triggers and panels, and activation mode. This wrapper contributes\n * only `ds-` class names and the `--ds-tabs-*` token bindings.\n *\n * Use as a compound component:\n *\n * ```tsx\n * <Tabs defaultValue=\"weekly\">\n * <TabsList aria-label=\"Goal timeframe\">\n * <TabsTrigger value=\"weekly\">Weekly</TabsTrigger>\n * <TabsTrigger value=\"quarterly\">Quarterly</TabsTrigger>\n * </TabsList>\n * <TabsContent value=\"weekly\">…</TabsContent>\n * <TabsContent value=\"quarterly\">…</TabsContent>\n * </Tabs>\n * ```\n *\n * Pass `activationMode=\"manual\"` when panel content is expensive — arrow keys\n * then move focus without switching panels until Enter or Space.\n */\nexport function Tabs({ className, children, ...props }: TabsProps) {\n return (\n <ArkTabs.Root className={cx('ds-tabs', className)} {...props}>\n {children}\n </ArkTabs.Root>\n );\n}\n\nexport interface TabsListProps extends ComponentProps<typeof ArkTabs.List> {\n /**\n * Distribute triggers evenly across the full width instead of sizing them\n * to their content. Matches the segmented-control look.\n */\n fitted?: boolean;\n}\n\n/**\n * Container for the tab triggers. Renders with `role=\"tablist\"`.\n *\n * Always give this an `aria-label` (or `aria-labelledby`) when the page has\n * more than one tablist — screen reader users otherwise get several\n * indistinguishable \"tab list\" landmarks.\n *\n * When the triggers need more room than the list has, the list scrolls\n * sideways inside its own box instead of widening the page. Focusing a\n * trigger, by Tab or by arrow key, brings it into view.\n *\n * The two elements around the list exist for the focus ring, which reaches\n * past the list's edge. The scroller is that much larger than the list, so\n * scrolling does not clip the ring; the frame keeps the scroller's extra size\n * from widening whatever the tabs sit in. `tabs.css` has the arithmetic.\n */\nexport function TabsList({ fitted = false, className, children, ...props }: TabsListProps) {\n return (\n <div className=\"ds-tabs__frame\">\n <div className=\"ds-tabs__scroller\">\n <ArkTabs.List\n className={cx('ds-tabs__list', fitted && 'ds-tabs__list--fitted', className)}\n {...props}\n >\n {children}\n </ArkTabs.List>\n </div>\n </div>\n );\n}\n\nexport type TabsTriggerProps = ComponentProps<typeof ArkTabs.Trigger>;\n\n/**\n * A single tab. `value` must match the `value` of its {@link TabsContent}.\n *\n * Disabled triggers are skipped by arrow-key navigation, which Ark handles.\n */\nexport function TabsTrigger({ className, children, ...props }: TabsTriggerProps) {\n return (\n <ArkTabs.Trigger className={cx('ds-tabs__trigger', className)} {...props}>\n {children}\n </ArkTabs.Trigger>\n );\n}\n\nexport type TabsContentProps = ComponentProps<typeof ArkTabs.Content>;\n\n/** Panel for one tab. `value` must match its {@link TabsTrigger}. */\nexport function TabsContent({ className, children, ...props }: TabsContentProps) {\n return (\n <ArkTabs.Content className={cx('ds-tabs__content', className)} {...props}>\n {children}\n </ArkTabs.Content>\n );\n}\n"]}
1
+ {"version":3,"file":"tabs.js","sourceRoot":"","sources":["../../src/tabs/tabs.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAwC,QAAQ,EAAE,MAAM,OAAO,CAAC;AACvE,OAAO,YAAY,CAAC;AACpB,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAI3B;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,IAAI,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAa;IAC/D,OAAO,CACL,KAAC,OAAO,CAAC,IAAI,IAAC,SAAS,EAAE,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,KAAM,KAAK,YACzD,QAAQ,GACI,CAChB,CAAC;AACJ,CAAC;AA+BD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,QAAQ,CAAC,EACvB,MAAM,GAAG,KAAK,EACd,UAAU,GAAG,WAAW,EACxB,SAAS,EACT,QAAQ,EACR,OAAO,EACP,MAAM,EACN,GAAG,KAAK,EACM;IACd,MAAM,EAAE,KAAK,EAAE,GAAG,cAAc,EAAE,CAAC;IACnC,MAAM,CAA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GAAG,KAAK,EAAoB;IAC7E,OAAO,CACL,KAAC,OAAO,CAAC,OAAO,IAAC,SAAS,EAAE,EAAE,CAAC,kBAAkB,EAAE,SAAS,CAAC,KAAM,KAAK,YACrE,QAAQ,GACO,CACnB,CAAC;AACJ,CAAC;AAID,qEAAqE;AACrE,MAAM,UAAU,WAAW,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAoB;IAC7E,OAAO,CACL,KAAC,OAAO,CAAC,OAAO,IAAC,SAAS,EAAE,EAAE,CAAC,kBAAkB,EAAE,SAAS,CAAC,KAAM,KAAK,YACrE,QAAQ,GACO,CACnB,CAAC;AACJ,CAAC","sourcesContent":["import { Tabs as ArkTabs, useTabsContext } from '@ark-ui/react/tabs';\nimport { type ComponentProps, type FocusEvent, useState } from 'react';\nimport './tabs.css';\nimport { cx } from '../cx';\n\nexport type TabsProps = ComponentProps<typeof ArkTabs.Root>;\n\n/**\n * Tabbed disclosure built on Ark UI.\n *\n * Ark supplies the behaviour that is easy to get wrong by hand: roving\n * tabindex, arrow-key navigation, `aria-controls`/`aria-labelledby` wiring\n * between triggers and panels, and activation mode. This wrapper contributes\n * only `ds-` class names and the `--ds-tabs-*` token bindings.\n *\n * Use as a compound component:\n *\n * ```tsx\n * <Tabs defaultValue=\"weekly\">\n * <TabsList aria-label=\"Goal timeframe\">\n * <TabsTrigger value=\"weekly\">Weekly</TabsTrigger>\n * <TabsTrigger value=\"quarterly\">Quarterly</TabsTrigger>\n * </TabsList>\n * <TabsContent value=\"weekly\">…</TabsContent>\n * <TabsContent value=\"quarterly\">…</TabsContent>\n * </Tabs>\n * ```\n *\n * Pass `activationMode=\"manual\"` when panel content is expensive — arrow keys\n * then move focus without switching panels until Enter or Space.\n */\nexport function Tabs({ className, children, ...props }: TabsProps) {\n return (\n <ArkTabs.Root className={cx('ds-tabs', className)} {...props}>\n {children}\n </ArkTabs.Root>\n );\n}\n\n/**\n * `fitted` shares the width of one row, and a `plain` row wraps, so the two\n * cannot be combined: the pairing is a compile error rather than a\n * convention, as Badge's `BadgeLook` is.\n */\ntype TabsListLook =\n | {\n /**\n * `segmented` (default) sets the triggers on a track and scrolls them\n * sideways when they outgrow the list. `plain` drops the track and its\n * padding: every trigger takes the list's radius as its own shape, the\n * triggers sit `--ds-layout-gap` apart, and a row that outgrows the list\n * wraps onto a new line instead of scrolling. For triggers that carry\n * their own look, such as a row of avatars or category badges.\n */\n appearance?: 'segmented';\n /**\n * Distribute triggers evenly across the full width instead of sizing\n * them to their content. Matches the segmented-control look.\n */\n fitted?: boolean;\n }\n | { appearance: 'plain'; fitted?: never };\n\nexport type TabsListProps = ComponentProps<typeof ArkTabs.List> & TabsListLook;\n\n/** `segmented` sets the triggers on a track; `plain` lets each stand alone and wraps the row. */\nexport type TabsListAppearance = NonNullable<TabsListProps['appearance']>;\n\n/**\n * Container for the tab triggers. Renders with `role=\"tablist\"`.\n *\n * Always give this an `aria-label` (or `aria-labelledby`) when the page has\n * more than one tablist — screen reader users otherwise get several\n * indistinguishable \"tab list\" landmarks.\n *\n * When the triggers need more room than a segmented list has, the list\n * scrolls sideways inside its own box instead of widening the page. Focusing\n * a trigger, by Tab or by arrow key, brings it into view. A `plain` list\n * wraps instead, so it neither scrolls nor needs the elements below.\n *\n * The two elements around a segmented list exist for the focus ring, which\n * reaches past the list's edge. The scroller is that much larger than the\n * list, so scrolling does not clip the ring; the frame keeps the scroller's\n * extra size from widening whatever the tabs sit in. `tabs.css` has the\n * arithmetic.\n *\n * Ark makes the selected trigger the list's one tab stop. While no tab is\n * selected (a controlled `value` of `null`) it leaves none, so the list\n * itself takes the stop and hands focus to its first enabled trigger, as the\n * selected one would have had it; once focus is inside, the list steps out of\n * the tab order again, so Tab and Shift+Tab leave the row in one press.\n */\nexport function TabsList({\n fitted = false,\n appearance = 'segmented',\n className,\n children,\n onFocus,\n onBlur,\n ...props\n}: TabsListProps) {\n const { value } = useTabsContext();\n const [focusWithin, setFocusWithin] = useState(false);\n const tabIndex = value == null && !focusWithin ? 0 : undefined;\n\n const handleFocus = (event: FocusEvent<HTMLDivElement>) => {\n onFocus?.(event);\n setFocusWithin(true);\n if (event.target !== event.currentTarget) return;\n event.currentTarget.querySelector<HTMLElement>('[role=\"tab\"]:not([disabled])')?.focus();\n };\n const handleBlur = (event: FocusEvent<HTMLDivElement>) => {\n onBlur?.(event);\n if (!event.currentTarget.contains(event.relatedTarget)) setFocusWithin(false);\n };\n\n const list = (\n <ArkTabs.List\n className={cx(\n 'ds-tabs__list',\n fitted && 'ds-tabs__list--fitted',\n appearance === 'plain' && 'ds-tabs__list--plain',\n className,\n )}\n tabIndex={tabIndex}\n onFocus={handleFocus}\n onBlur={handleBlur}\n {...props}\n >\n {children}\n </ArkTabs.List>\n );\n\n if (appearance === 'plain') return list;\n return (\n <div className=\"ds-tabs__frame\">\n <div className=\"ds-tabs__scroller\">{list}</div>\n </div>\n );\n}\n\nexport type TabsTriggerProps = ComponentProps<typeof ArkTabs.Trigger>;\n\n/**\n * A single tab. `value` must match the `value` of its {@link TabsContent}.\n *\n * Disabled triggers are skipped by arrow-key navigation, which Ark handles.\n */\nexport function TabsTrigger({ className, children, ...props }: TabsTriggerProps) {\n return (\n <ArkTabs.Trigger className={cx('ds-tabs__trigger', className)} {...props}>\n {children}\n </ArkTabs.Trigger>\n );\n}\n\nexport type TabsContentProps = ComponentProps<typeof ArkTabs.Content>;\n\n/** Panel for one tab. `value` must match its {@link TabsTrigger}. */\nexport function TabsContent({ className, children, ...props }: TabsContentProps) {\n return (\n <ArkTabs.Content className={cx('ds-tabs__content', className)} {...props}>\n {children}\n </ArkTabs.Content>\n );\n}\n"]}
@@ -4,9 +4,15 @@ export type TooltipPlacement = 'top' | 'bottom' | 'left' | 'right';
4
4
  export interface TooltipProps {
5
5
  /** The caption: a few words, never a control. */
6
6
  content: ReactNode;
7
- /** The element it captions. It keeps its own accessible name. */
7
+ /**
8
+ * The element it captions. It keeps its own accessible name. A disabled
9
+ * one (`disabled` set) is captioned too, and described for good; see the
10
+ * component's description.
11
+ */
8
12
  children: ReactElement<{
9
13
  id?: string;
14
+ disabled?: boolean;
15
+ 'aria-describedby'?: string;
10
16
  }>;
11
17
  /**
12
18
  * What the caption is to assistive tech. `description` (default) adds it
@@ -33,6 +39,16 @@ export interface TooltipProps {
33
39
  * for another control whose meaning its glyph alone does not say. Anything
34
40
  * a user must read to act belongs on the page, not in a tooltip: touch
35
41
  * screens never show one.
42
+ *
43
+ * A disabled control can carry the reason it is disabled ("Month planning
44
+ * is coming later"): the pointer still shows the caption, and since nothing
45
+ * can focus the control, its description holds the same words for good, for
46
+ * assistive technology, which still reads a disabled control. When the
47
+ * control is another part's trigger that finds itself by id (a tab), give it
48
+ * that id and the part the same one through its `ids`, as `CategoryTabs`
49
+ * does; the caption's trigger id otherwise replaces it. The keyboard skips a
50
+ * disabled control, so a sighted keyboard user never sees the caption: put
51
+ * anything they need on the page.
36
52
  */
37
53
  export declare function Tooltip({ content, children, kind, placement, }: TooltipProps): import("react/jsx-runtime").JSX.Element;
38
54
  //# sourceMappingURL=tooltip.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../src/tooltip/tooltip.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,SAAS,EAAmC,MAAM,OAAO,CAAC;AAE3F,OAAO,eAAe,CAAC;AAEvB,MAAM,MAAM,gBAAgB,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AAEnE,MAAM,WAAW,YAAY;IAC3B,iDAAiD;IACjD,OAAO,EAAE,SAAS,CAAC;IACnB,iEAAiE;IACjE,QAAQ,EAAE,YAAY,CAAC;QAAE,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACxC;;;;;OAKG;IACH,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC;IAC/B,uEAAuE;IACvE,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,OAAO,CAAC,EACtB,OAAO,EACP,QAAQ,EACR,IAAoB,EACpB,SAAiB,GAClB,EAAE,YAAY,2CA0Dd"}
1
+ {"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../src/tooltip/tooltip.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,SAAS,EAMf,MAAM,OAAO,CAAC;AAGf,OAAO,eAAe,CAAC;AAMvB,MAAM,MAAM,gBAAgB,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AAEnE,MAAM,WAAW,YAAY;IAC3B,iDAAiD;IACjD,OAAO,EAAE,SAAS,CAAC;IACnB;;;;OAIG;IACH,QAAQ,EAAE,YAAY,CAAC;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;QAAC,kBAAkB,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACzF;;;;;OAKG;IACH,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC;IAC/B,uEAAuE;IACvE,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,OAAO,CAAC,EACtB,OAAO,EACP,QAAQ,EACR,IAAoB,EACpB,SAAiB,GAClB,EAAE,YAAY,2CAiFd"}
@@ -1,9 +1,13 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Portal } from '@ark-ui/react/portal';
3
3
  import { Tooltip as ArkTooltip } from '@ark-ui/react/tooltip';
4
- import { useContext, useEffect, useState } from 'react';
4
+ import { cloneElement, useContext, useEffect, useId, useState, useSyncExternalStore, } from 'react';
5
5
  import { PortalContainerContext } from '../portal-container';
6
+ import { VisuallyHidden } from '../visually-hidden/visually-hidden';
6
7
  import './tooltip.css';
8
+ const neverChanges = () => () => { };
9
+ const isClient = () => true;
10
+ const isServer = () => false;
7
11
  /**
8
12
  * A caption that shows while the pointer rests on its trigger or the
9
13
  * keyboard focuses it, built on Ark UI's Tooltip. Esc and moving away hide
@@ -19,6 +23,16 @@ import './tooltip.css';
19
23
  * for another control whose meaning its glyph alone does not say. Anything
20
24
  * a user must read to act belongs on the page, not in a tooltip: touch
21
25
  * screens never show one.
26
+ *
27
+ * A disabled control can carry the reason it is disabled ("Month planning
28
+ * is coming later"): the pointer still shows the caption, and since nothing
29
+ * can focus the control, its description holds the same words for good, for
30
+ * assistive technology, which still reads a disabled control. When the
31
+ * control is another part's trigger that finds itself by id (a tab), give it
32
+ * that id and the part the same one through its `ids`, as `CategoryTabs`
33
+ * does; the caption's trigger id otherwise replaces it. The keyboard skips a
34
+ * disabled control, so a sighted keyboard user never sees the caption: put
35
+ * anything they need on the page.
22
36
  */
23
37
  export function Tooltip({ content, children, kind = 'description', placement = 'top', }) {
24
38
  const portalContainer = useContext(PortalContainerContext);
@@ -28,6 +42,7 @@ export function Tooltip({ content, children, kind = 'description', placement = '
28
42
  * one. A description the trigger sets itself still wins.
29
43
  */
30
44
  const triggerDescription = kind === 'label' ? '' : undefined;
45
+ const describesDisabled = children.props.disabled === true && kind === 'description';
31
46
  /*
32
47
  * A trigger that is itself another part's asChild trigger (a Menu's, a
33
48
  * Dialog's close button, a Calendar arrow) takes that part's id, and the
@@ -36,7 +51,23 @@ export function Tooltip({ content, children, kind = 'description', placement = '
36
51
  * with keeps the lookup on the real element.
37
52
  */
38
53
  const triggerId = children.props.id;
54
+ const descriptionId = useId();
39
55
  const [open, setOpen] = useState(false);
56
+ const description = [children.props['aria-describedby'], descriptionId].filter(Boolean).join(' ');
57
+ /*
58
+ * A disabled control's description holds the caption for good, since
59
+ * nothing can focus the control to show it. The words live at the end of
60
+ * the page, not beside the control: a list that may hold only its items (a
61
+ * tablist, a menu) would otherwise hold a stray text.
62
+ */
63
+ const trigger = describesDisabled
64
+ ? cloneElement(children, { 'aria-describedby': description })
65
+ : children;
66
+ /*
67
+ * A portal renders in place on the server and while hydrating, which would
68
+ * put the words inside the list after all, so they wait for the client.
69
+ */
70
+ const onClient = useSyncExternalStore(neverChanges, isClient, isServer);
40
71
  /*
41
72
  * Escape hides the caption and goes on to whatever else it means: Zag's
42
73
  * own Escape handling stops the key at the document, so a keyboard drag
@@ -53,6 +84,6 @@ export function Tooltip({ content, children, kind = 'description', placement = '
53
84
  document.addEventListener('keydown', hide);
54
85
  return () => document.removeEventListener('keydown', hide);
55
86
  }, [open]);
56
- return (_jsxs(ArkTooltip.Root, { lazyMount: true, unmountOnExit: true, positioning: { placement, gutter: 6 }, ids: triggerId ? { trigger: triggerId } : undefined, open: open, onOpenChange: (details) => setOpen(details.open), closeOnEscape: false, children: [_jsx(ArkTooltip.Trigger, { asChild: true, "aria-describedby": triggerDescription, children: children }), _jsx(Portal, { container: portalContainer, children: _jsx(ArkTooltip.Positioner, { children: _jsx(ArkTooltip.Content, { className: "ds-tooltip__content", "aria-hidden": kind === 'label' ? true : undefined, children: content }) }) })] }));
87
+ return (_jsxs(ArkTooltip.Root, { lazyMount: true, unmountOnExit: true, positioning: { placement, gutter: 6 }, ids: triggerId ? { trigger: triggerId } : undefined, open: open, onOpenChange: (details) => setOpen(details.open), closeOnEscape: false, children: [_jsx(ArkTooltip.Trigger, { asChild: true, "aria-describedby": triggerDescription, children: trigger }), describesDisabled && onClient && (_jsx(Portal, { container: portalContainer, children: _jsx(VisuallyHidden, { id: descriptionId, children: content }) })), _jsx(Portal, { container: portalContainer, children: _jsx(ArkTooltip.Positioner, { children: _jsx(ArkTooltip.Content, { className: "ds-tooltip__content", "aria-hidden": kind === 'label' ? true : undefined, children: content }) }) })] }));
57
88
  }
58
89
  //# sourceMappingURL=tooltip.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip.js","sourceRoot":"","sources":["../../src/tooltip/tooltip.tsx"],"names":[],"mappings":";AAAA,OAAO,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,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,EACrC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,SAAS,EACnD,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAChD,aAAa,EAAE,KAAK,aAEpB,KAAC,UAAU,CAAC,OAAO,IAAC,OAAO,4BAAmB,kBAAkB,YAC7D,QAAQ,GACU,EACrB,KAAC,MAAM,IAAC,SAAS,EAAE,eAAe,YAChC,KAAC,UAAU,CAAC,UAAU,cACpB,KAAC,UAAU,CAAC,OAAO,IACjB,SAAS,EAAC,qBAAqB,iBAClB,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,YAE/C,OAAO,GACW,GACC,GACjB,IACO,CACnB,CAAC;AACJ,CAAC","sourcesContent":["import { Portal } from '@ark-ui/react/portal';\nimport { Tooltip as ArkTooltip } from '@ark-ui/react/tooltip';\nimport { type ReactElement, type ReactNode, useContext, useEffect, useState } from 'react';\nimport { PortalContainerContext } from '../portal-container';\nimport './tooltip.css';\n\nexport type TooltipPlacement = 'top' | 'bottom' | 'left' | 'right';\n\nexport interface TooltipProps {\n /** The caption: a few words, never a control. */\n content: ReactNode;\n /** The element it captions. It keeps its own accessible name. */\n children: ReactElement<{ id?: string }>;\n /**\n * What the caption is to assistive tech. `description` (default) adds it\n * to the trigger's description while it shows. `label` says it repeats the\n * trigger's accessible name, as an icon-only button's caption does, so it\n * is left out and the name is announced once.\n */\n kind?: 'description' | 'label';\n /** Side of the trigger it opens on, flipping when there is no room. */\n placement?: TooltipPlacement;\n}\n\n/**\n * A caption that shows while the pointer rests on its trigger or the\n * keyboard focuses it, built on Ark UI's Tooltip. Esc and moving away hide\n * it; it never takes focus and holds nothing to click.\n *\n * ```tsx\n * <Tooltip content=\"Archive\">\n * <button type=\"button\" aria-label=\"Archive Run 10k\">…</button>\n * </Tooltip>\n * ```\n *\n * `IconButton` shows one with its label by default. Reach for it directly\n * for another control whose meaning its glyph alone does not say. Anything\n * a user must read to act belongs on the page, not in a tooltip: touch\n * screens never show one.\n */\nexport function Tooltip({\n content,\n children,\n kind = 'description',\n placement = 'top',\n}: TooltipProps) {\n const portalContainer = useContext(PortalContainerContext);\n /*\n * Zag points the trigger's description at the caption while it shows, and\n * only a defined value overrides it, so a label caption passes an empty\n * one. A description the trigger sets itself still wins.\n */\n const triggerDescription = kind === 'label' ? '' : undefined;\n /*\n * A trigger that is itself another part's asChild trigger (a Menu's, a\n * Dialog's close button, a Calendar arrow) takes that part's id, and the\n * child's props win the merge, so Zag would look for its own id and find\n * nothing to place the caption against. Naming the id the trigger ends up\n * with keeps the lookup on the real element.\n */\n const triggerId = children.props.id;\n const [open, setOpen] = useState(false);\n\n /*\n * Escape hides the caption and goes on to whatever else it means: Zag's\n * own Escape handling stops the key at the document, so a keyboard drag\n * could not be cancelled and a dialog would not close while a caption\n * showed.\n */\n useEffect(() => {\n if (!open) return;\n const hide = (event: KeyboardEvent) => {\n if (event.key === 'Escape') setOpen(false);\n };\n document.addEventListener('keydown', hide);\n return () => document.removeEventListener('keydown', hide);\n }, [open]);\n\n return (\n <ArkTooltip.Root\n lazyMount\n unmountOnExit\n positioning={{ placement, gutter: 6 }}\n ids={triggerId ? { trigger: triggerId } : undefined}\n open={open}\n onOpenChange={(details) => setOpen(details.open)}\n closeOnEscape={false}\n >\n <ArkTooltip.Trigger asChild aria-describedby={triggerDescription}>\n {children}\n </ArkTooltip.Trigger>\n <Portal container={portalContainer}>\n <ArkTooltip.Positioner>\n <ArkTooltip.Content\n className=\"ds-tooltip__content\"\n aria-hidden={kind === 'label' ? true : undefined}\n >\n {content}\n </ArkTooltip.Content>\n </ArkTooltip.Positioner>\n </Portal>\n </ArkTooltip.Root>\n );\n}\n"]}
1
+ {"version":3,"file":"tooltip.js","s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AC7D,OAAO,GACW,EACpB,iBAAiB,IAAI,QAAQ,IAAI,CAChC,KAAC,MAAM,IAAC,SAAS,EAAE,eAAe,YAChC,KAAC,cAAc,IAAC,EAAE,EAAE,aAAa,YAAG,OAAO,GAAkB,GACtD,CACV,EACD,KAAC,MAAM,IAAC,SAAS,EAAE,eAAe,YAChC,KAAC,UAAU,CAAC,UAAU,cACpB,KAAC,UAAU,CAAC,OAAO,IACjB,SAAS,EAAC,qBAAqB,iBAClB,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,YAE/C,OAAO,GACW,GACC,GACjB,IACO,CACnB,CAAC;AACJ,CAAC","sourcesContent":["import { Portal } from '@ark-ui/react/portal';\nimport { Tooltip as ArkTooltip } from '@ark-ui/react/tooltip';\nimport {\n cloneElement,\n type ReactElement,\n type ReactNode,\n useContext,\n useEffect,\n useId,\n useState,\n useSyncExternalStore,\n} from 'react';\nimport { PortalContainerContext } from '../portal-container';\nimport { VisuallyHidden } from '../visually-hidden/visually-hidden';\nimport './tooltip.css';\n\nconst neverChanges = () => () => {};\nconst isClient = () => true;\nconst isServer = () => false;\n\nexport type TooltipPlacement = 'top' | 'bottom' | 'left' | 'right';\n\nexport interface TooltipProps {\n /** The caption: a few words, never a control. */\n content: ReactNode;\n /**\n * The element it captions. It keeps its own accessible name. A disabled\n * one (`disabled` set) is captioned too, and described for good; see the\n * component's description.\n */\n children: ReactElement<{ id?: string; disabled?: boolean; 'aria-describedby'?: string }>;\n /**\n * What the caption is to assistive tech. `description` (default) adds it\n * to the trigger's description while it shows. `label` says it repeats the\n * trigger's accessible name, as an icon-only button's caption does, so it\n * is left out and the name is announced once.\n */\n kind?: 'description' | 'label';\n /** Side of the trigger it opens on, flipping when there is no room. */\n placement?: TooltipPlacement;\n}\n\n/**\n * A caption that shows while the pointer rests on its trigger or the\n * keyboard focuses it, built on Ark UI's Tooltip. Esc and moving away hide\n * it; it never takes focus and holds nothing to click.\n *\n * ```tsx\n * <Tooltip content=\"Archive\">\n * <button type=\"button\" aria-label=\"Archive Run 10k\">…</button>\n * </Tooltip>\n * ```\n *\n * `IconButton` shows one with its label by default. Reach for it directly\n * for another control whose meaning its glyph alone does not say. Anything\n * a user must read to act belongs on the page, not in a tooltip: touch\n * screens never show one.\n *\n * A disabled control can carry the reason it is disabled (\"Month planning\n * is coming later\"): the pointer still shows the caption, and since nothing\n * can focus the control, its description holds the same words for good, for\n * assistive technology, which still reads a disabled control. When the\n * control is another part's trigger that finds itself by id (a tab), give it\n * that id and the part the same one through its `ids`, as `CategoryTabs`\n * does; the caption's trigger id otherwise replaces it. The keyboard skips a\n * disabled control, so a sighted keyboard user never sees the caption: put\n * anything they need on the page.\n */\nexport function Tooltip({\n content,\n children,\n kind = 'description',\n placement = 'top',\n}: TooltipProps) {\n const portalContainer = useContext(PortalContainerContext);\n /*\n * Zag points the trigger's description at the caption while it shows, and\n * only a defined value overrides it, so a label caption passes an empty\n * one. A description the trigger sets itself still wins.\n */\n const triggerDescription = kind === 'label' ? '' : undefined;\n const describesDisabled = children.props.disabled === true && kind === 'description';\n /*\n * A trigger that is itself another part's asChild trigger (a Menu's, a\n * Dialog's close button, a Calendar arrow) takes that part's id, and the\n * child's props win the merge, so Zag would look for its own id and find\n * nothing to place the caption against. Naming the id the trigger ends up\n * with keeps the lookup on the real element.\n */\n const triggerId = children.props.id;\n const descriptionId = useId();\n const [open, setOpen] = useState(false);\n\n const description = [children.props['aria-describedby'], descriptionId].filter(Boolean).join(' ');\n /*\n * A disabled control's description holds the caption for good, since\n * nothing can focus the control to show it. The words live at the end of\n * the page, not beside the control: a list that may hold only its items (a\n * tablist, a menu) would otherwise hold a stray text.\n */\n const trigger = describesDisabled\n ? cloneElement(children, { 'aria-describedby': description })\n : children;\n /*\n * A portal renders in place on the server and while hydrating, which would\n * put the words inside the list after all, so they wait for the client.\n */\n const onClient = useSyncExternalStore(neverChanges, isClient, isServer);\n\n /*\n * Escape hides the caption and goes on to whatever else it means: Zag's\n * own Escape handling stops the key at the document, so a keyboard drag\n * could not be cancelled and a dialog would not close while a caption\n * showed.\n */\n useEffect(() => {\n if (!open) return;\n const hide = (event: KeyboardEvent) => {\n if (event.key === 'Escape') setOpen(false);\n };\n document.addEventListener('keydown', hide);\n return () => document.removeEventListener('keydown', hide);\n }, [open]);\n\n return (\n <ArkTooltip.Root\n lazyMount\n unmountOnExit\n positioning={{ placement, gutter: 6 }}\n ids={triggerId ? { trigger: triggerId } : undefined}\n open={open}\n onOpenChange={(details) => setOpen(details.open)}\n closeOnEscape={false}\n >\n <ArkTooltip.Trigger asChild aria-describedby={triggerDescription}>\n {trigger}\n </ArkTooltip.Trigger>\n {describesDisabled && onClient && (\n <Portal container={portalContainer}>\n <VisuallyHidden id={descriptionId}>{content}</VisuallyHidden>\n </Portal>\n )}\n <Portal container={portalContainer}>\n <ArkTooltip.Positioner>\n <ArkTooltip.Content\n className=\"ds-tooltip__content\"\n aria-hidden={kind === 'label' ? true : undefined}\n >\n {content}\n </ArkTooltip.Content>\n </ArkTooltip.Positioner>\n </Portal>\n </ArkTooltip.Root>\n );\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manakind/ui-core",
3
- "version": "0.35.0",
3
+ "version": "0.37.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -412,7 +412,7 @@
412
412
  },
413
413
  "devDependencies": {
414
414
  "@manakind/ds-config": "*",
415
- "@manakind/manuia-tokens": "0.33.0",
415
+ "@manakind/manuia-tokens": "0.35.0",
416
416
  "@testing-library/jest-dom": "^6.9.1",
417
417
  "@testing-library/react": "^16.3.2",
418
418
  "@testing-library/user-event": "^14.6.1",