@charcuterie/ui 4.27.1 → 4.27.3
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/SegmentedControl/SegmentedControl.d.ts +4 -2
- package/dist/SegmentedControl/SegmentedControl.d.ts.map +1 -1
- package/dist/SegmentedControl/SegmentedControl.js.map +1 -1
- package/dist/SegmentedControl/SegmentedOption.d.ts.map +1 -1
- package/dist/SegmentedControl/SegmentedOption.js +10 -6
- package/dist/SegmentedControl/SegmentedOption.js.map +1 -1
- package/package.json +2 -2
- package/src/SegmentedControl/SegmentedControl.stories.tsx +49 -0
- package/src/SegmentedControl/SegmentedControl.test.tsx +66 -0
- package/src/SegmentedControl/SegmentedControl.tsx +4 -2
- package/src/SegmentedControl/SegmentedOption.tsx +9 -5
|
@@ -15,8 +15,10 @@ export type SegmentedControlProps = {
|
|
|
15
15
|
className?: string;
|
|
16
16
|
/**
|
|
17
17
|
* Fill the available inline space, with every option claiming an
|
|
18
|
-
* equal share
|
|
19
|
-
*
|
|
18
|
+
* equal share where label minimum widths allow. Options wrap
|
|
19
|
+
* onto another row before squeezing rich labels below their
|
|
20
|
+
* minimum content width. A board's Narrow View selector needs
|
|
21
|
+
* this: its options name the only lane on screen, so a content-width strip
|
|
20
22
|
* leaves the rest of the board looking disconnected.
|
|
21
23
|
*
|
|
22
24
|
* The default stays content-width. Most segmented controls choose
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SegmentedControl.d.ts","sourceRoot":"","sources":["../../src/SegmentedControl/SegmentedControl.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAMtC,MAAM,MAAM,aAAa,GAAG;IAC1B;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,KAAK,EAAE,SAAS,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB
|
|
1
|
+
{"version":3,"file":"SegmentedControl.d.ts","sourceRoot":"","sources":["../../src/SegmentedControl/SegmentedControl.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAMtC,MAAM,MAAM,aAAa,GAAG;IAC1B;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,KAAK,EAAE,SAAS,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;;;;;;;;OAWG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,KAAK,EAAE,SAAS,aAAa,EAAE,CAAA;IAC/B,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;IACjD,0DAA0D;IAC1D,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,IAAI,CAAC,EAAE,WAAW,CAAA;CACnB,CAAA;AAQD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,gBAAgB,GAAI,0EAQ9B,qBAAqB,KAAG,SA0I1B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SegmentedControl.js","sourceRoot":"","sources":["../../src/SegmentedControl/SegmentedControl.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,eAAe,GAChB,MAAM,oBAAoB,CAAA;AAG3B,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM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,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;gBAC5C,CAAC;qBAAM,CAAC;oBACN,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;gBACtC,CAAC;YACH,CAAC,IAhBI,IAAI,CAAC,KAAK,CAiBf,CACH,CAAC,GACE,CACP,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SegmentedOption.d.ts","sourceRoot":"","sources":["../../src/SegmentedControl/SegmentedOption.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAMtC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAE3D,MAAM,MAAM,oBAAoB,GAAG;IACjC,SAAS,EAAE,OAAO,CAAA;IAClB,WAAW,EAAE,OAAO,CAAA;IACpB,IAAI,EAAE,aAAa,CAAA;IACnB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACjC,kEAAkE;IAClE,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,IAAI,CAAA;IAC5C,0DAA0D;IAC1D,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,IAAI,CAAA;IAChD,IAAI,EAAE,WAAW,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,CACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,iBAAiB,GAAG,IAAI,KAC9B,IAAI,CAAA;CACV,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,GAAI,6GAU7B,oBAAoB,KAAG,
|
|
1
|
+
{"version":3,"file":"SegmentedOption.d.ts","sourceRoot":"","sources":["../../src/SegmentedControl/SegmentedOption.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAMtC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAE3D,MAAM,MAAM,oBAAoB,GAAG;IACjC,SAAS,EAAE,OAAO,CAAA;IAClB,WAAW,EAAE,OAAO,CAAA;IACpB,IAAI,EAAE,aAAa,CAAA;IACnB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACjC,kEAAkE;IAClE,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,IAAI,CAAA;IAC5C,0DAA0D;IAC1D,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,IAAI,CAAA;IAChD,IAAI,EAAE,WAAW,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,CACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,iBAAiB,GAAG,IAAI,KAC9B,IAAI,CAAA;CACV,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,GAAI,6GAU7B,oBAAoB,KAAG,SAyDzB,CAAA"}
|
|
@@ -24,11 +24,11 @@ export const SegmentedOption = ({ isChecked, isFullWidth, item, onChoose, regist
|
|
|
24
24
|
return registerFocus(value);
|
|
25
25
|
}, [isDisabled, registerFocus, value]);
|
|
26
26
|
return (_jsx("button", { "aria-checked": isChecked, className: toClassName("inline-flex cursor-pointer items-center justify-center rounded-sm border border-transparent font-medium tabular-nums transition-colors duration-(--duration-fast) ease-standard",
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
isFullWidth && "min-w-
|
|
27
|
+
// Keep the usual seven-rem wrapping basis, but let a label's
|
|
28
|
+
// minimum content width raise the floor. Rich nowrap labels
|
|
29
|
+
// then move to another row instead of spilling out of a
|
|
30
|
+
// button whose fixed minimum was smaller than its content.
|
|
31
|
+
isFullWidth && "min-w-min flex-1 basis-28", CONTROL_SIZE_CLASS[size],
|
|
32
32
|
// Two entries rather than one interpolated string:
|
|
33
33
|
// `tailwindCandidates.test.ts` rejects a template literal in
|
|
34
34
|
// a className outright, because Tailwind's scanner cannot
|
|
@@ -40,6 +40,10 @@ export const SegmentedOption = ({ isChecked, isFullWidth, item, onChoose, regist
|
|
|
40
40
|
onChoose(value);
|
|
41
41
|
}, ref: (element) => {
|
|
42
42
|
trackElement(value, element);
|
|
43
|
-
},
|
|
43
|
+
},
|
|
44
|
+
// Full-width targets are already sized by the row. Inline
|
|
45
|
+
// padding must not inflate the minimum beyond the label
|
|
46
|
+
// itself; centering still leaves equal space on both sides.
|
|
47
|
+
style: isFullWidth ? { paddingInline: 0 } : undefined, role: "radio", tabIndex: tabIndex, type: "button", children: label }));
|
|
44
48
|
};
|
|
45
49
|
//# sourceMappingURL=SegmentedOption.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SegmentedOption.js","sourceRoot":"","sources":["../../src/SegmentedControl/SegmentedOption.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAoB/C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAC9B,SAAS,EACT,WAAW,EACX,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,iBAAiB,EACjB,IAAI,EACJ,QAAQ,EACR,YAAY,GACS,EAAa,EAAE;IACpC,MAAM,EAAE,UAAU,GAAG,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI,CAAA;IAEjD,SAAS,CACP,GAAG,EAA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,CAAC,CAAA;IAEtC,OAAO,CAEL,iCACgB,SAAS,EACvB,SAAS,EAAE,WAAW,CACpB,iLAAiL;QACjL,6DAA6D;QAC7D,4DAA4D;QAC5D,wDAAwD;QACxD,2DAA2D;QAC3D,WAAW,IAAI,2BAA2B,EAC1C,kBAAkB,CAAC,IAAI,CAAC;QACxB,mDAAmD;QACnD,6DAA6D;QAC7D,0DAA0D;QAC1D,2CAA2C;QAC3C,SAAS;YACP,CAAC,CAAC,oDAAoD;YACtD,CAAC,CAAC,mFAAmF,EACvF,UAAU;YACR,2FAA2F,EAC7F,gBAAgB,CACjB,EACD,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,GAAG,EAAE;YACZ,QAAQ,CAAC,KAAK,CAAC,CAAA;QACjB,CAAC,EACD,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE;YACf,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QAC9B,CAAC;QACD,0DAA0D;QAC1D,wDAAwD;QACxD,4DAA4D;QAC5D,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,EACrD,IAAI,EAAC,OAAO,EACZ,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAC,QAAQ,YAEZ,KAAK,GACC,CACV,CAAA;AACH,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@charcuterie/ui",
|
|
3
|
-
"version": "4.27.
|
|
3
|
+
"version": "4.27.3",
|
|
4
4
|
"description": "The Charcuterie components. Tokens for look, @charcuterie/logic for state, ARIA that agents can actually drive.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"src"
|
|
58
58
|
],
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@charcuterie/logic": "2.
|
|
60
|
+
"@charcuterie/logic": "2.12.0",
|
|
61
61
|
"@charcuterie/tokens": "1.10.2",
|
|
62
62
|
"@floating-ui/react": "^0.27.20",
|
|
63
63
|
"@tanstack/react-virtual": "^3.13.12",
|
|
@@ -2,6 +2,7 @@ import { playgroundParameters } from "@charcuterie/storybook-config/story-parame
|
|
|
2
2
|
import type { Meta, StoryObj } from "@storybook/react"
|
|
3
3
|
|
|
4
4
|
import { controlSizeArgType } from "../argTypes.storyHelpers.ts"
|
|
5
|
+
import { Badge } from "../Badge/Badge.tsx"
|
|
5
6
|
import {
|
|
6
7
|
ContainerBoard,
|
|
7
8
|
StoryCell,
|
|
@@ -241,3 +242,51 @@ export const RichLabels: Story = {
|
|
|
241
242
|
],
|
|
242
243
|
},
|
|
243
244
|
}
|
|
245
|
+
|
|
246
|
+
export const NarrowRichLabels: Story = {
|
|
247
|
+
args: RichLabels.args,
|
|
248
|
+
render: (controlProps) => (
|
|
249
|
+
<ContainerBoard>
|
|
250
|
+
{(width) => (
|
|
251
|
+
<SegmentedControl
|
|
252
|
+
{...controlProps}
|
|
253
|
+
label={`Message type at ${width}`}
|
|
254
|
+
/>
|
|
255
|
+
)}
|
|
256
|
+
</ContainerBoard>
|
|
257
|
+
),
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export const FragmentLabels: Story = {
|
|
261
|
+
args: {
|
|
262
|
+
isFullWidth: true,
|
|
263
|
+
label: "Message format",
|
|
264
|
+
items: [
|
|
265
|
+
{
|
|
266
|
+
value: "text",
|
|
267
|
+
label: (
|
|
268
|
+
<>
|
|
269
|
+
<span
|
|
270
|
+
aria-hidden="true"
|
|
271
|
+
className="size-4 shrink-0 rounded-sm bg-current"
|
|
272
|
+
/>
|
|
273
|
+
<span>Type a message</span>
|
|
274
|
+
</>
|
|
275
|
+
),
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
value: "voice",
|
|
279
|
+
label: (
|
|
280
|
+
<>
|
|
281
|
+
<span
|
|
282
|
+
aria-hidden="true"
|
|
283
|
+
className="size-4 shrink-0 rounded-full bg-current"
|
|
284
|
+
/>
|
|
285
|
+
<span>Your voice</span>
|
|
286
|
+
<Badge size="sm">Later</Badge>
|
|
287
|
+
</>
|
|
288
|
+
),
|
|
289
|
+
},
|
|
290
|
+
],
|
|
291
|
+
},
|
|
292
|
+
}
|
|
@@ -13,6 +13,8 @@ const {
|
|
|
13
13
|
FullWidth,
|
|
14
14
|
Interactive,
|
|
15
15
|
RichLabels,
|
|
16
|
+
NarrowRichLabels,
|
|
17
|
+
FragmentLabels,
|
|
16
18
|
} = composeStories(stories)
|
|
17
19
|
|
|
18
20
|
test("rich label boxes are centered inside both segmented options", async () => {
|
|
@@ -45,6 +47,70 @@ test("rich label boxes are centered inside both segmented options", async () =>
|
|
|
45
47
|
}
|
|
46
48
|
})
|
|
47
49
|
|
|
50
|
+
test("rich labels stay inside their options in constrained containers", async () => {
|
|
51
|
+
const { canvas } = await mountStory(NarrowRichLabels)
|
|
52
|
+
for (const group of canvas.getAllByRole("radiogroup", {
|
|
53
|
+
name: /Message type at/,
|
|
54
|
+
})) {
|
|
55
|
+
const groupBox = group.getBoundingClientRect()
|
|
56
|
+
for (const option of getOptions(group)) {
|
|
57
|
+
const label = option.firstElementChild
|
|
58
|
+
if (!label)
|
|
59
|
+
throw new Error("The rich label is missing")
|
|
60
|
+
const optionBox = option.getBoundingClientRect()
|
|
61
|
+
const labelBox = label.getBoundingClientRect()
|
|
62
|
+
expect(labelBox.left).toBeGreaterThanOrEqual(
|
|
63
|
+
optionBox.left - 0.5,
|
|
64
|
+
)
|
|
65
|
+
expect(labelBox.right).toBeLessThanOrEqual(
|
|
66
|
+
optionBox.right + 0.5,
|
|
67
|
+
)
|
|
68
|
+
expect(optionBox.left).toBeGreaterThanOrEqual(
|
|
69
|
+
groupBox.left - 0.5,
|
|
70
|
+
)
|
|
71
|
+
expect(optionBox.right).toBeLessThanOrEqual(
|
|
72
|
+
groupBox.right + 0.5,
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
test("fragment label children align and have readable accessible names", async () => {
|
|
79
|
+
const { canvas } = await mountStory(FragmentLabels)
|
|
80
|
+
const group = expectAgentDrivable(canvas, {
|
|
81
|
+
name: "Message format",
|
|
82
|
+
role: "radiogroup",
|
|
83
|
+
})
|
|
84
|
+
expectAgentDrivable(canvas, {
|
|
85
|
+
name: "Type a message",
|
|
86
|
+
role: "radio",
|
|
87
|
+
})
|
|
88
|
+
expectAgentDrivable(canvas, {
|
|
89
|
+
name: "Your voice Later",
|
|
90
|
+
role: "radio",
|
|
91
|
+
})
|
|
92
|
+
for (const option of getOptions(group)) {
|
|
93
|
+
const optionBox = option.getBoundingClientRect()
|
|
94
|
+
let previousRight = optionBox.left
|
|
95
|
+
for (const child of option.children) {
|
|
96
|
+
const box = child.getBoundingClientRect()
|
|
97
|
+
expect(
|
|
98
|
+
Math.abs(
|
|
99
|
+
optionBox.y +
|
|
100
|
+
optionBox.height / 2 -
|
|
101
|
+
box.y -
|
|
102
|
+
box.height / 2,
|
|
103
|
+
),
|
|
104
|
+
).toBeLessThan(0.5)
|
|
105
|
+
expect(box.left).toBeGreaterThanOrEqual(previousRight)
|
|
106
|
+
expect(box.right).toBeLessThanOrEqual(
|
|
107
|
+
optionBox.right + 0.5,
|
|
108
|
+
)
|
|
109
|
+
previousRight = box.right
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
|
|
48
114
|
/**
|
|
49
115
|
* `querySelectorAll` rather than `getAllByRole("radio")`, and not
|
|
50
116
|
* for typing convenience: a board renders several groups, and an
|
|
@@ -26,8 +26,10 @@ export type SegmentedControlProps = {
|
|
|
26
26
|
className?: string
|
|
27
27
|
/**
|
|
28
28
|
* Fill the available inline space, with every option claiming an
|
|
29
|
-
* equal share
|
|
30
|
-
*
|
|
29
|
+
* equal share where label minimum widths allow. Options wrap
|
|
30
|
+
* onto another row before squeezing rich labels below their
|
|
31
|
+
* minimum content width. A board's Narrow View selector needs
|
|
32
|
+
* this: its options name the only lane on screen, so a content-width strip
|
|
31
33
|
* leaves the rest of the board looking disconnected.
|
|
32
34
|
*
|
|
33
35
|
* The default stays content-width. Most segmented controls choose
|
|
@@ -67,11 +67,11 @@ export const SegmentedOption = ({
|
|
|
67
67
|
aria-checked={isChecked}
|
|
68
68
|
className={toClassName(
|
|
69
69
|
"inline-flex cursor-pointer items-center justify-center rounded-sm border border-transparent font-medium tabular-nums transition-colors duration-(--duration-fast) ease-standard",
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
isFullWidth && "min-w-
|
|
70
|
+
// Keep the usual seven-rem wrapping basis, but let a label's
|
|
71
|
+
// minimum content width raise the floor. Rich nowrap labels
|
|
72
|
+
// then move to another row instead of spilling out of a
|
|
73
|
+
// button whose fixed minimum was smaller than its content.
|
|
74
|
+
isFullWidth && "min-w-min flex-1 basis-28",
|
|
75
75
|
CONTROL_SIZE_CLASS[size],
|
|
76
76
|
// Two entries rather than one interpolated string:
|
|
77
77
|
// `tailwindCandidates.test.ts` rejects a template literal in
|
|
@@ -91,6 +91,10 @@ export const SegmentedOption = ({
|
|
|
91
91
|
ref={(element) => {
|
|
92
92
|
trackElement(value, element)
|
|
93
93
|
}}
|
|
94
|
+
// Full-width targets are already sized by the row. Inline
|
|
95
|
+
// padding must not inflate the minimum beyond the label
|
|
96
|
+
// itself; centering still leaves equal space on both sides.
|
|
97
|
+
style={isFullWidth ? { paddingInline: 0 } : undefined}
|
|
94
98
|
role="radio"
|
|
95
99
|
tabIndex={tabIndex}
|
|
96
100
|
type="button"
|