@manakind/ui-core 0.13.0 → 0.14.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/README.md +2 -0
- package/dist/checkbox/checkbox.d.ts +5 -1
- package/dist/checkbox/checkbox.d.ts.map +1 -1
- package/dist/checkbox/checkbox.js +17 -2
- package/dist/checkbox/checkbox.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/segment-group/index.d.ts +2 -0
- package/dist/segment-group/index.d.ts.map +1 -0
- package/dist/segment-group/index.js +2 -0
- package/dist/segment-group/index.js.map +1 -0
- package/dist/segment-group/segment-group.css +111 -0
- package/dist/segment-group/segment-group.css.d.ts +2 -0
- package/dist/segment-group/segment-group.d.ts +85 -0
- package/dist/segment-group/segment-group.d.ts.map +1 -0
- package/dist/segment-group/segment-group.js +64 -0
- package/dist/segment-group/segment-group.js.map +1 -0
- package/dist/switch/switch.d.ts +5 -1
- package/dist/switch/switch.d.ts.map +1 -1
- package/dist/switch/switch.js +13 -3
- package/dist/switch/switch.js.map +1 -1
- package/package.json +10 -2
package/README.md
CHANGED
|
@@ -69,6 +69,7 @@ separately, so an app can load only what it renders.
|
|
|
69
69
|
| `@manakind/ui-core/checkbox` | `Checkbox` |
|
|
70
70
|
| `@manakind/ui-core/date-input` | `DateInput` |
|
|
71
71
|
| `@manakind/ui-core/progress` | `Progress` |
|
|
72
|
+
| `@manakind/ui-core/segment-group` | `SegmentGroup` |
|
|
72
73
|
| `@manakind/ui-core/select` | `Select` |
|
|
73
74
|
| `@manakind/ui-core/switch` | `Switch` |
|
|
74
75
|
| `@manakind/ui-core/field` | `Field`, `Input`, `Textarea`, `useFieldControl` |
|
|
@@ -85,6 +86,7 @@ separately, so an app can load only what it renders.
|
|
|
85
86
|
| `@manakind/ui-core/css/checkbox` | Checkbox structural CSS |
|
|
86
87
|
| `@manakind/ui-core/css/date-input` | DateInput structural CSS |
|
|
87
88
|
| `@manakind/ui-core/css/progress` | Progress structural CSS |
|
|
89
|
+
| `@manakind/ui-core/css/segment-group` | SegmentGroup structural CSS |
|
|
88
90
|
| `@manakind/ui-core/css/select` | Select structural CSS |
|
|
89
91
|
| `@manakind/ui-core/css/switch` | Switch structural CSS |
|
|
90
92
|
| `@manakind/ui-core/css/field` | Field, Input and Textarea structural CSS |
|
|
@@ -10,7 +10,11 @@ export type CheckboxSize = 'sm' | 'md' | 'lg';
|
|
|
10
10
|
type CheckboxName = {
|
|
11
11
|
/** Visible label. The whole label is the click target. */
|
|
12
12
|
label: ReactNode;
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* A different accessible name when the visible label alone would not
|
|
15
|
+
* say what the control is. Keep the visible words in it, so a voice
|
|
16
|
+
* user can still say what they see.
|
|
17
|
+
*/
|
|
14
18
|
'aria-label'?: string;
|
|
15
19
|
} | {
|
|
16
20
|
label?: undefined;
|
|
@@ -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","sourceRoot":"","sources":["../../src/checkbox/checkbox.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAiB,MAAM,OAAO,CAAC;AACtD,OAAO,gBAAgB,CAAC;AAGxB,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAErD,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE9C;;;;GAIG;AACH,KAAK,YAAY,GACb;IACE,0DAA0D;IAC1D,KAAK,EAAE,SAAS,CAAC;IACjB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GACD;IACE,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,8GAA8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useRef } from 'react';
|
|
3
|
+
import { useId, useRef } from 'react';
|
|
4
4
|
import './checkbox.css';
|
|
5
5
|
import { cx } from '../cx';
|
|
6
6
|
import { Check } from '../fallback-glyphs';
|
|
@@ -24,6 +24,20 @@ import { Icon } from '../icon/icon';
|
|
|
24
24
|
*/
|
|
25
25
|
export function Checkbox({ label, checked, defaultChecked, onCheckedChange, size = 'md', disabled, invalid, readOnly, required, name, value, indicator = Check, className, 'aria-label': ariaLabel, 'aria-describedby': ariaDescribedBy, }) {
|
|
26
26
|
const inputRef = useRef(null);
|
|
27
|
+
/*
|
|
28
|
+
* Zag always names the hidden input by its label part's id, which would
|
|
29
|
+
* outrank an `aria-label`. With both given, the visible label is plain
|
|
30
|
+
* text instead, so that id resolves to nothing and the `aria-label` wins;
|
|
31
|
+
* the root is still the `<label>`, so the text stays the click target.
|
|
32
|
+
*/
|
|
33
|
+
/*
|
|
34
|
+
* Ark hands a checkbox inside a Field the field's control and label ids,
|
|
35
|
+
* so two checkboxes in one field would share an id and both be named by
|
|
36
|
+
* the field's label. A checkbox names itself, so it keeps its own ids and
|
|
37
|
+
* takes only the states from a field around it.
|
|
38
|
+
*/
|
|
39
|
+
const ownId = useId();
|
|
40
|
+
const ids = { hiddenInput: `${ownId}:input`, label: `${ownId}:label` };
|
|
27
41
|
/*
|
|
28
42
|
* Ark renders the hidden input uncontrolled and syncs it only when its own
|
|
29
43
|
* state changes, so a controlled parent that declines a toggle would leave
|
|
@@ -36,6 +50,7 @@ export function Checkbox({ label, checked, defaultChecked, onCheckedChange, size
|
|
|
36
50
|
if (checked !== undefined && inputRef.current)
|
|
37
51
|
inputRef.current.checked = checked;
|
|
38
52
|
};
|
|
39
|
-
return (_jsxs(ArkCheckbox.Root, { className: cx('ds-checkbox', `ds-checkbox--${size}`, className), checked: checked, defaultChecked: defaultChecked, onCheckedChange: handleCheckedChange, disabled: disabled, invalid: invalid, readOnly: readOnly, required: required, name: name, value: value, children: [_jsx(ArkCheckbox.Control, { className: "ds-checkbox__control", children: _jsx(ArkCheckbox.Indicator, { className: "ds-checkbox__indicator", children: _jsx(Icon, { source: indicator, size: "sm", decorative: true }) }) }), label &&
|
|
53
|
+
return (_jsxs(ArkCheckbox.Root, { ids: ids, className: cx('ds-checkbox', `ds-checkbox--${size}`, className), checked: checked, defaultChecked: defaultChecked, onCheckedChange: handleCheckedChange, disabled: disabled, invalid: invalid, readOnly: readOnly, required: required, name: name, value: value, children: [_jsx(ArkCheckbox.Control, { className: "ds-checkbox__control", children: _jsx(ArkCheckbox.Indicator, { className: "ds-checkbox__indicator", children: _jsx(Icon, { source: indicator, size: "sm", decorative: true }) }) }), label &&
|
|
54
|
+
(ariaLabel ? (_jsx("span", { className: "ds-checkbox__label", children: label })) : (_jsx(ArkCheckbox.Label, { className: "ds-checkbox__label", children: label }))), _jsx(ArkCheckbox.HiddenInput, { ref: inputRef, "aria-label": ariaLabel, "aria-describedby": ariaDescribedBy, "aria-readonly": readOnly || undefined })] }));
|
|
40
55
|
}
|
|
41
56
|
//# 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,MAAM,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"checkbox.js","sourceRoot":"","sources":["../../src/checkbox/checkbox.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,IAAI,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAkB,KAAK,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,gBAAgB,CAAC;AACxB,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,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AC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,OAAO,EACL,KAAK,IAAI,aAAa,EACtB,YAAY,IAAI,oBAAoB,EACpC,KAAK,IAAI,aAAa,GACvB,MAAM,mBAAmB,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,OAAO,EACL,KAAK,IAAI,aAAa,EACtB,YAAY,IAAI,oBAAoB,EACpC,KAAK,IAAI,aAAa,GACvB,MAAM,mBAAmB,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,OAAO,EACL,KAAK,IAAI,aAAa,EACtB,YAAY,IAAI,oBAAoB,EACpC,KAAK,IAAI,aAAa,GACvB,MAAM,mBAAmB,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/segment-group/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,GACtB,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/segment-group/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,GAIb,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
@layer components {
|
|
2
|
+
.ds-segment-group {
|
|
3
|
+
display: inline-flex;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
gap: var(--ds-segment-group-label-gap);
|
|
6
|
+
max-width: 100%;
|
|
7
|
+
min-inline-size: 0;
|
|
8
|
+
overflow-wrap: anywhere;
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* Derived so a segment never curves more than the track it sits in.
|
|
12
|
+
* Underscore-prefixed, not `--ds-`: computed from two contract tokens and
|
|
13
|
+
* owned by the component, as Tabs derives its inner radius.
|
|
14
|
+
*/
|
|
15
|
+
--_segment-group-inner-radius: max(
|
|
16
|
+
0px,
|
|
17
|
+
calc(var(--ds-segment-group-track-radius) - var(--ds-segment-group-track-padding))
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
& .ds-segment-group__label {
|
|
21
|
+
min-inline-size: 0;
|
|
22
|
+
color: var(--ds-segment-group-label-text);
|
|
23
|
+
font-size: var(--_segment-group-font-size);
|
|
24
|
+
font-weight: var(--ds-segment-group-label-font-weight);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/*
|
|
28
|
+
* Equal columns, each as wide as the widest label, as a segmented control
|
|
29
|
+
* reads: no segment is wider for a longer word. Under a narrower
|
|
30
|
+
* container the columns shrink together (minmax lets them go below their
|
|
31
|
+
* content) and a word longer than its column breaks inside the segment,
|
|
32
|
+
* as every component lets a long word wrap.
|
|
33
|
+
*/
|
|
34
|
+
& .ds-segment-group__track {
|
|
35
|
+
display: grid;
|
|
36
|
+
grid-auto-flow: column;
|
|
37
|
+
grid-auto-columns: minmax(0, 1fr);
|
|
38
|
+
gap: var(--ds-segment-group-track-gap);
|
|
39
|
+
padding: var(--ds-segment-group-track-padding);
|
|
40
|
+
border-radius: var(--ds-segment-group-track-radius);
|
|
41
|
+
background-color: var(--ds-segment-group-track-bg);
|
|
42
|
+
max-width: 100%;
|
|
43
|
+
min-inline-size: 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/*
|
|
47
|
+
* The text is a flex item of its segment, so without this it keeps its
|
|
48
|
+
* content width and a long word overflows the segment instead of
|
|
49
|
+
* breaking inside it.
|
|
50
|
+
*/
|
|
51
|
+
& .ds-segment-group__item-text {
|
|
52
|
+
min-inline-size: 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/*
|
|
56
|
+
* Ark renders the item as the `<label>` of its hidden radio, so the whole
|
|
57
|
+
* segment is the hit area and the radio's focus is mirrored onto it as
|
|
58
|
+
* `data-focus-visible`, where the ring is drawn.
|
|
59
|
+
*/
|
|
60
|
+
& .ds-segment-group__item {
|
|
61
|
+
display: inline-flex;
|
|
62
|
+
align-items: center;
|
|
63
|
+
justify-content: center;
|
|
64
|
+
min-inline-size: 0;
|
|
65
|
+
overflow-wrap: anywhere;
|
|
66
|
+
text-align: center;
|
|
67
|
+
padding: var(--_segment-group-padding-block) var(--_segment-group-padding-inline);
|
|
68
|
+
border-radius: var(--_segment-group-inner-radius);
|
|
69
|
+
color: var(--ds-segment-group-item-text);
|
|
70
|
+
font-size: var(--_segment-group-font-size);
|
|
71
|
+
font-weight: var(--ds-segment-group-item-font-weight);
|
|
72
|
+
line-height: inherit;
|
|
73
|
+
cursor: pointer;
|
|
74
|
+
transition:
|
|
75
|
+
background-color 150ms cubic-bezier(0, 0, 0.2, 1),
|
|
76
|
+
color 150ms cubic-bezier(0, 0, 0.2, 1);
|
|
77
|
+
|
|
78
|
+
&[data-hover]:not([data-state="checked"]):not([data-disabled]) {
|
|
79
|
+
background-color: var(--ds-segment-group-item-bg-hover);
|
|
80
|
+
color: var(--ds-segment-group-item-text-hover);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
&[data-state="checked"] {
|
|
84
|
+
background-color: var(--ds-segment-group-item-bg-checked);
|
|
85
|
+
color: var(--ds-segment-group-item-text-checked);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
&[data-focus-visible] {
|
|
89
|
+
outline: 2px solid var(--ds-segment-group-focus-ring);
|
|
90
|
+
outline-offset: 3px;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
&[data-disabled] {
|
|
94
|
+
opacity: var(--ds-opacity-disabled);
|
|
95
|
+
cursor: not-allowed;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
&.ds-segment-group--sm {
|
|
100
|
+
--_segment-group-font-size: var(--ds-segment-group-size-sm-font-size);
|
|
101
|
+
--_segment-group-padding-block: var(--ds-segment-group-size-sm-padding-block);
|
|
102
|
+
--_segment-group-padding-inline: var(--ds-segment-group-size-sm-padding-inline);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
&.ds-segment-group--md {
|
|
106
|
+
--_segment-group-font-size: var(--ds-segment-group-size-md-font-size);
|
|
107
|
+
--_segment-group-padding-block: var(--ds-segment-group-size-md-padding-block);
|
|
108
|
+
--_segment-group-padding-inline: var(--ds-segment-group-size-md-padding-inline);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import './segment-group.css';
|
|
3
|
+
export type SegmentGroupSize = 'sm' | 'md';
|
|
4
|
+
export interface SegmentGroupItem {
|
|
5
|
+
/** Stable value reported by `onValueChange` and compared with `value`. */
|
|
6
|
+
value: string;
|
|
7
|
+
/** Text shown on the segment. Keep it to a word or two; a longer one wraps inside its segment. */
|
|
8
|
+
label: string;
|
|
9
|
+
/** Individually disable this choice without removing it. */
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A segment group has to have a name. A visible `label` is the one to reach
|
|
14
|
+
* for; expressed as a union so an unnamed group is a compile error rather
|
|
15
|
+
* than an axe finding, as `Checkbox` and `Switch` do.
|
|
16
|
+
*/
|
|
17
|
+
type SegmentGroupName = {
|
|
18
|
+
/** Visible label, rendered above the track and naming the group. */
|
|
19
|
+
label: ReactNode;
|
|
20
|
+
/**
|
|
21
|
+
* A different accessible name when the visible label alone would not
|
|
22
|
+
* say what the choice is. Keep the visible words in it ("Period" →
|
|
23
|
+
* "Reporting period"), so a voice user can still say what they see.
|
|
24
|
+
*/
|
|
25
|
+
'aria-label'?: string;
|
|
26
|
+
} | {
|
|
27
|
+
label?: undefined;
|
|
28
|
+
/** Accessible name when the surrounding heading or row already says what the choice is. */
|
|
29
|
+
'aria-label': string;
|
|
30
|
+
};
|
|
31
|
+
export type SegmentGroupProps = SegmentGroupName & {
|
|
32
|
+
/** The choices, in order. Exactly one is checked. */
|
|
33
|
+
items: SegmentGroupItem[];
|
|
34
|
+
/**
|
|
35
|
+
* Controlled value. `null` is controlled with nothing checked, for a form
|
|
36
|
+
* that starts without a choice; `undefined` leaves the component to own
|
|
37
|
+
* its value from `defaultValue` onward, as `Select` does.
|
|
38
|
+
*/
|
|
39
|
+
value?: string | null;
|
|
40
|
+
/** Initial value when uncontrolled. */
|
|
41
|
+
defaultValue?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Fired with the newly checked value. Choosing the checked segment again
|
|
44
|
+
* does nothing, so a consumer that saves on change never writes twice.
|
|
45
|
+
*/
|
|
46
|
+
onValueChange?: (value: string) => void;
|
|
47
|
+
/** Segment height and type scale. `sm` suits a toolbar or a card header. */
|
|
48
|
+
size?: SegmentGroupSize;
|
|
49
|
+
/** Disable every segment. The checked one keeps showing which is set. */
|
|
50
|
+
disabled?: boolean;
|
|
51
|
+
/** Name for native form participation through the hidden radio inputs. */
|
|
52
|
+
name?: string;
|
|
53
|
+
/** Extra class names appended after the `ds-segment-group` modifiers. */
|
|
54
|
+
className?: string;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* One choice among a few, shown as a row of segments, built on Ark UI's
|
|
58
|
+
* SegmentGroup: a radio group whose radios are drawn as one control.
|
|
59
|
+
*
|
|
60
|
+
* Ark owns the behaviour: hidden radio inputs carry the state, the arrow keys
|
|
61
|
+
* move the choice, and the whole segment is its radio's label. This wrapper
|
|
62
|
+
* contributes `ds-` classes, the `--ds-segment-group-*` bindings and a flat
|
|
63
|
+
* `items` API in place of Ark's anatomy.
|
|
64
|
+
*
|
|
65
|
+
* ```tsx
|
|
66
|
+
* <SegmentGroup
|
|
67
|
+
* label="Period"
|
|
68
|
+
* items={[
|
|
69
|
+
* { value: 'today', label: 'Today' },
|
|
70
|
+
* { value: 'week', label: 'Week' },
|
|
71
|
+
* { value: 'month', label: 'Month' },
|
|
72
|
+
* ]}
|
|
73
|
+
* value={period}
|
|
74
|
+
* onValueChange={setPeriod}
|
|
75
|
+
* />
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* Reach for it when the choices are few, short and all worth seeing at once:
|
|
79
|
+
* a period, a size, a view. More than five, or labels that need a sentence,
|
|
80
|
+
* want a `Select`. Panels that change with the choice are `Tabs`; a segment
|
|
81
|
+
* group changes a value, not what is on the page.
|
|
82
|
+
*/
|
|
83
|
+
export declare function SegmentGroup({ label, items, value, defaultValue, onValueChange, size, disabled, name, className, 'aria-label': ariaLabel, }: SegmentGroupProps): import("react/jsx-runtime").JSX.Element;
|
|
84
|
+
export {};
|
|
85
|
+
//# sourceMappingURL=segment-group.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"segment-group.d.ts","sourceRoot":"","sources":["../../src/segment-group/segment-group.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAU,MAAM,OAAO,CAAC;AAC/C,OAAO,qBAAqB,CAAC;AAG7B,MAAM,MAAM,gBAAgB,GAAG,IAAI,GAAG,IAAI,CAAC;AAE3C,MAAM,WAAW,gBAAgB;IAC/B,0EAA0E;IAC1E,KAAK,EAAE,MAAM,CAAC;IACd,kGAAkG;IAClG,KAAK,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;GAIG;AACH,KAAK,gBAAgB,GACjB;IACE,oEAAoE;IACpE,KAAK,EAAE,SAAS,CAAC;IACjB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GACD;IACE,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,2FAA2F;IAC3F,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEN,MAAM,MAAM,iBAAiB,GAAG,gBAAgB,GAAG;IACjD,qDAAqD;IACrD,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,uCAAuC;IACvC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,4EAA4E;IAC5E,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB,yEAAyE;IACzE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,0EAA0E;IAC1E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,KAAK,EACL,KAAK,EACL,YAAY,EACZ,aAAa,EACb,IAAW,EACX,QAAQ,EACR,IAAI,EACJ,SAAS,EACT,YAAY,EAAE,SAAS,GACxB,EAAE,iBAAiB,2CAgEnB"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { SegmentGroup as ArkSegmentGroup } from '@ark-ui/react/segment-group';
|
|
3
|
+
import { useRef } from 'react';
|
|
4
|
+
import './segment-group.css';
|
|
5
|
+
import { cx } from '../cx';
|
|
6
|
+
/**
|
|
7
|
+
* One choice among a few, shown as a row of segments, built on Ark UI's
|
|
8
|
+
* SegmentGroup: a radio group whose radios are drawn as one control.
|
|
9
|
+
*
|
|
10
|
+
* Ark owns the behaviour: hidden radio inputs carry the state, the arrow keys
|
|
11
|
+
* move the choice, and the whole segment is its radio's label. This wrapper
|
|
12
|
+
* contributes `ds-` classes, the `--ds-segment-group-*` bindings and a flat
|
|
13
|
+
* `items` API in place of Ark's anatomy.
|
|
14
|
+
*
|
|
15
|
+
* ```tsx
|
|
16
|
+
* <SegmentGroup
|
|
17
|
+
* label="Period"
|
|
18
|
+
* items={[
|
|
19
|
+
* { value: 'today', label: 'Today' },
|
|
20
|
+
* { value: 'week', label: 'Week' },
|
|
21
|
+
* { value: 'month', label: 'Month' },
|
|
22
|
+
* ]}
|
|
23
|
+
* value={period}
|
|
24
|
+
* onValueChange={setPeriod}
|
|
25
|
+
* />
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Reach for it when the choices are few, short and all worth seeing at once:
|
|
29
|
+
* a period, a size, a view. More than five, or labels that need a sentence,
|
|
30
|
+
* want a `Select`. Panels that change with the choice are `Tabs`; a segment
|
|
31
|
+
* group changes a value, not what is on the page.
|
|
32
|
+
*/
|
|
33
|
+
export function SegmentGroup({ label, items, value, defaultValue, onValueChange, size = 'md', disabled, name, className, 'aria-label': ariaLabel, }) {
|
|
34
|
+
const rootRef = useRef(null);
|
|
35
|
+
/*
|
|
36
|
+
* Zag reports `null` only when the value is cleared through its API, which
|
|
37
|
+
* this wrapper never calls; a user can only move the choice to a segment.
|
|
38
|
+
*
|
|
39
|
+
* Ark renders the hidden radios uncontrolled and syncs them only when its
|
|
40
|
+
* own state changes, so a controlled parent that declines a choice would
|
|
41
|
+
* leave the native radio checked while the segment shows the old one.
|
|
42
|
+
* Restoring the parent's value after Ark has read the radios keeps the two
|
|
43
|
+
* agreeing, as Checkbox and Switch do.
|
|
44
|
+
*/
|
|
45
|
+
const handleValueChange = (details) => {
|
|
46
|
+
if (details.value !== null)
|
|
47
|
+
onValueChange?.(details.value);
|
|
48
|
+
if (value === undefined || !rootRef.current)
|
|
49
|
+
return;
|
|
50
|
+
for (const input of rootRef.current.querySelectorAll('input[type="radio"]')) {
|
|
51
|
+
input.checked = input.value === value;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/*
|
|
55
|
+
* Zag always names the root by its label part's id, which would outrank an
|
|
56
|
+
* `aria-label`. With both given, the visible label is plain text instead,
|
|
57
|
+
* so that id resolves to nothing and the `aria-label` is what is announced.
|
|
58
|
+
*/
|
|
59
|
+
const visibleLabel = label &&
|
|
60
|
+
(ariaLabel ? (_jsx("span", { className: "ds-segment-group__label", children: label })) : (_jsx(ArkSegmentGroup.Label, { className: "ds-segment-group__label", children: label })));
|
|
61
|
+
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
|
+
return (_jsxs(ArkSegmentGroup.Root, { ref: rootRef, className: cx('ds-segment-group', `ds-segment-group--${size}`, className), value: value, defaultValue: defaultValue, onValueChange: handleValueChange, disabled: disabled, name: name, orientation: "horizontal", "aria-label": ariaLabel, children: [visibleLabel, _jsx("div", { className: "ds-segment-group__track", children: items.map(renderItem) })] }));
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=segment-group.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"segment-group.js","sourceRoot":"","sources":["../../src/segment-group/segment-group.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,IAAI,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,EAAkB,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,qBAAqB,CAAC;AAC7B,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AA6D3B;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,YAAY,CAAC,EAC3B,KAAK,EACL,KAAK,EACL,KAAK,EACL,Y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IAAI,IACnB,GAAG,EAAE,OAAO,EACZ,SAAS,EAAE,EAAE,CAAC,kBAAkB,EAAE,qBAAqB,IAAI,EAAE,EAAE,SAAS,CAAC,EACzE,KAAK,EAAE,KAAK,EACZ,YAAY,EAAE,YAAY,EAC1B,aAAa,EAAE,iBAAiB,EAChC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,WAAW,EAAC,YAAY,gBACZ,SAAS,aAEpB,YAAY,EACb,cAAK,SAAS,EAAC,yBAAyB,YAAE,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,GAAO,IACjD,CACxB,CAAC;AACJ,CAAC"}
|
package/dist/switch/switch.d.ts
CHANGED
|
@@ -11,7 +11,11 @@ export type SwitchLabelPlacement = 'start' | 'end';
|
|
|
11
11
|
type SwitchName = {
|
|
12
12
|
/** Visible label. The whole label is the click target. */
|
|
13
13
|
label: ReactNode;
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* A different accessible name when the visible label alone would not
|
|
16
|
+
* say what the control is. Keep the visible words in it, so a voice
|
|
17
|
+
* user can still say what they see.
|
|
18
|
+
*/
|
|
15
19
|
'aria-label'?: string;
|
|
16
20
|
} | {
|
|
17
21
|
label?: undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switch.d.ts","sourceRoot":"","sources":["../../src/switch/switch.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"switch.d.ts","sourceRoot":"","sources":["../../src/switch/switch.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAiB,MAAM,OAAO,CAAC;AACtD,OAAO,cAAc,CAAC;AAGtB,MAAM,MAAM,UAAU,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE5C,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,KAAK,CAAC;AAEnD;;;;;GAKG;AACH,KAAK,UAAU,GACX;IACE,0DA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dist/switch/switch.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Switch as ArkSwitch } from '@ark-ui/react/switch';
|
|
3
|
-
import { useRef } from 'react';
|
|
3
|
+
import { useId, useRef } from 'react';
|
|
4
4
|
import './switch.css';
|
|
5
5
|
import { cx } from '../cx';
|
|
6
6
|
/**
|
|
@@ -22,8 +22,18 @@ import { cx } from '../cx';
|
|
|
22
22
|
* or a segmented control.
|
|
23
23
|
*/
|
|
24
24
|
export function Switch({ label, labelPlacement = 'end', checked, defaultChecked, onCheckedChange, size = 'md', disabled, invalid, readOnly, required, name, value, className, 'aria-label': ariaLabel, 'aria-describedby': ariaDescribedBy, }) {
|
|
25
|
-
|
|
25
|
+
/*
|
|
26
|
+
* Zag always names the hidden input by its label part's id, which would
|
|
27
|
+
* outrank an `aria-label`. With both given, the visible label is plain
|
|
28
|
+
* text instead, so that id resolves to nothing and the `aria-label` wins;
|
|
29
|
+
* the root is still the `<label>`, so the text stays the click target.
|
|
30
|
+
*/
|
|
31
|
+
const labelNode = label ? (ariaLabel ? (_jsx("span", { className: "ds-switch__label", children: label })) : (_jsx(ArkSwitch.Label, { className: "ds-switch__label", children: label }))) : null;
|
|
26
32
|
const inputRef = useRef(null);
|
|
33
|
+
// Own ids, as Checkbox: a switch names itself, and two switches in one
|
|
34
|
+
// Field must not share the field's control id.
|
|
35
|
+
const ownId = useId();
|
|
36
|
+
const ids = { hiddenInput: `${ownId}:input`, label: `${ownId}:label` };
|
|
27
37
|
/*
|
|
28
38
|
* Ark renders the hidden input uncontrolled (`defaultChecked`) and syncs it
|
|
29
39
|
* only when its own state changes. A controlled parent that declines a
|
|
@@ -37,6 +47,6 @@ export function Switch({ label, labelPlacement = 'end', checked, defaultChecked,
|
|
|
37
47
|
if (checked !== undefined && inputRef.current)
|
|
38
48
|
inputRef.current.checked = checked;
|
|
39
49
|
};
|
|
40
|
-
return (_jsxs(ArkSwitch.Root, { className: cx('ds-switch', `ds-switch--${size}`, className), checked: checked, defaultChecked: defaultChecked, onCheckedChange: handleCheckedChange, disabled: disabled, invalid: invalid, readOnly: readOnly, required: required, name: name, value: value, children: [labelPlacement === 'start' && labelNode, _jsx(ArkSwitch.Control, { className: "ds-switch__control", children: _jsx(ArkSwitch.Thumb, { className: "ds-switch__thumb" }) }), labelPlacement === 'end' && labelNode, _jsx(ArkSwitch.HiddenInput, { ref: inputRef, role: "switch", "aria-label": ariaLabel, "aria-describedby": ariaDescribedBy, "aria-readonly": readOnly || undefined })] }));
|
|
50
|
+
return (_jsxs(ArkSwitch.Root, { ids: ids, className: cx('ds-switch', `ds-switch--${size}`, className), checked: checked, defaultChecked: defaultChecked, onCheckedChange: handleCheckedChange, disabled: disabled, invalid: invalid, readOnly: readOnly, required: required, name: name, value: value, children: [labelPlacement === 'start' && labelNode, _jsx(ArkSwitch.Control, { className: "ds-switch__control", children: _jsx(ArkSwitch.Thumb, { className: "ds-switch__thumb" }) }), labelPlacement === 'end' && labelNode, _jsx(ArkSwitch.HiddenInput, { ref: inputRef, role: "switch", "aria-label": ariaLabel, "aria-describedby": ariaDescribedBy, "aria-readonly": readOnly || undefined })] }));
|
|
41
51
|
}
|
|
42
52
|
//# sourceMappingURL=switch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switch.js","sourceRoot":"","sources":["../../src/switch/switch.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAkB,MAAM,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"switch.js","sourceRoot":"","sources":["../../src/switch/switch.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAkB,KAAK,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACtD,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W,EAAE,cAAc,IAAI,EAAE,EAAE,SAAS,CAAC,EAC3D,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,aAEX,cAAc,KAAK,OAAO,IAAI,SAAS,EACxC,KAAC,SAAS,CAAC,OAAO,IAAC,SAAS,EAAC,oBAAoB,YAC/C,KAAC,SAAS,CAAC,KAAK,IAAC,SAAS,EAAC,kBAAkB,GAAG,GAC9B,EACnB,cAAc,KAAK,KAAK,IAAI,SAAS,EACtC,KAAC,SAAS,CAAC,WAAW,IACpB,GAAG,EAAE,QAAQ,EACb,IAAI,EAAC,QAAQ,gBACD,SAAS,sBACH,eAAe,mBAClB,QAAQ,IAAI,SAAS,GACpC,IACa,CAClB,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manakind/ui-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -76,6 +76,10 @@
|
|
|
76
76
|
"types": "./dist/progress/index.d.ts",
|
|
77
77
|
"import": "./dist/progress/index.js"
|
|
78
78
|
},
|
|
79
|
+
"./segment-group": {
|
|
80
|
+
"types": "./dist/segment-group/index.d.ts",
|
|
81
|
+
"import": "./dist/segment-group/index.js"
|
|
82
|
+
},
|
|
79
83
|
"./select": {
|
|
80
84
|
"types": "./dist/select/index.d.ts",
|
|
81
85
|
"import": "./dist/select/index.js"
|
|
@@ -140,6 +144,10 @@
|
|
|
140
144
|
"types": "./dist/progress/progress.css.d.ts",
|
|
141
145
|
"default": "./dist/progress/progress.css"
|
|
142
146
|
},
|
|
147
|
+
"./css/segment-group": {
|
|
148
|
+
"types": "./dist/segment-group/segment-group.css.d.ts",
|
|
149
|
+
"default": "./dist/segment-group/segment-group.css"
|
|
150
|
+
},
|
|
143
151
|
"./css/select": {
|
|
144
152
|
"types": "./dist/select/select.css.d.ts",
|
|
145
153
|
"default": "./dist/select/select.css"
|
|
@@ -171,7 +179,7 @@
|
|
|
171
179
|
},
|
|
172
180
|
"devDependencies": {
|
|
173
181
|
"@manakind/ds-config": "*",
|
|
174
|
-
"@manakind/manuia-tokens": "0.
|
|
182
|
+
"@manakind/manuia-tokens": "0.12.0",
|
|
175
183
|
"@testing-library/jest-dom": "^6.9.1",
|
|
176
184
|
"@testing-library/react": "^16.3.2",
|
|
177
185
|
"@testing-library/user-event": "^14.6.1",
|