@manakind/ui-core 0.32.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.
- package/dist/ark-native-input.d.ts +65 -0
- package/dist/ark-native-input.d.ts.map +1 -0
- package/dist/ark-native-input.js +72 -0
- package/dist/ark-native-input.js.map +1 -0
- package/dist/badge/badge.css +6 -0
- package/dist/badge/badge.d.ts +4 -3
- package/dist/badge/badge.d.ts.map +1 -1
- package/dist/badge/badge.js.map +1 -1
- package/dist/checkbox/checkbox.d.ts.map +1 -1
- package/dist/checkbox/checkbox.js +11 -27
- package/dist/checkbox/checkbox.js.map +1 -1
- package/dist/icon-defaults.d.ts +1 -1
- package/dist/icon-defaults.d.ts.map +1 -1
- package/dist/icon-defaults.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/radio-group/radio-group.d.ts.map +1 -1
- package/dist/radio-group/radio-group.js +7 -21
- package/dist/radio-group/radio-group.js.map +1 -1
- package/dist/segment-group/segment-group.d.ts.map +1 -1
- package/dist/segment-group/segment-group.js +7 -26
- package/dist/segment-group/segment-group.js.map +1 -1
- package/dist/switch/switch.d.ts.map +1 -1
- package/dist/switch/switch.js +11 -24
- package/dist/switch/switch.js.map +1 -1
- package/dist/table/index.d.ts +3 -0
- package/dist/table/index.d.ts.map +1 -0
- package/dist/table/index.js +2 -0
- package/dist/table/index.js.map +1 -0
- package/dist/table/table.css +189 -0
- package/dist/table/table.css.d.ts +2 -0
- package/dist/table/table.d.ts +144 -0
- package/dist/table/table.d.ts.map +1 -0
- package/dist/table/table.js +95 -0
- package/dist/table/table.js.map +1 -0
- package/package.json +2 -2
|
@@ -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"]}
|
package/dist/badge/badge.css
CHANGED
|
@@ -118,6 +118,12 @@
|
|
|
118
118
|
color: var(--ds-badge-outline-text);
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
&.ds-badge--neutral {
|
|
122
|
+
background-color: transparent;
|
|
123
|
+
border-color: var(--ds-badge-neutral-border);
|
|
124
|
+
color: var(--ds-badge-neutral-text);
|
|
125
|
+
}
|
|
126
|
+
|
|
121
127
|
&.ds-badge--info {
|
|
122
128
|
background-color: var(--ds-badge-info-bg);
|
|
123
129
|
color: var(--ds-badge-info-text);
|
package/dist/badge/badge.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ark } from '@ark-ui/react/factory';
|
|
|
2
2
|
import type { ComponentProps } from 'react';
|
|
3
3
|
import { type IconSource } from '../icon';
|
|
4
4
|
import './badge.css';
|
|
5
|
-
export type BadgeVariant = 'solid' | 'muted' | 'outline' | 'info' | 'success' | 'warning' | 'danger';
|
|
5
|
+
export type BadgeVariant = 'solid' | 'muted' | 'outline' | 'neutral' | 'info' | 'success' | 'warning' | 'danger';
|
|
6
6
|
export type BadgeShape = 'pill' | 'circle';
|
|
7
7
|
/**
|
|
8
8
|
* `compact` hides the label, so it may only be used with a glyph to replace it
|
|
@@ -30,8 +30,9 @@ type BadgeLook = {
|
|
|
30
30
|
* Visual treatment.
|
|
31
31
|
*
|
|
32
32
|
* `solid` is the emphatic one — use it sparingly, at most once in a view.
|
|
33
|
-
* `muted` and `outline` are the neutral workhorses. `
|
|
34
|
-
*
|
|
33
|
+
* `muted` and `outline` are the neutral workhorses. `neutral` is
|
|
34
|
+
* outline's edge in the body text colour, for a settled state. `info`,
|
|
35
|
+
* `success`, `warning`, and `danger` are tinted status treatments.
|
|
35
36
|
*/
|
|
36
37
|
variant?: BadgeVariant;
|
|
37
38
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"badge.d.ts","sourceRoot":"","sources":["../../src/badge/badge.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAC5C,OAA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,UAAU,CAAA;CAAE,CAAC;AAEvD;;;;GAIG;AACH,KAAK,SAAS,GACV;IACE;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,QAAQ,CAAC;CACvB,GACD;IAAE,OAAO,CAAC,EAAE,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAAC,UAAU,EAAE,OAAO,CAAA;CAAE,CAAC;AAEtE;;;;;GAKG;AACH,KAAK,eAAe,GAChB;IACE;;;;;;OAMG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;CACtB,GACD;IAAE,cAAc,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC;AAEnC,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,GACvE,YAAY,GACZ,SAAS,GACT,eAAe,GAAG;IAChB;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAEJ,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC;AAoBpE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,KAAK,CAAC,EACpB,OAAiB,EACjB,KAAc,EACd,UAAqB,EACrB,cAAc,EACd,IAAI,EACJ,OAAe,EACf,IAAY,EACZ,SAAS,EACT,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,UAAU,2CAyCZ"}
|
package/dist/badge/badge.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"badge.js","sourceRoot":"","sources":["../../src/badge/badge.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAE5C,OAAO,EAAE,IAAI,EA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,IAAI,gBAAgB,EACxB,SAAS,CACV,KACG,KAAK,aAER,IAAI,IAAI,KAAC,IAAI,IAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAC,IAAI,EAAC,UAAU,SAAG,EACnD,KAAK,IACG,CACZ,CAAC;AACJ,CAAC","sourcesContent":["import { ark } from '@ark-ui/react/factory';\nimport type { ComponentProps } from 'react';\nimport { Icon, type IconSource } from '../icon';\nimport './badge.css';\nimport { cx } from '../cx';\n\nexport type BadgeVariant =\n | 'solid'\n | 'muted'\n | 'outline'\n | 'neutral'\n | 'info'\n | 'success'\n | 'warning'\n | 'danger';\n\nexport type BadgeShape = 'pill' | 'circle';\n\n/**\n * `compact` hides the label, so it may only be used with a glyph to replace it\n * and a name to announce — otherwise the badge is a bare colour chip, and\n * colour alone is never a signal.\n *\n * Expressed as a discriminated union so the pairing is a compile error rather\n * than a convention, mirroring `IconProps`' label/decorative union.\n */\ntype BadgeCompact =\n | { compact: true; icon: IconSource; 'aria-label': string }\n | { compact?: false | undefined; icon?: IconSource };\n\n/**\n * `plain` drops the fill, so a variant's text must read on the surface behind\n * it. Every variant's does except `solid`, whose text colour is made for its\n * own dark fill and disappears without it, so that pairing is a compile error.\n */\ntype BadgeLook =\n | {\n /**\n * Visual treatment.\n *\n * `solid` is the emphatic one — use it sparingly, at most once in a view.\n * `muted` and `outline` are the neutral workhorses. `neutral` is\n * outline's edge in the body text colour, for a settled state. `info`,\n * `success`, `warning`, and `danger` are tinted status treatments.\n */\n variant?: BadgeVariant;\n /**\n * `filled` (default) draws the variant's fill and border. `plain` drops\n * both and keeps the variant's colour on the glyph and label, for a\n * status that sits inside a busier composition and should not add a\n * chip of its own. Its text is then measured against the surface\n * behind it, not against a tint.\n */\n appearance?: 'filled';\n }\n | { variant?: Exclude<BadgeVariant, 'solid'>; appearance: 'plain' };\n\n/**\n * `labelClassName` lets a composition hide the label (a container query, say),\n * so the badge must then carry its own name: without `aria-label` a hidden\n * label leaves the badge unnamed, since the glyph is always decorative.\n * Required here the same way `compact` requires it.\n */\ntype BadgeLabelClass =\n | {\n /**\n * Your own class on the label wrapper, so a composition can style the\n * label — for instance hide it from a container query when space runs\n * out — without selecting `ui-core`'s classes. The wrapper exists only\n * when there is an `icon`, so a label can never be hidden without a glyph\n * left in its place: colour alone is never the signal.\n */\n labelClassName: string;\n 'aria-label': string;\n }\n | { labelClassName?: undefined };\n\nexport type BadgeProps = Omit<ComponentProps<typeof ark.span>, 'asChild'> &\n BadgeCompact &\n BadgeLook &\n BadgeLabelClass & {\n /**\n * `pill` is the default. `circle` is for counts: a true circle at one or two\n * digits, and a fixed-height lozenge beyond that.\n *\n * The height is pinned on purpose — see the note in `badge.css`. An earlier\n * `aspect-ratio` grew a three-digit count in both directions, which made the\n * badge taller than its row and broke the nested radius of any track it sat\n * in.\n *\n * Only use it for short numerics. Words in a circle wrap badly, and past two\n * digits the shape stops being a circle anyway.\n */\n shape?: BadgeShape;\n /**\n * Set the label as a small-caps label: uppercase, in the product's label\n * face, weight and tracking, the same style as `Text`'s `caps`. For a\n * category or tag rather than a count.\n */\n caps?: boolean;\n };\n\nexport type BadgeAppearance = NonNullable<BadgeProps['appearance']>;\n\n/*\n * `icon` and `compact` are declared on `BadgeCompact` above rather than here,\n * so their docs live with the union that constrains them:\n *\n * icon — glyph before the label, supplied by the product so this package\n * never imports an icon set. Always decorative; the label beside\n * it says the same thing, and when the label is collapsed the\n * badge's own `aria-label` carries the name. Announcing both would\n * read the status twice.\n *\n * compact — collapse to the glyph alone: square geometry, no visible label.\n * Requires `icon` and `aria-label`, enforced by the union.\n *\n * For a badge that should collapse only when space runs out, leave `compact`\n * off, pass a `labelClassName`, and hide that class from a container query —\n * GoalCard's status badge is the worked example.\n */\n\n/**\n * Small inline label for counts, states, and categories.\n *\n * Renders a `span`, so a badge is decorative text by default. If the badge\n * carries meaning that is not repeated in nearby text — a count, a status —\n * give it an `aria-label` so it is announced usefully rather than as a bare\n * number. Labelling it also switches it to `role=\"img\"`, because `aria-label`\n * on a role-less `span` is prohibited and would not be announced.\n *\n * A badge is not a button. If it needs to be clickable, put it inside one.\n *\n * Colour alone must never be the only signal a badge carries. Pair a status\n * variant with text (or an `aria-label`) that says the same thing.\n *\n * @example Status that survives a narrow card\n * ```tsx\n * <Badge variant=\"success\" icon={CheckIcon} aria-label=\"Completed\">\n * Completed\n * </Badge>\n * ```\n * Reads as \"Completed\" wide, collapses to the glyph when the container\n * shrinks, and announces the same name at every width.\n */\nexport function Badge({\n variant = 'muted',\n shape = 'pill',\n appearance = 'filled',\n labelClassName,\n icon,\n compact = false,\n caps = false,\n className,\n children,\n ...props\n}: BadgeProps) {\n /*\n * ARIA prohibits `aria-label` on a role-less `span` (it resolves to\n * `role=\"generic\"`), so the label is not reliably announced — axe reports\n * `aria-prohibited-attr`. Since the whole point of the label is to replace\n * the bare text, `role=\"img\"` is the honest role: it makes the element a\n * single labelled node and the label becomes its accessible name.\n *\n * Only applied when a label is actually present. An unlabelled badge is\n * decorative text and should stay a plain `span`.\n */\n const labelled = props['aria-label'] !== undefined || props['aria-labelledby'] !== undefined;\n\n /*\n * Wrapped only when there is a glyph, because the wrapper exists to be\n * collapsed against one. A text-only badge keeps its bare-text DOM.\n */\n const label = icon ? (\n <span className={cx('ds-badge__label', labelClassName)}>{children}</span>\n ) : (\n children\n );\n\n return (\n <ark.span\n role={labelled ? 'img' : undefined}\n className={cx(\n 'ds-badge',\n `ds-badge--${variant}`,\n `ds-badge--${shape}`,\n appearance === 'plain' && 'ds-badge--plain',\n compact && 'ds-badge--compact',\n caps && 'ds-badge--caps',\n className,\n )}\n {...props}\n >\n {icon && <Icon source={icon} size=\"sm\" decorative />}\n {label}\n </ark.span>\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkbox.d.ts","sourceRoot":"","sources":["../../src/checkbox/checkbox.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"checkbox.d.ts","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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 {
|
|
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
|
|
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
|
-
|
|
53
|
-
inputRef.current.checked = checked;
|
|
33
|
+
restoreNativeInputs(rootRef.current, checked);
|
|
54
34
|
};
|
|
55
|
-
|
|
56
|
-
|
|
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,
|
|
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,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAClG,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,IAAI,EAAmB,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AA+DnD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,QAAQ,CAAC,EACvB,KAAK,EACL,OAAO,EACP,cAAc,EACd,eAAe,EACf,IAAI,GAAG,IAAI,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,GACrB;IACd,MAAM,KAAK,GAAG,eAAe,EAAE,CAAC;IAChC,MAAM,SAAS,GAAG,aAAa,IAAI,KAAK,CAAC,KAAK,CAAC;IAC/C,MAAM,OAAO,GAAG,MAAM,CAAmB,IAAI,CAAC,CAAC;IAE/C,MAAM,GAAG,GAAG,kBAAkB,EAAE,CAAC;IAEjC,MAAM,mBAAmB,GAAG,CAAC,OAA+C,EAAE,EAAE;QAC9E,eAAe,EAAE,CAAC,OAAO,CAAC,OAAO,KAAK,IAAI,CAAC,CAAC;QAC5C,mBAAmB,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAChD,CAAC,CAAC;IAEF,MAAM,YAAY,GAAG,kBAAkB,CAAC,WAAW,CAAC,KAAK,EAAE;QACzD,KAAK;QACL,SAAS;QACT,SAAS,EAAE,oBAAoB;KAChC,CAAC,CAAC;IAEH,OAAO,CACL,MAAC,WAAW,CAAC,IAAI,IACf,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CAAC,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"]}
|
package/dist/icon-defaults.d.ts
CHANGED
|
@@ -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,
|
|
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,wGAAwG;IACxG,YAAY,EAAE,UAAU,CAAC;IACzB,iCAAiC;IACjC,WAAW,EAAE,UAAU,CAAC;IACxB,uEAAuE;IACvE,KAAK,EAAE,UAAU,CAAC;IAClB,mDAAmD;IACnD,KAAK,EAAE,UAAU,CAAC;IAClB,sBAAsB;IACtB,GAAG,EAAE,UAAU,CAAC;CACjB;AAYD,MAAM,WAAW,yBAAyB;IACxC,gGAAgG;IAChG,KAAK,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAC7B,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,yBAAyB,2CAOlF;AAED,mFAAmF;AACnF,wBAAgB,eAAe,IAAI,YAAY,CAE9C"}
|
|
@@ -1 +1 @@
|
|
|
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. */\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
package/dist/index.d.ts.map
CHANGED
|
@@ -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,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,C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,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,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 './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;
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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;;;;;;;;;;;;;;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C,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;
|
|
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,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,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sx, 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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|