@manakind/ui-core 0.39.0 → 0.41.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/radio-group/radio-group.css +74 -2
- package/dist/radio-group/radio-group.d.ts +23 -9
- package/dist/radio-group/radio-group.d.ts.map +1 -1
- package/dist/radio-group/radio-group.js +16 -8
- package/dist/radio-group/radio-group.js.map +1 -1
- package/dist/segment-group/segment-group.css +20 -0
- package/package.json +2 -2
|
@@ -6,9 +6,11 @@
|
|
|
6
6
|
gap: var(--ds-radio-group-gap);
|
|
7
7
|
overflow-wrap: anywhere;
|
|
8
8
|
|
|
9
|
+
/* Field's label, as every control a form names; the choices keep the group's own size. */
|
|
9
10
|
& .ds-radio-group__label {
|
|
10
|
-
color: var(--ds-
|
|
11
|
-
font-size: var(--ds-
|
|
11
|
+
color: var(--ds-field-label-text);
|
|
12
|
+
font-size: var(--ds-field-label-font-size);
|
|
13
|
+
font-weight: var(--ds-field-label-font-weight);
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
/*
|
|
@@ -30,6 +32,12 @@
|
|
|
30
32
|
}
|
|
31
33
|
}
|
|
32
34
|
|
|
35
|
+
/* A Field's hint, as a Field's sits between its label and its control. */
|
|
36
|
+
& .ds-radio-group__hint {
|
|
37
|
+
color: var(--ds-field-hint-text);
|
|
38
|
+
font-size: var(--ds-field-hint-font-size);
|
|
39
|
+
}
|
|
40
|
+
|
|
33
41
|
/* The hint text of a Field: a choice's description reads as the hint under a label. */
|
|
34
42
|
& .ds-radio-group__description {
|
|
35
43
|
grid-column: 2;
|
|
@@ -133,4 +141,68 @@
|
|
|
133
141
|
justify-content: center;
|
|
134
142
|
}
|
|
135
143
|
}
|
|
144
|
+
|
|
145
|
+
/*
|
|
146
|
+
* Chips: the label above a row of chips that wraps. Each chip is the whole
|
|
147
|
+
* click target; the hidden radio inside it carries the state and the
|
|
148
|
+
* keyboard. Chosen, the chip fills with the primary's tint and its border
|
|
149
|
+
* takes a step of the primary that clears 3:1 on the surface around it;
|
|
150
|
+
* keyboard focus is the focus ring drawn outside it.
|
|
151
|
+
*/
|
|
152
|
+
.ds-radio-group--chips {
|
|
153
|
+
& .ds-radio-group__chips {
|
|
154
|
+
display: flex;
|
|
155
|
+
flex-wrap: wrap;
|
|
156
|
+
gap: var(--ds-radio-group-chip-gap);
|
|
157
|
+
max-width: 100%;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
& .ds-radio-group__item {
|
|
161
|
+
box-sizing: border-box;
|
|
162
|
+
display: inline-flex;
|
|
163
|
+
align-items: center;
|
|
164
|
+
padding: var(--ds-radio-group-chip-padding-block) var(--ds-radio-group-chip-padding-inline);
|
|
165
|
+
border: 1px solid var(--ds-radio-group-chip-border);
|
|
166
|
+
border-radius: var(--ds-radio-group-chip-radius);
|
|
167
|
+
background-color: var(--ds-radio-group-chip-bg);
|
|
168
|
+
color: var(--ds-radio-group-chip-text);
|
|
169
|
+
font-size: var(--ds-radio-group-chip-font-size);
|
|
170
|
+
transition:
|
|
171
|
+
background-color 150ms cubic-bezier(0, 0, 0.2, 1),
|
|
172
|
+
border-color 150ms cubic-bezier(0, 0, 0.2, 1),
|
|
173
|
+
color 150ms cubic-bezier(0, 0, 0.2, 1);
|
|
174
|
+
|
|
175
|
+
&[data-hover]:not([data-disabled], [data-state="checked"]) {
|
|
176
|
+
border-color: var(--ds-radio-group-chip-border-hover);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
&[data-state="checked"] {
|
|
180
|
+
border-color: var(--ds-radio-group-chip-border-checked);
|
|
181
|
+
background-color: var(--ds-radio-group-chip-bg-checked);
|
|
182
|
+
color: var(--ds-radio-group-chip-text-checked);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
&[data-focus-visible] {
|
|
186
|
+
outline: 2px solid var(--ds-radio-group-focus-ring);
|
|
187
|
+
outline-offset: 2px;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
&[data-disabled] {
|
|
191
|
+
opacity: var(--ds-opacity-disabled);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/*
|
|
197
|
+
* Forced colours paint every chip in the same system colours, so the tint
|
|
198
|
+
* that marks the chosen one vanishes. Its border thickens instead, as a
|
|
199
|
+
* chosen card's does, and the padding gives back what it takes.
|
|
200
|
+
*/
|
|
201
|
+
@media (forced-colors: active) {
|
|
202
|
+
.ds-radio-group--chips .ds-radio-group__item[data-state="checked"] {
|
|
203
|
+
border-width: 2px;
|
|
204
|
+
padding: calc(var(--ds-radio-group-chip-padding-block) - 1px)
|
|
205
|
+
calc(var(--ds-radio-group-chip-padding-inline) - 1px);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
136
208
|
}
|
|
@@ -9,7 +9,8 @@ export interface RadioGroupItem {
|
|
|
9
9
|
* A sentence under the label saying what the choice means, in the muted
|
|
10
10
|
* hint text of a Field. The radio's accessible description; its name
|
|
11
11
|
* stays the label alone. A list group shows it; a cards group, which
|
|
12
|
-
* shows `visual` instead,
|
|
12
|
+
* shows `visual` instead, and a chips group, which shows the label
|
|
13
|
+
* alone, ignore it.
|
|
13
14
|
*/
|
|
14
15
|
description?: string;
|
|
15
16
|
/** Individually disable this choice without removing it. */
|
|
@@ -17,12 +18,16 @@ export interface RadioGroupItem {
|
|
|
17
18
|
/**
|
|
18
19
|
* A picture of the choice, above its label on a `cards` group: a swatch,
|
|
19
20
|
* a badge, a preview. Decorative: the label names the choice. A `list`
|
|
20
|
-
* group ignores it.
|
|
21
|
+
* or `chips` group ignores it.
|
|
21
22
|
*/
|
|
22
23
|
visual?: ReactNode;
|
|
23
24
|
}
|
|
24
|
-
/**
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* `list` (default) sets radios one under the other; `cards` sets each choice
|
|
27
|
+
* on a card in a wrapping grid; `chips` sets each choice on a chip in a
|
|
28
|
+
* wrapping row.
|
|
29
|
+
*/
|
|
30
|
+
export type RadioGroupAppearance = 'list' | 'cards' | 'chips';
|
|
26
31
|
/**
|
|
27
32
|
* A radio group has to have a name, expressed as a union so an unnamed group
|
|
28
33
|
* is a compile error rather than an axe finding, as `SegmentGroup` does.
|
|
@@ -43,12 +48,20 @@ type RadioGroupName = {
|
|
|
43
48
|
export type RadioGroupProps = RadioGroupName & {
|
|
44
49
|
/** The choices, in order. */
|
|
45
50
|
items: RadioGroupItem[];
|
|
51
|
+
/**
|
|
52
|
+
* A sentence about the whole choice, between the label and the choices in
|
|
53
|
+
* a Field's hint text, as a Field's hint sits between its label and its
|
|
54
|
+
* control. It is the group's accessible description.
|
|
55
|
+
*/
|
|
56
|
+
hint?: ReactNode;
|
|
46
57
|
/**
|
|
47
58
|
* `list` (default) sets a radio beside each label, one under the other.
|
|
48
59
|
* `cards` sets each choice on a card, its `visual` above its label, in a
|
|
49
60
|
* grid that fills the width and wraps; the chosen card carries a heavier
|
|
50
61
|
* ring instead of a radio. For choices told apart by how they look, such
|
|
51
|
-
* as colours or themes.
|
|
62
|
+
* as colours or themes. `chips` sets each label on a chip, in a row that
|
|
63
|
+
* wraps; the chosen chip fills with the primary's tint instead of a radio.
|
|
64
|
+
* For a few short choices in a form, read at a glance.
|
|
52
65
|
*/
|
|
53
66
|
appearance?: RadioGroupAppearance;
|
|
54
67
|
/**
|
|
@@ -114,10 +127,11 @@ export type RadioGroupProps = RadioGroupName & {
|
|
|
114
127
|
* ```
|
|
115
128
|
*
|
|
116
129
|
* Choices told apart by how they look (a colour, a theme) take
|
|
117
|
-
* `appearance="cards"`, each with a `visual`. A few short choices
|
|
118
|
-
*
|
|
119
|
-
* a `
|
|
130
|
+
* `appearance="cards"`, each with a `visual`. A few short choices in a
|
|
131
|
+
* form, whose labels may run to several words, take `appearance="chips"`.
|
|
132
|
+
* A few short choices that switch a view are a `SegmentGroup`; a long list
|
|
133
|
+
* is a `Select`.
|
|
120
134
|
*/
|
|
121
|
-
export declare function RadioGroup({ label, items, value, defaultValue, onValueChange, disabled, name, appearance, className, 'aria-label': ariaLabel, }: RadioGroupProps): import("react/jsx-runtime").JSX.Element;
|
|
135
|
+
export declare function RadioGroup({ label, items, hint, value, defaultValue, onValueChange, disabled, name, appearance, className, 'aria-label': ariaLabel, }: RadioGroupProps): import("react/jsx-runtime").JSX.Element;
|
|
122
136
|
export {};
|
|
123
137
|
//# 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,EAAiB,MAAM,OAAO,CAAC;AACtD,OAAO,mBAAmB,CAAC;AAI3B,MAAM,WAAW,cAAc;IAC7B,0EAA0E;IAC1E,KAAK,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IACd
|
|
1
|
+
{"version":3,"file":"radio-group.d.ts","sourceRoot":"","sources":["../../src/radio-group/radio-group.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAiB,MAAM,OAAO,CAAC;AACtD,OAAO,mBAAmB,CAAC;AAI3B,MAAM,WAAW,cAAc;IAC7B,0EAA0E;IAC1E,KAAK,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IACd;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,MAAM,CAAC,EAAE,SAAS,CAAC;CACpB;AAED;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAE9D;;;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,6BAA6B;IAC7B,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB;;;;OAIG;IACH,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB;;;;;;;;OAQG;IACH,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAClC;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,KAAK,EACL,IAAI,EACJ,KAAK,EACL,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,IAAI,EACJ,UAAmB,EACnB,SAAS,EACT,YAAY,EAAE,SAAS,GACxB,EAAE,eAAe,2CA4EjB"}
|
|
@@ -51,26 +51,34 @@ import { cx } from '../cx';
|
|
|
51
51
|
* ```
|
|
52
52
|
*
|
|
53
53
|
* Choices told apart by how they look (a colour, a theme) take
|
|
54
|
-
* `appearance="cards"`, each with a `visual`. A few short choices
|
|
55
|
-
*
|
|
56
|
-
* a `
|
|
54
|
+
* `appearance="cards"`, each with a `visual`. A few short choices in a
|
|
55
|
+
* form, whose labels may run to several words, take `appearance="chips"`.
|
|
56
|
+
* A few short choices that switch a view are a `SegmentGroup`; a long list
|
|
57
|
+
* is a `Select`.
|
|
57
58
|
*/
|
|
58
|
-
export function RadioGroup({ label, items, value, defaultValue, onValueChange, disabled, name, appearance = 'list', className, 'aria-label': ariaLabel, }) {
|
|
59
|
+
export function RadioGroup({ label, items, hint, value, defaultValue, onValueChange, disabled, name, appearance = 'list', className, 'aria-label': ariaLabel, }) {
|
|
59
60
|
const cards = appearance === 'cards';
|
|
61
|
+
const list = appearance === 'list';
|
|
60
62
|
const rootRef = useRef(null);
|
|
61
63
|
const descriptionId = useId();
|
|
64
|
+
const hintId = hint ? `${descriptionId}-hint` : undefined;
|
|
62
65
|
const handleValueChange = radioGroupChangeHandler(rootRef, value, onValueChange);
|
|
63
66
|
const visibleLabel = renderVisibleLabel(ArkRadioGroup.Label, {
|
|
64
67
|
label,
|
|
65
68
|
ariaLabel,
|
|
66
69
|
className: 'ds-radio-group__label',
|
|
67
70
|
});
|
|
68
|
-
const marker = (item) =>
|
|
71
|
+
const marker = (item) => {
|
|
72
|
+
if (cards) {
|
|
73
|
+
return (_jsx("span", { className: "ds-radio-group__visual", "aria-hidden": true, children: item.visual }));
|
|
74
|
+
}
|
|
75
|
+
return list ? _jsx(ArkRadioGroup.ItemControl, { className: "ds-radio-group__control" }) : null;
|
|
76
|
+
};
|
|
69
77
|
const renderItem = (item, index) => {
|
|
70
|
-
const describedBy =
|
|
78
|
+
const describedBy = list && item.description ? `${descriptionId}-${index}` : undefined;
|
|
71
79
|
return (_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 }), describedBy && (_jsx("span", { id: describedBy, className: "ds-radio-group__description", children: item.description })), _jsx(ArkRadioGroup.ItemHiddenInput, { "aria-describedby": describedBy })] }, item.value));
|
|
72
80
|
};
|
|
73
|
-
const choices =
|
|
74
|
-
return (_jsxs(ArkRadioGroup.Root, { ref: rootRef, className: cx('ds-radio-group',
|
|
81
|
+
const choices = list ? (items.map(renderItem)) : (_jsx("div", { className: `ds-radio-group__${appearance}`, children: items.map(renderItem) }));
|
|
82
|
+
return (_jsxs(ArkRadioGroup.Root, { ref: rootRef, className: cx('ds-radio-group', !list && `ds-radio-group--${appearance}`, className), value: value, defaultValue: defaultValue, onValueChange: handleValueChange, disabled: disabled, name: name, orientation: "vertical", "aria-label": ariaLabel, "aria-describedby": hintId, children: [visibleLabel, hint && (_jsx("span", { id: hintId, className: "ds-radio-group__hint", children: hint })), choices] }));
|
|
75
83
|
}
|
|
76
84
|
//# 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,KAAK,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,mBAAmB,CAAC;AAC3B,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AA2E3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;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,KAAK,GAAG,UAAU,KAAK,OAAO,CAAC;IACrC,MAAM,OAAO,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAC7C,MAAM,aAAa,GAAG,KAAK,EAAE,CAAC;IAE9B,MAAM,iBAAiB,GAAG,uBAAuB,CAAC,OAAO,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC;IAEjF,MAAM,YAAY,GAAG,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F,OAAO,CACL,MAAC,aAAa,CAAC,IAAI,IACjB,GAAG,EAAE,OAAO,EACZ,SAAS,EAAE,EAAE,CAAC,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, useId, 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 /**\n * A sentence under the label saying what the choice means, in the muted\n * hint text of a Field. The radio's accessible description; its name\n * stays the label alone. A list group shows it; a cards group, which\n * shows `visual` instead, ignores it.\n */\n description?: 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 * A choice whose label alone would not say what it does takes a\n * `description`, a sentence set under the label and read as the radio's\n * description:\n *\n * ```tsx\n * <RadioGroup\n * label=\"Completing a task\"\n * items={[\n * {\n * value: 'archive',\n * label: 'Archive',\n * description: 'Done tasks leave the list and stay searchable.',\n * },\n * {\n * value: 'keep',\n * label: 'Keep in place',\n * description: 'Done tasks stay where they are, struck through.',\n * },\n * ]}\n * value={mode}\n * onValueChange={setMode}\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 const descriptionId = useId();\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, index: number) => {\n const describedBy = !cards && item.description ? `${descriptionId}-${index}` : undefined;\n return (\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\">\n {item.label}\n </ArkRadioGroup.ItemText>\n {describedBy && (\n <span id={describedBy} className=\"ds-radio-group__description\">\n {item.description}\n </span>\n )}\n <ArkRadioGroup.ItemHiddenInput aria-describedby={describedBy} />\n </ArkRadioGroup.Item>\n );\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
|
+
{"version":3,"file":"radio-group.js","sourceRoot":"","sources":["../../src/radio-group/radio-group.tsx"],"names":[],"mappings":";AAAA,OAAO,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AAiB,EAChC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,WAAW,EAAC,UAAU,gBACV,SAAS,sBACH,MAAM,aAEvB,YAAY,EACZ,IAAI,IAAI,CACP,eAAM,EAAE,EAAE,MAAM,EAAE,SAAS,EAAC,sBAAsB,YAC/C,IAAI,GACA,CACR,EACA,OAAO,IACW,CACtB,CAAC;AACJ,CAAC","sourcesContent":["import { RadioGroup as ArkRadioGroup } from '@ark-ui/react/radio-group';\nimport { type ReactNode, useId, 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 /**\n * A sentence under the label saying what the choice means, in the muted\n * hint text of a Field. The radio's accessible description; its name\n * stays the label alone. A list group shows it; a cards group, which\n * shows `visual` instead, and a chips group, which shows the label\n * alone, ignore it.\n */\n description?: 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 * or `chips` group ignores it.\n */\n visual?: ReactNode;\n}\n\n/**\n * `list` (default) sets radios one under the other; `cards` sets each choice\n * on a card in a wrapping grid; `chips` sets each choice on a chip in a\n * wrapping row.\n */\nexport type RadioGroupAppearance = 'list' | 'cards' | 'chips';\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 * A sentence about the whole choice, between the label and the choices in\n * a Field's hint text, as a Field's hint sits between its label and its\n * control. It is the group's accessible description.\n */\n hint?: ReactNode;\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. `chips` sets each label on a chip, in a row that\n * wraps; the chosen chip fills with the primary's tint instead of a radio.\n * For a few short choices in a form, read at a glance.\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 * A choice whose label alone would not say what it does takes a\n * `description`, a sentence set under the label and read as the radio's\n * description:\n *\n * ```tsx\n * <RadioGroup\n * label=\"Completing a task\"\n * items={[\n * {\n * value: 'archive',\n * label: 'Archive',\n * description: 'Done tasks leave the list and stay searchable.',\n * },\n * {\n * value: 'keep',\n * label: 'Keep in place',\n * description: 'Done tasks stay where they are, struck through.',\n * },\n * ]}\n * value={mode}\n * onValueChange={setMode}\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 in a\n * form, whose labels may run to several words, take `appearance=\"chips\"`.\n * A few short choices that switch a view are a `SegmentGroup`; a long list\n * is a `Select`.\n */\nexport function RadioGroup({\n label,\n items,\n hint,\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 list = appearance === 'list';\n const rootRef = useRef<HTMLDivElement>(null);\n const descriptionId = useId();\n const hintId = hint ? `${descriptionId}-hint` : undefined;\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 if (cards) {\n return (\n <span className=\"ds-radio-group__visual\" aria-hidden>\n {item.visual}\n </span>\n );\n }\n return list ? <ArkRadioGroup.ItemControl className=\"ds-radio-group__control\" /> : null;\n };\n const renderItem = (item: RadioGroupItem, index: number) => {\n const describedBy = list && item.description ? `${descriptionId}-${index}` : undefined;\n return (\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\">\n {item.label}\n </ArkRadioGroup.ItemText>\n {describedBy && (\n <span id={describedBy} className=\"ds-radio-group__description\">\n {item.description}\n </span>\n )}\n <ArkRadioGroup.ItemHiddenInput aria-describedby={describedBy} />\n </ArkRadioGroup.Item>\n );\n };\n\n const choices = list ? (\n items.map(renderItem)\n ) : (\n <div className={`ds-radio-group__${appearance}`}>{items.map(renderItem)}</div>\n );\n\n return (\n <ArkRadioGroup.Root\n ref={rootRef}\n className={cx('ds-radio-group', !list && `ds-radio-group--${appearance}`, className)}\n value={value}\n defaultValue={defaultValue}\n onValueChange={handleValueChange}\n disabled={disabled}\n name={name}\n orientation=\"vertical\"\n aria-label={ariaLabel}\n aria-describedby={hintId}\n >\n {visibleLabel}\n {hint && (\n <span id={hintId} className=\"ds-radio-group__hint\">\n {hint}\n </span>\n )}\n {choices}\n </ArkRadioGroup.Root>\n );\n}\n"]}
|
|
@@ -204,4 +204,24 @@
|
|
|
204
204
|
--_segment-group-padding-inline: var(--ds-segment-group-dense-padding-inline);
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
|
+
|
|
208
|
+
/*
|
|
209
|
+
* Forced colours paint the checked segment's fill over with the system's
|
|
210
|
+
* colours, so every segment looks the same. The checked one draws a ring in
|
|
211
|
+
* the text colour inside its edge instead; focus, which moves the choice,
|
|
212
|
+
* keeps its own ring outside. The custom field loses its box-shadow there,
|
|
213
|
+
* so its border thickens, the padding giving back what it takes.
|
|
214
|
+
*/
|
|
215
|
+
@media (forced-colors: active) {
|
|
216
|
+
.ds-segment-group__item[data-state="checked"]:not([data-focus-visible]) {
|
|
217
|
+
outline: 2px solid currentColor;
|
|
218
|
+
outline-offset: -2px;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
.ds-segment-group__custom[data-state="checked"] {
|
|
222
|
+
border-width: 2px;
|
|
223
|
+
padding: calc(var(--_segment-group-padding-block) - 1px)
|
|
224
|
+
calc(var(--_segment-group-padding-inline) - 1px);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
207
227
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manakind/ui-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -420,7 +420,7 @@
|
|
|
420
420
|
},
|
|
421
421
|
"devDependencies": {
|
|
422
422
|
"@manakind/ds-config": "*",
|
|
423
|
-
"@manakind/manuia-tokens": "0.
|
|
423
|
+
"@manakind/manuia-tokens": "0.38.0",
|
|
424
424
|
"@testing-library/jest-dom": "^6.9.1",
|
|
425
425
|
"@testing-library/react": "^16.3.2",
|
|
426
426
|
"@testing-library/user-event": "^14.6.1",
|