@42-central/ui-react 0.25.0 → 0.26.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/{chunk-LHUWOA2U.js → chunk-276RL7FX.js} +5 -5
- package/dist/{chunk-LHUWOA2U.js.map → chunk-276RL7FX.js.map} +1 -1
- package/dist/{chunk-6UIQJJNJ.js → chunk-2NTCQIRP.js} +4 -4
- package/dist/{chunk-6UIQJJNJ.js.map → chunk-2NTCQIRP.js.map} +1 -1
- package/dist/{chunk-T44RW5DW.js → chunk-2TZU4LSX.js} +4 -4
- package/dist/{chunk-T44RW5DW.js.map → chunk-2TZU4LSX.js.map} +1 -1
- package/dist/{chunk-QZ4N5LYG.js → chunk-7B44J3CF.js} +3 -3
- package/dist/{chunk-QZ4N5LYG.js.map → chunk-7B44J3CF.js.map} +1 -1
- package/dist/{chunk-XUFCI262.js → chunk-7OGZT7U2.js} +12 -4
- package/dist/chunk-7OGZT7U2.js.map +1 -0
- package/dist/{chunk-N5M4PDBK.js → chunk-DMI4KS32.js} +3 -3
- package/dist/{chunk-N5M4PDBK.js.map → chunk-DMI4KS32.js.map} +1 -1
- package/dist/{chunk-UDCCOUWR.js → chunk-DSZF2TW6.js} +5 -5
- package/dist/{chunk-UDCCOUWR.js.map → chunk-DSZF2TW6.js.map} +1 -1
- package/dist/{chunk-N66NC6QK.js → chunk-E3XLWMEB.js} +3 -3
- package/dist/{chunk-N66NC6QK.js.map → chunk-E3XLWMEB.js.map} +1 -1
- package/dist/{chunk-HRNWWL3Y.js → chunk-J2NW7JID.js} +61 -29
- package/dist/chunk-J2NW7JID.js.map +1 -0
- package/dist/{chunk-FZSLSUSX.js → chunk-JDPVD2YE.js} +3 -3
- package/dist/{chunk-FZSLSUSX.js.map → chunk-JDPVD2YE.js.map} +1 -1
- package/dist/{chunk-6II2DVYR.js → chunk-JFB6O7IY.js} +4 -4
- package/dist/{chunk-6II2DVYR.js.map → chunk-JFB6O7IY.js.map} +1 -1
- package/dist/chunk-LJVIZNPE.js +9 -0
- package/dist/chunk-LJVIZNPE.js.map +1 -0
- package/dist/{chunk-HQPU73WV.js → chunk-LYGOFMXJ.js} +3 -3
- package/dist/{chunk-HQPU73WV.js.map → chunk-LYGOFMXJ.js.map} +1 -1
- package/dist/{chunk-AHKMN3YQ.js → chunk-N42EFOML.js} +3 -3
- package/dist/{chunk-AHKMN3YQ.js.map → chunk-N42EFOML.js.map} +1 -1
- package/dist/{chunk-7HZBD4YZ.js → chunk-NF2PBGD3.js} +36 -23
- package/dist/chunk-NF2PBGD3.js.map +1 -0
- package/dist/{chunk-MW42XVPD.js → chunk-PBSVX5DB.js} +15 -5
- package/dist/chunk-PBSVX5DB.js.map +1 -0
- package/dist/{chunk-PI7X5YFJ.js → chunk-PT22KEVD.js} +4 -4
- package/dist/{chunk-PI7X5YFJ.js.map → chunk-PT22KEVD.js.map} +1 -1
- package/dist/{chunk-36NWC4GV.js → chunk-QEAF57ZQ.js} +3 -3
- package/dist/{chunk-36NWC4GV.js.map → chunk-QEAF57ZQ.js.map} +1 -1
- package/dist/{chunk-SAXWCGWR.js → chunk-SOUDKESO.js} +14 -7
- package/dist/chunk-SOUDKESO.js.map +1 -0
- package/dist/{chunk-54W6VAI3.js → chunk-THGJLR5S.js} +5 -5
- package/dist/{chunk-54W6VAI3.js.map → chunk-THGJLR5S.js.map} +1 -1
- package/dist/{chunk-LMCUGYHT.js → chunk-YMVUQ2L7.js} +3 -3
- package/dist/{chunk-LMCUGYHT.js.map → chunk-YMVUQ2L7.js.map} +1 -1
- package/dist/components/ambient-background/index.js +9 -23
- package/dist/components/ambient-background/index.js.map +1 -1
- package/dist/components/ambient-background/starfield.d.ts.map +1 -1
- package/dist/components/app-shell/app-shell.d.ts +55 -10
- package/dist/components/app-shell/app-shell.d.ts.map +1 -1
- package/dist/components/app-shell/index.d.ts +1 -1
- package/dist/components/app-shell/index.d.ts.map +1 -1
- package/dist/components/app-shell/index.js +297 -36
- package/dist/components/app-shell/index.js.map +1 -1
- package/dist/components/autocomplete/index.js +3 -3
- package/dist/components/avatar/avatar.d.ts +1 -1
- package/dist/components/avatar/avatar.d.ts.map +1 -1
- package/dist/components/avatar/index.js +10 -1
- package/dist/components/avatar/index.js.map +1 -1
- package/dist/components/button-group/button-group.d.ts +10 -2
- package/dist/components/button-group/button-group.d.ts.map +1 -1
- package/dist/components/button-group/index.js +1 -1
- package/dist/components/button-multi-select/index.js +2 -2
- package/dist/components/button-select/button-select-control.d.ts +4 -1
- package/dist/components/button-select/button-select-control.d.ts.map +1 -1
- package/dist/components/button-select/button-select.d.ts +4 -1
- package/dist/components/button-select/button-select.d.ts.map +1 -1
- package/dist/components/button-select/index.js +2 -2
- package/dist/components/camera/index.js +5 -5
- package/dist/components/code-block/chrome.js +3 -3
- package/dist/components/code-block/index.js +4 -4
- package/dist/components/combobox/index.js +3 -3
- package/dist/components/combobox-list/index.js +5 -5
- package/dist/components/data-table/index.js +13 -13
- package/dist/components/date-picker/index.js +7 -7
- package/dist/components/drawer/index.js +2 -2
- package/dist/components/geodesic/a11y.d.ts +3 -3
- package/dist/components/geodesic/a11y.d.ts.map +1 -1
- package/dist/components/geodesic/badge-frame.d.ts +13 -1
- package/dist/components/geodesic/badge-frame.d.ts.map +1 -1
- package/dist/components/geodesic/exam-badge.d.ts +4 -1
- package/dist/components/geodesic/exam-badge.d.ts.map +1 -1
- package/dist/components/geodesic/geometry.d.ts +14 -9
- package/dist/components/geodesic/geometry.d.ts.map +1 -1
- package/dist/components/geodesic/index.js +62 -23
- package/dist/components/geodesic/index.js.map +1 -1
- package/dist/components/geodesic/status.d.ts +8 -6
- package/dist/components/geodesic/status.d.ts.map +1 -1
- package/dist/components/geodesic/styles.css +15 -2
- package/dist/components/hover-card/index.js +2 -2
- package/dist/components/indicator/index.js +23 -8
- package/dist/components/indicator/index.js.map +1 -1
- package/dist/components/indicator/indicator.d.ts +15 -6
- package/dist/components/indicator/indicator.d.ts.map +1 -1
- package/dist/components/lightbox/index.js +2 -2
- package/dist/components/menu/index.js +3 -3
- package/dist/components/modal/index.js +2 -2
- package/dist/components/multi-combobox-list/index.js +5 -5
- package/dist/components/multi-select/index.js +3 -3
- package/dist/components/nav-link/index.js +5 -1
- package/dist/components/nav-link/nav-link.d.ts.map +1 -1
- package/dist/components/nav-link/tanstack.js +5 -1
- package/dist/components/nav-link/tanstack.js.map +1 -1
- package/dist/components/number-input/index.js +3 -3
- package/dist/components/overlays/index.js +3 -3
- package/dist/components/photo-capture/index.js +5 -5
- package/dist/components/popover/index.js +2 -2
- package/dist/components/schedule/index.js +3 -3
- package/dist/components/segment-group/index.js +1 -1
- package/dist/components/segment-group/segment-group.d.ts +6 -1
- package/dist/components/segment-group/segment-group.d.ts.map +1 -1
- package/dist/components/select/index.js +4 -4
- package/dist/components/spotlight/index.js +4 -4
- package/dist/components/tabs/index.js +1 -1
- package/dist/components/tabs/tabs-data.d.ts +4 -1
- package/dist/components/tabs/tabs-data.d.ts.map +1 -1
- package/dist/components/tabs/tabs.d.ts +4 -1
- package/dist/components/tabs/tabs.d.ts.map +1 -1
- package/dist/components/tags-input/index.js +2 -2
- package/dist/components/time-input/index.js +5 -5
- package/dist/components/tree-multi-select/index.js +3 -3
- package/dist/components/tree-select/index.js +3 -3
- package/dist/lib/sidebar-rail.d.ts +21 -0
- package/dist/lib/sidebar-rail.d.ts.map +1 -0
- package/dist/theme.css +7 -12
- package/package.json +1 -1
- package/src/as-child.contract.test.tsx +6 -0
- package/src/components/ambient-background/starfield.tsx +14 -41
- package/src/components/app-shell/app-shell.test.tsx +430 -5
- package/src/components/app-shell/app-shell.tsx +484 -24
- package/src/components/app-shell/index.ts +2 -0
- package/src/components/avatar/avatar.test.tsx +12 -0
- package/src/components/avatar/avatar.tsx +9 -0
- package/src/components/button-group/button-group.test.tsx +24 -0
- package/src/components/button-group/button-group.tsx +21 -4
- package/src/components/button-multi-select/button-multi-select.test.tsx +15 -0
- package/src/components/button-select/button-select-control.tsx +5 -0
- package/src/components/button-select/button-select.test.tsx +25 -0
- package/src/components/button-select/button-select.tsx +13 -2
- package/src/components/geodesic/badge-frame.tsx +67 -13
- package/src/components/geodesic/exam-badge.tsx +8 -4
- package/src/components/geodesic/geometry.ts +8 -6
- package/src/components/geodesic/status.test.ts +11 -2
- package/src/components/geodesic/status.ts +11 -7
- package/src/components/geodesic/styles.css +15 -2
- package/src/components/indicator/indicator.test.tsx +45 -0
- package/src/components/indicator/indicator.tsx +40 -13
- package/src/components/nav-link/nav-link.test.tsx +121 -1
- package/src/components/nav-link/nav-link.tsx +78 -29
- package/src/components/segment-group/segment-group.test.tsx +22 -0
- package/src/components/segment-group/segment-group.tsx +35 -19
- package/src/components/tabs/tabs-data.tsx +5 -1
- package/src/components/tabs/tabs.test.tsx +28 -0
- package/src/components/tabs/tabs.tsx +14 -4
- package/src/lib/sidebar-rail.ts +24 -0
- package/src/theme.css +7 -12
- package/src/theme.test.ts +0 -1
- package/dist/chunk-7HZBD4YZ.js.map +0 -1
- package/dist/chunk-HRNWWL3Y.js.map +0 -1
- package/dist/chunk-MW42XVPD.js.map +0 -1
- package/dist/chunk-SAXWCGWR.js.map +0 -1
- package/dist/chunk-XUFCI262.js.map +0 -1
|
@@ -70,12 +70,21 @@ const avatarVariants = cva(
|
|
|
70
70
|
// `size`/`spacing` pairing (e.g. `md` avatars in a `spacing="xs"`
|
|
71
71
|
// group) still gets a correctly-sized notch, just more or less
|
|
72
72
|
// overlap.
|
|
73
|
+
//
|
|
74
|
+
// `2xl` (88px) and `3xl` (128px) sit outside the shared `SIZES` scale
|
|
75
|
+
// in `lib/sizes.ts`, the way Text/Title/Container declare their own
|
|
76
|
+
// extra steps: they're for a person shown as the subject of a screen
|
|
77
|
+
// rather than in a list. They keep `xl`'s proportions — initials at
|
|
78
|
+
// about 0.28× the diameter, the icon at 0.5× — and their own
|
|
79
|
+
// `--avatar-r`. `Avatar.Group`'s `spacing` stays on the shared scale.
|
|
73
80
|
size: {
|
|
74
81
|
xs: "size-6 text-[10px] [&_svg]:size-3.5 [--avatar-r:12]",
|
|
75
82
|
sm: "size-8 text-xs [&_svg]:size-4 [--avatar-r:16]",
|
|
76
83
|
md: "size-10 text-sm [&_svg]:size-5 [--avatar-r:20]",
|
|
77
84
|
lg: "size-12 text-base [&_svg]:size-6 [--avatar-r:24]",
|
|
78
85
|
xl: "size-16 text-lg [&_svg]:size-8 [--avatar-r:32]",
|
|
86
|
+
"2xl": "size-22 text-2xl [&_svg]:size-11 [--avatar-r:44]",
|
|
87
|
+
"3xl": "size-32 text-4xl [&_svg]:size-16 [--avatar-r:64]",
|
|
79
88
|
},
|
|
80
89
|
// `--avatar-corner-r` also rides along with `radius`: it's the other
|
|
81
90
|
// half of `Avatar.Group`'s notch for a non-circular avatar (see
|
|
@@ -165,4 +165,28 @@ describe("ButtonGroup", () => {
|
|
|
165
165
|
expect(screen.getByTestId("two").getAttribute("data-size")).toBe("xl")
|
|
166
166
|
expect(screen.getByTestId("three").getAttribute("data-size")).toBe("md")
|
|
167
167
|
})
|
|
168
|
+
|
|
169
|
+
it("spans the container with an even share per child under `grow`", () => {
|
|
170
|
+
const group = renderGroup(
|
|
171
|
+
<ButtonGroup grow>
|
|
172
|
+
<Button>One</Button>
|
|
173
|
+
<Button>Two</Button>
|
|
174
|
+
</ButtonGroup>,
|
|
175
|
+
)
|
|
176
|
+
expect(group.className).toMatch(/(^|\s)w-full(\s|$)/)
|
|
177
|
+
expect(group.className).toContain("*:flex-1")
|
|
178
|
+
expect(group.className).not.toContain("inline-flex")
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
it("hugs its children without `grow`", () => {
|
|
182
|
+
const group = renderGroup(
|
|
183
|
+
<ButtonGroup>
|
|
184
|
+
<Button>One</Button>
|
|
185
|
+
<Button>Two</Button>
|
|
186
|
+
</ButtonGroup>,
|
|
187
|
+
)
|
|
188
|
+
expect(group.className).toContain("inline-flex")
|
|
189
|
+
expect(group.className).not.toMatch(/(^|\s)w-full(\s|$)/)
|
|
190
|
+
expect(group.className).not.toContain("*:flex-1")
|
|
191
|
+
})
|
|
168
192
|
})
|
|
@@ -42,6 +42,9 @@ import type { WithTestId } from "../../lib/test-id"
|
|
|
42
42
|
* `orientation="horizontal"` (default) flattens the inline edges — logical
|
|
43
43
|
* `rounded-s` / `rounded-e` + `-ms`, so it flips correctly under RTL — while
|
|
44
44
|
* `"vertical"` flattens the block edges.
|
|
45
|
+
*
|
|
46
|
+
* `grow` spans the container and gives every child an even share of it
|
|
47
|
+
* (`flex-1`), like a tab bar.
|
|
45
48
|
*/
|
|
46
49
|
export const buttonGroupVariants = cva(
|
|
47
50
|
[
|
|
@@ -97,6 +100,10 @@ export const buttonGroupVariants = cva(
|
|
|
97
100
|
"[&>:is([data-variant=filled],[data-variant=subtle])]:border-x-0",
|
|
98
101
|
],
|
|
99
102
|
},
|
|
103
|
+
// Span the container, with an even share per child. `flex` (not
|
|
104
|
+
// `inline-flex`) so `w-full` resolves against the parent; `cn`'s twMerge
|
|
105
|
+
// drops the base `inline-flex`.
|
|
106
|
+
grow: { true: "flex w-full *:flex-1" },
|
|
100
107
|
},
|
|
101
108
|
defaultVariants: { orientation: "horizontal" },
|
|
102
109
|
},
|
|
@@ -107,14 +114,24 @@ export type ButtonGroupOrientation = NonNullable<
|
|
|
107
114
|
>
|
|
108
115
|
|
|
109
116
|
export type ButtonGroupProps = HTMLArkProps<"div"> &
|
|
110
|
-
VariantProps<typeof buttonGroupVariants> &
|
|
111
|
-
WithTestId
|
|
117
|
+
Omit<VariantProps<typeof buttonGroupVariants>, "grow"> &
|
|
118
|
+
WithTestId & {
|
|
119
|
+
/** Span the container and give every child an even share of it, like a
|
|
120
|
+
* tab bar. Without it the group hugs its children. */
|
|
121
|
+
grow?: boolean
|
|
122
|
+
}
|
|
112
123
|
|
|
113
|
-
export const ButtonGroup = ({
|
|
124
|
+
export const ButtonGroup = ({
|
|
125
|
+
className,
|
|
126
|
+
orientation,
|
|
127
|
+
grow,
|
|
128
|
+
testId,
|
|
129
|
+
...rest
|
|
130
|
+
}: ButtonGroupProps) => (
|
|
114
131
|
<ark.div
|
|
115
132
|
role="group"
|
|
116
133
|
data-orientation={orientation ?? "horizontal"}
|
|
117
|
-
className={cn(buttonGroupVariants({ orientation }), className)}
|
|
134
|
+
className={cn(buttonGroupVariants({ orientation, grow }), className)}
|
|
118
135
|
{...props({ "data-testid": testId })}
|
|
119
136
|
{...rest}
|
|
120
137
|
/>
|
|
@@ -132,6 +132,21 @@ describe("ButtonMultiSelect", () => {
|
|
|
132
132
|
fireEvent.click(toggle("Italic"))
|
|
133
133
|
await waitFor(() => expect(toggle("Italic").getAttribute("data-variant")).toBe("light"))
|
|
134
134
|
})
|
|
135
|
+
|
|
136
|
+
it("spans the container under `grow`", () => {
|
|
137
|
+
render(<ButtonMultiSelect data={DAYS} testId="days" grow />)
|
|
138
|
+
const root = screen.getByTestId("days")
|
|
139
|
+
expect(root.className).toMatch(/(^|\s)w-full(\s|$)/)
|
|
140
|
+
expect(root.className).not.toContain("w-fit")
|
|
141
|
+
expect(root.className).toContain("*:flex-1")
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
it("hugs its items without `grow`", () => {
|
|
145
|
+
render(<ButtonMultiSelect data={DAYS} testId="days" />)
|
|
146
|
+
const root = screen.getByTestId("days")
|
|
147
|
+
expect(root.className).toContain("w-fit")
|
|
148
|
+
expect(root.className).not.toContain("*:flex-1")
|
|
149
|
+
})
|
|
135
150
|
})
|
|
136
151
|
|
|
137
152
|
describe("ButtonMultiSelect types", () => {
|
|
@@ -36,6 +36,9 @@ export type ButtonSelectBaseProps<Data extends ButtonSelectData> = Pick<
|
|
|
36
36
|
orientation?: "horizontal" | "vertical"
|
|
37
37
|
/** Red invalid state, independent of (and OR'd with) `error`. */
|
|
38
38
|
invalid?: boolean
|
|
39
|
+
/** Span the container and give every item an even share of it, like a tab
|
|
40
|
+
* bar. Without it the group hugs its items. */
|
|
41
|
+
grow?: boolean
|
|
39
42
|
/** Dims and blocks every item. */
|
|
40
43
|
disabled?: boolean
|
|
41
44
|
size?: ButtonSize
|
|
@@ -70,6 +73,7 @@ export const ButtonSelectControl = ({
|
|
|
70
73
|
renderItem,
|
|
71
74
|
orientation,
|
|
72
75
|
invalid,
|
|
76
|
+
grow,
|
|
73
77
|
disabled,
|
|
74
78
|
required,
|
|
75
79
|
size = "md",
|
|
@@ -116,6 +120,7 @@ export const ButtonSelectControl = ({
|
|
|
116
120
|
orientation={orientation}
|
|
117
121
|
disabled={disabled}
|
|
118
122
|
invalid={isInvalid}
|
|
123
|
+
grow={grow}
|
|
119
124
|
size={size}
|
|
120
125
|
variant={variant}
|
|
121
126
|
selectedVariant={selectedVariant}
|
|
@@ -207,6 +207,31 @@ describe("ButtonSelect", () => {
|
|
|
207
207
|
await waitFor(() => expect(onChange).toHaveBeenLastCalledWith("right"))
|
|
208
208
|
expect(radio("Right").getAttribute("data-variant")).toBe("filled")
|
|
209
209
|
})
|
|
210
|
+
|
|
211
|
+
it("spans the container under `grow`, the invalid ring with it", () => {
|
|
212
|
+
render(<ButtonSelect data={ITEMS} testId="range" grow invalid />)
|
|
213
|
+
const root = screen.getByTestId("range")
|
|
214
|
+
expect(root.className).toMatch(/(^|\s)w-full(\s|$)/)
|
|
215
|
+
expect(root.className).not.toContain("w-fit")
|
|
216
|
+
expect(root.className).toContain("*:flex-1")
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
it("hugs its items without `grow`", () => {
|
|
220
|
+
render(<ButtonSelect data={ITEMS} testId="range" />)
|
|
221
|
+
const root = screen.getByTestId("range")
|
|
222
|
+
expect(root.className).toContain("w-fit")
|
|
223
|
+
expect(root.className).not.toMatch(/(^|\s)w-full(\s|$)/)
|
|
224
|
+
expect(root.className).not.toContain("*:flex-1")
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
it("spans the container under `grow` on the composable Root", () => {
|
|
228
|
+
render(
|
|
229
|
+
<ButtonSelect.Root grow testId="root">
|
|
230
|
+
<ButtonSelect.Item value="a">A</ButtonSelect.Item>
|
|
231
|
+
</ButtonSelect.Root>,
|
|
232
|
+
)
|
|
233
|
+
expect(screen.getByTestId("root").className).toContain("*:flex-1")
|
|
234
|
+
})
|
|
210
235
|
})
|
|
211
236
|
|
|
212
237
|
describe("ButtonSelect types", () => {
|
|
@@ -63,7 +63,9 @@ const ButtonSelectStyleContext = createContext<StyleContextValue>({
|
|
|
63
63
|
* seams out-specify a per-item border anyway. A `ring` (box-shadow) is used, not
|
|
64
64
|
* an `outline`, because the machine writes `outline: none` inline on the root.
|
|
65
65
|
* `w-fit` keeps that ring hugging the items: inside `Field`'s flex column the
|
|
66
|
-
* root would otherwise stretch to the field's full width.
|
|
66
|
+
* root would otherwise stretch to the field's full width. Under `grow` the root
|
|
67
|
+
* spans that width on purpose, so `w-full` overrides it and the ring spans the
|
|
68
|
+
* row with it.
|
|
67
69
|
*/
|
|
68
70
|
const invalidRing =
|
|
69
71
|
"w-fit rounded-button data-invalid:ring-1 data-invalid:ring-red-500 data-invalid:ring-offset-2 data-invalid:ring-offset-brand-50 dark:data-invalid:ring-offset-brand-950"
|
|
@@ -82,6 +84,9 @@ type BaseRootProps = Omit<
|
|
|
82
84
|
size?: ButtonSize
|
|
83
85
|
/** Red invalid ring around the group. */
|
|
84
86
|
invalid?: boolean
|
|
87
|
+
/** Span the container and give every item an even share of it, like a tab
|
|
88
|
+
* bar. Without it the group hugs its items. */
|
|
89
|
+
grow?: boolean
|
|
85
90
|
/** Lands on the group root, which forwards focus to its active item. Ark's
|
|
86
91
|
* prop types carry no `ref`, so it is declared here. */
|
|
87
92
|
ref?: Ref<HTMLDivElement>
|
|
@@ -152,6 +157,7 @@ export const RootBase = ({
|
|
|
152
157
|
selectedVariant = "filled",
|
|
153
158
|
size = "md",
|
|
154
159
|
invalid,
|
|
160
|
+
grow,
|
|
155
161
|
loopFocus = true,
|
|
156
162
|
className,
|
|
157
163
|
testId,
|
|
@@ -190,7 +196,12 @@ export const RootBase = ({
|
|
|
190
196
|
data-color={color}
|
|
191
197
|
{...props({ "aria-invalid": invalid, "data-invalid": invalid, "data-testid": testId })}
|
|
192
198
|
{...fieldA11yProps(field)}
|
|
193
|
-
className={cn(
|
|
199
|
+
className={cn(
|
|
200
|
+
buttonGroupVariants({ orientation, grow }),
|
|
201
|
+
invalidRing,
|
|
202
|
+
grow && "w-full",
|
|
203
|
+
className,
|
|
204
|
+
)}
|
|
194
205
|
{...rest}
|
|
195
206
|
>
|
|
196
207
|
{children}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
fillLevel,
|
|
12
12
|
type Hue,
|
|
13
13
|
hueOf,
|
|
14
|
+
inProgressShare,
|
|
14
15
|
liquidFadeWidth,
|
|
15
16
|
paint,
|
|
16
17
|
type Tone,
|
|
@@ -28,6 +29,8 @@ export type SolidData = {
|
|
|
28
29
|
readonly hidden: string
|
|
29
30
|
readonly hull: string
|
|
30
31
|
readonly details: string
|
|
32
|
+
/** The facet (index) a corner fill grows on, and the corner it grows from. */
|
|
33
|
+
readonly cap?: { readonly facet: number; readonly origin: readonly [number, number] }
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
export type BadgeTile =
|
|
@@ -63,6 +66,13 @@ type BadgeFrameProps = BadgeBaseProps & {
|
|
|
63
66
|
locked: "wire" | "silhouette"
|
|
64
67
|
/** Dotted connectors drawn between the solids (the social badge). */
|
|
65
68
|
links?: string
|
|
69
|
+
/**
|
|
70
|
+
* How progress fills the solid: `liquid` rises through every face from the
|
|
71
|
+
* bottom; `corner` grows a square on the solid's cap from its front corner
|
|
72
|
+
* (the exam), so its sides lengthen with progress. `corner` needs a solid
|
|
73
|
+
* with a `cap`.
|
|
74
|
+
*/
|
|
75
|
+
fill?: "liquid" | "corner"
|
|
66
76
|
}
|
|
67
77
|
|
|
68
78
|
const VIEWBOX = "0 0 64 64"
|
|
@@ -130,14 +140,14 @@ function Solid({
|
|
|
130
140
|
hue,
|
|
131
141
|
progress,
|
|
132
142
|
locked,
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
143
|
+
fill,
|
|
144
|
+
}: SolidProps & { locked: "wire" | "silhouette"; fill: "liquid" | "corner" }) {
|
|
145
|
+
const lit =
|
|
146
|
+
fill === "corner" && solid.cap ? (
|
|
147
|
+
<CornerSolid solid={solid} status={status} hue={hue} progress={progress} />
|
|
148
|
+
) : (
|
|
149
|
+
<LiquidSolid solid={solid} status={status} hue={hue} progress={progress} />
|
|
150
|
+
)
|
|
141
151
|
if (locked === "wire") return lit
|
|
142
152
|
// The silhouette and the solid are both kept mounted and cross-faded, so
|
|
143
153
|
// locking and unlocking ease like every other status change.
|
|
@@ -168,9 +178,11 @@ function Wires({ solid, status, hue }: Omit<SolidProps, "progress">) {
|
|
|
168
178
|
const done = status === "done"
|
|
169
179
|
// Done glints over its own faces, the same on either page; the bare
|
|
170
180
|
// wireframe takes one step darker on a light page, just enough to show.
|
|
181
|
+
// Failed burns a deeper red, so the closed, glowing tile still reads as a
|
|
182
|
+
// fault rather than a pale "available".
|
|
171
183
|
const wire = done
|
|
172
184
|
? paint(hue, [200, 200], 50)
|
|
173
|
-
: paint(hue, status === "locked" ? [400, 400] : [200, 400])
|
|
185
|
+
: paint(hue, status === "locked" ? [400, 400] : status === "failed" ? [400, 500] : [200, 400])
|
|
174
186
|
return (
|
|
175
187
|
<>
|
|
176
188
|
{!done && solid.hidden && (
|
|
@@ -236,6 +248,44 @@ function LiquidSolid({ solid, status, hue, progress }: SolidProps) {
|
|
|
236
248
|
)
|
|
237
249
|
}
|
|
238
250
|
|
|
251
|
+
/**
|
|
252
|
+
* The corner fill: the faces light as a whole (in progress lights the sides
|
|
253
|
+
* and leaves the cap dim), and a copy of the cap, scaled from its front
|
|
254
|
+
* corner by progress, is the level — Figma's "Niveau" square. Scaling keeps
|
|
255
|
+
* it a square on the cap at every value, and its side, not its area, tracks
|
|
256
|
+
* progress. The first frame renders it at 0, so it grows when it appears.
|
|
257
|
+
*/
|
|
258
|
+
function CornerSolid({ solid, status, hue, progress }: SolidProps) {
|
|
259
|
+
const cap = solid.cap
|
|
260
|
+
const capFacet = cap && solid.facets[cap.facet]
|
|
261
|
+
const lit = status === "done" || status === "in-progress"
|
|
262
|
+
const share =
|
|
263
|
+
status === "done" ? 1 : status === "in-progress" ? inProgressShare(progress) / 100 : 0
|
|
264
|
+
const scale = useSettled(0, share)
|
|
265
|
+
if (!cap || !capFacet) return null
|
|
266
|
+
return (
|
|
267
|
+
<g>
|
|
268
|
+
{solid.facets.map((facet) => (
|
|
269
|
+
<polygon
|
|
270
|
+
key={facet.points}
|
|
271
|
+
points={facet.points}
|
|
272
|
+
fill={faceFill(hue, facet === capFacet && lit ? "available" : status, facet.tone)}
|
|
273
|
+
/>
|
|
274
|
+
))}
|
|
275
|
+
<polygon
|
|
276
|
+
className="geodesic-cap"
|
|
277
|
+
points={capFacet.points}
|
|
278
|
+
fill={faceFill(hue, lit ? status : "in-progress", capFacet.tone)}
|
|
279
|
+
style={{
|
|
280
|
+
transformOrigin: `${cap.origin[0]}px ${cap.origin[1]}px`,
|
|
281
|
+
transform: `scale(${scale})`,
|
|
282
|
+
}}
|
|
283
|
+
/>
|
|
284
|
+
<Wires solid={solid} status={status} hue={hue} />
|
|
285
|
+
</g>
|
|
286
|
+
)
|
|
287
|
+
}
|
|
288
|
+
|
|
239
289
|
/**
|
|
240
290
|
* Draws any statused badge: a tile, one or more solids, and what the status
|
|
241
291
|
* adds (lock, glow). The per-shape components only pick the geometry
|
|
@@ -254,16 +304,19 @@ export function BadgeFrame({
|
|
|
254
304
|
progress = 50,
|
|
255
305
|
locked,
|
|
256
306
|
links,
|
|
307
|
+
fill = "liquid",
|
|
257
308
|
}: BadgeFrameProps) {
|
|
258
309
|
const hue = hueOf(status, doneHue)
|
|
259
310
|
const done = status === "done"
|
|
311
|
+
// Done and failed are both over: a closed tile and a glow, in their own hue.
|
|
312
|
+
const closed = done || status === "failed"
|
|
260
313
|
const tileFill =
|
|
261
314
|
// Locked is a fully transparent tint, not `none`, so the fill can ease in.
|
|
262
|
-
paint(hue, [500, 500], status === "locked" ? 0 :
|
|
315
|
+
paint(hue, [500, 500], status === "locked" ? 0 : closed ? 20 : status === "available" ? 22 : 16)
|
|
263
316
|
const tileStroke =
|
|
264
317
|
status === "locked"
|
|
265
318
|
? paint("neutral", [500, 400])
|
|
266
|
-
:
|
|
319
|
+
: closed
|
|
267
320
|
? paint(hue, [400, 400])
|
|
268
321
|
: paint(hue, [400, 400], 65)
|
|
269
322
|
|
|
@@ -277,7 +330,7 @@ export function BadgeFrame({
|
|
|
277
330
|
width: size,
|
|
278
331
|
height: size,
|
|
279
332
|
flex: "none",
|
|
280
|
-
filter:
|
|
333
|
+
filter: closed ? `drop-shadow(0 0 ${size * 0.09}px ${tint(hue, 500, 55)})` : undefined,
|
|
281
334
|
...style,
|
|
282
335
|
}}
|
|
283
336
|
>
|
|
@@ -293,7 +346,7 @@ export function BadgeFrame({
|
|
|
293
346
|
fill={tileFill}
|
|
294
347
|
stroke={tileStroke}
|
|
295
348
|
strokeWidth={1}
|
|
296
|
-
strokeDasharray={
|
|
349
|
+
strokeDasharray={closed ? undefined : DASH}
|
|
297
350
|
strokeLinejoin="round"
|
|
298
351
|
/>
|
|
299
352
|
{links && (
|
|
@@ -315,6 +368,7 @@ export function BadgeFrame({
|
|
|
315
368
|
hue={hue}
|
|
316
369
|
progress={progress}
|
|
317
370
|
locked={locked}
|
|
371
|
+
fill={fill}
|
|
318
372
|
/>
|
|
319
373
|
))}
|
|
320
374
|
<Lock shown={status === "locked"} />
|
|
@@ -3,15 +3,19 @@ import { GEOMETRY } from "./geometry"
|
|
|
3
3
|
|
|
4
4
|
export type ExamBadgeProps = BadgeBaseProps
|
|
5
5
|
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* An exam: a square slab lying on a square tile. Progress grows a square on
|
|
8
|
+
* its top from the front corner; blue once passed, red when failed.
|
|
9
|
+
*/
|
|
7
10
|
export function ExamBadge(props: ExamBadgeProps) {
|
|
8
11
|
return (
|
|
9
12
|
<BadgeFrame
|
|
10
13
|
{...props}
|
|
11
|
-
tile={{ kind: "polygon", points: GEOMETRY.tiles.
|
|
14
|
+
tile={{ kind: "polygon", points: GEOMETRY.tiles.square }}
|
|
12
15
|
solids={[GEOMETRY.exam]}
|
|
13
|
-
doneHue="
|
|
14
|
-
locked="
|
|
16
|
+
doneHue="blue"
|
|
17
|
+
locked="wire"
|
|
18
|
+
fill="corner"
|
|
15
19
|
/>
|
|
16
20
|
)
|
|
17
21
|
}
|
|
@@ -66,15 +66,16 @@ export const GEOMETRY = {
|
|
|
66
66
|
},
|
|
67
67
|
exam: {
|
|
68
68
|
facets: [
|
|
69
|
-
{ points: "
|
|
70
|
-
{ points: "
|
|
71
|
-
{ points: "
|
|
69
|
+
{ points: "12.59,22.46 24.55,45.72 24.55,48.81 12.59,25.55", tone: 2, rank: 1 },
|
|
70
|
+
{ points: "12.59,22.46 39.45,12.11 51.41,35.37 24.55,45.72", tone: 3, rank: 2 },
|
|
71
|
+
{ points: "24.55,45.72 51.41,35.37 51.41,38.46 24.55,48.81", tone: 0, rank: 0 },
|
|
72
72
|
],
|
|
73
73
|
edges:
|
|
74
|
-
"
|
|
75
|
-
hidden: "",
|
|
76
|
-
hull: "
|
|
74
|
+
"M24.55 45.72L12.59 22.46M24.55 48.81L24.55 45.72M12.59 25.55L24.55 48.81M12.59 22.46L12.59 25.55M51.41 35.37L51.41 38.46M39.45 12.11L51.41 35.37M39.45 12.11L12.59 22.46M24.55 45.72L51.41 35.37M51.41 38.46L24.55 48.81",
|
|
75
|
+
hidden: "M39.45 15.2L39.45 12.11M51.41 38.46L39.45 15.2M12.59 25.55L39.45 15.2",
|
|
76
|
+
hull: "12.59,22.46 39.45,12.11 51.41,35.37 51.41,38.46 24.55,48.81 12.59,25.55",
|
|
77
77
|
details: "",
|
|
78
|
+
cap: { facet: 1, origin: [24.55, 45.72] },
|
|
78
79
|
},
|
|
79
80
|
activity: {
|
|
80
81
|
facets: [
|
|
@@ -363,5 +364,6 @@ export const GEOMETRY = {
|
|
|
363
364
|
pentagon: "32,4.5 59.58,24.54 49.05,56.96 14.95,56.96 4.42,24.54",
|
|
364
365
|
octagon: "43.1,5.21 58.79,20.9 58.79,43.1 43.1,58.79 20.9,58.79 5.21,43.1 5.21,20.9 20.9,5.21",
|
|
365
366
|
giftToken: "32,18 44.12,25 44.12,39 32,46 19.88,39 19.88,25",
|
|
367
|
+
square: "0.56,21.55 44.07,4.77 63.44,42.46 19.93,59.23",
|
|
366
368
|
},
|
|
367
369
|
} as const
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest"
|
|
2
|
-
import { faceLight, fillLevel, inProgressShare, MIN_IN_PROGRESS } from "./status"
|
|
2
|
+
import { faceLight, fillLevel, hueOf, inProgressShare, MIN_IN_PROGRESS } from "./status"
|
|
3
|
+
|
|
4
|
+
describe("hueOf", () => {
|
|
5
|
+
it("is red when failed, whatever the shape's done hue", () => {
|
|
6
|
+
expect(hueOf("failed", "green")).toBe("red")
|
|
7
|
+
expect(hueOf("failed", "blue")).toBe("red")
|
|
8
|
+
expect(hueOf("done", "blue")).toBe("blue")
|
|
9
|
+
})
|
|
10
|
+
})
|
|
3
11
|
|
|
4
12
|
describe("inProgressShare", () => {
|
|
5
13
|
it("maps 0–100 onto the floor–100", () => {
|
|
@@ -22,8 +30,9 @@ describe("fillLevel and faceLight", () => {
|
|
|
22
30
|
)
|
|
23
31
|
const total = (values: number[]) => values.reduce((a, b) => a + b, 0)
|
|
24
32
|
|
|
25
|
-
it("lights every face when done and none when locked or
|
|
33
|
+
it("lights every face when done and none when locked, available or failed", () => {
|
|
26
34
|
expect(lights("done", 0, 40)).toEqual(Array(40).fill(1))
|
|
35
|
+
expect(lights("failed", 100, 40)).toEqual(Array(40).fill(0))
|
|
27
36
|
expect(lights("locked", 100, 40)).toEqual(Array(40).fill(0))
|
|
28
37
|
expect(lights("available", 100, 40)).toEqual(Array(40).fill(0))
|
|
29
38
|
})
|
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
* levels": one colour per status, and the same progression on every shape —
|
|
4
4
|
* wireframe, then half lit, then full with a closed orbit.
|
|
5
5
|
*
|
|
6
|
-
* Only "done" varies by shape (a module is green, a
|
|
6
|
+
* Only "done" varies by shape (a module is green, a passed exam blue…), so
|
|
7
7
|
* each badge passes its own done hue and everything else comes from here.
|
|
8
|
+
* "failed" is red on every shape: the solid stays unlit like "available",
|
|
9
|
+
* but its tile closes and glows like "done" — the attempt is over.
|
|
8
10
|
*/
|
|
9
11
|
|
|
10
|
-
export type BadgeStatus = "locked" | "available" | "in-progress" | "done"
|
|
12
|
+
export type BadgeStatus = "locked" | "available" | "in-progress" | "done" | "failed"
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* A kit colour ramp, read as `--color-<hue>-<step>`, or `neutral`: the
|
|
@@ -76,6 +78,7 @@ const STATUS_HUE: Record<Exclude<BadgeStatus, "done">, Hue> = {
|
|
|
76
78
|
locked: "neutral",
|
|
77
79
|
available: "purple",
|
|
78
80
|
"in-progress": "pink",
|
|
81
|
+
failed: "red",
|
|
79
82
|
}
|
|
80
83
|
|
|
81
84
|
export function hueOf(status: BadgeStatus, doneHue: Hue): Hue {
|
|
@@ -106,12 +109,13 @@ const IN_PROGRESS_TONE_STEPS = { dark: [400, 300, 300, 200], light: [400, 300, 3
|
|
|
106
109
|
/**
|
|
107
110
|
* A facet's fill for its light bucket, per status and theme.
|
|
108
111
|
*
|
|
109
|
-
* Locked and
|
|
110
|
-
* drain out after a status change back down; a deep, see-through
|
|
111
|
-
* to the page keeps that drain from flashing coloured faces.
|
|
112
|
+
* Locked, available and failed light no facet, so theirs only shows while
|
|
113
|
+
* lit faces drain out after a status change back down; a deep, see-through
|
|
114
|
+
* step close to the page keeps that drain from flashing coloured faces.
|
|
112
115
|
*/
|
|
113
116
|
export function faceFill(hue: Hue, status: BadgeStatus, tone: Tone) {
|
|
114
|
-
if (status === "locked" || status === "available"
|
|
117
|
+
if (status === "locked" || status === "available" || status === "failed")
|
|
118
|
+
return paint(hue, [800, 100], 40)
|
|
115
119
|
const steps = status === "in-progress" ? IN_PROGRESS_TONE_STEPS : TONE_STEPS
|
|
116
120
|
return paint(hue, [steps.dark[tone], steps.light[tone]])
|
|
117
121
|
}
|
|
@@ -144,7 +148,7 @@ export function fadeWidth(facetCount: number) {
|
|
|
144
148
|
/**
|
|
145
149
|
* Where the fill stands, measured in faces along the bottom-up order: a face
|
|
146
150
|
* of rank `r` is lit by how far the level has passed it (see faceLight).
|
|
147
|
-
* Done is full, locked and
|
|
151
|
+
* Done is full, locked, available and failed are empty, and in progress maps
|
|
148
152
|
* `progress` through inProgressShare, so 0% still shows light.
|
|
149
153
|
*/
|
|
150
154
|
export function fillLevel(
|
|
@@ -134,13 +134,26 @@
|
|
|
134
134
|
transition: fill 300ms ease;
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
+
/*
|
|
138
|
+
* The corner fill's level: the cap, scaled from its front corner (set
|
|
139
|
+
* inline, in viewBox units, hence the view-box transform box).
|
|
140
|
+
*/
|
|
141
|
+
.geodesic-cap {
|
|
142
|
+
transform-box: view-box;
|
|
143
|
+
transition:
|
|
144
|
+
transform 900ms cubic-bezier(0.4, 0, 0.2, 1),
|
|
145
|
+
fill 300ms ease;
|
|
146
|
+
}
|
|
147
|
+
|
|
137
148
|
:where(:root[data-motion="reduced"]) {
|
|
138
|
-
.geodesic-solid-smooth
|
|
149
|
+
.geodesic-solid-smooth,
|
|
150
|
+
.geodesic-cap {
|
|
139
151
|
transition: none;
|
|
140
152
|
}
|
|
141
153
|
}
|
|
142
154
|
@media (prefers-reduced-motion: reduce) {
|
|
143
|
-
.geodesic-solid-smooth
|
|
155
|
+
.geodesic-solid-smooth,
|
|
156
|
+
.geodesic-cap {
|
|
144
157
|
transition: none;
|
|
145
158
|
}
|
|
146
159
|
}
|
|
@@ -305,4 +305,49 @@ describe("Indicator", () => {
|
|
|
305
305
|
)
|
|
306
306
|
expect(screen.getByRole("button", { name: "Inbox" })).toBeTruthy()
|
|
307
307
|
})
|
|
308
|
+
|
|
309
|
+
describe("without children", () => {
|
|
310
|
+
it("renders the dot alone, in the flow, inside an inline <span> root", () => {
|
|
311
|
+
const { container } = render(<Indicator testId="dot" color="pink" size="sm" />)
|
|
312
|
+
const root = screen.getByTestId("dot")
|
|
313
|
+
expect(root.tagName).toBe("SPAN")
|
|
314
|
+
expect(root.className).toContain("inline-flex")
|
|
315
|
+
const dot = getIndicator(container)
|
|
316
|
+
expect(dot?.className).toContain("relative")
|
|
317
|
+
expect(dot?.className).not.toContain("absolute")
|
|
318
|
+
expect(dot?.className).toContain("size-2")
|
|
319
|
+
expect(dot?.getAttribute("data-color")).toBe("pink")
|
|
320
|
+
})
|
|
321
|
+
|
|
322
|
+
it("ignores position and offset", () => {
|
|
323
|
+
const { container } = render(<Indicator position="bottom-start" offset={4} />)
|
|
324
|
+
const dot = getIndicator(container)
|
|
325
|
+
expect(dot?.hasAttribute("data-position")).toBe(false)
|
|
326
|
+
expect(dot?.className).not.toContain("bottom-0")
|
|
327
|
+
expect(dot?.style.bottom).toBe("")
|
|
328
|
+
})
|
|
329
|
+
|
|
330
|
+
it("keeps the processing pulse and alt", () => {
|
|
331
|
+
const { container } = render(<Indicator processing alt="Online" />)
|
|
332
|
+
expect(container.querySelector('[data-part="processing"]')).toBeTruthy()
|
|
333
|
+
expect(screen.getByText("Online").className).toContain("sr-only")
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
it("renders nothing when hidden", () => {
|
|
337
|
+
const { container } = render(<Indicator disabled testId="gone" />)
|
|
338
|
+
expect(container.innerHTML).toBe("")
|
|
339
|
+
const zero = render(<Indicator label={0} hideZero />)
|
|
340
|
+
expect(zero.container.innerHTML).toBe("")
|
|
341
|
+
})
|
|
342
|
+
|
|
343
|
+
it("renders a label badge in the flow too", () => {
|
|
344
|
+
const { container } = render(<Indicator label={3} />)
|
|
345
|
+
expect(getIndicator(container)?.textContent).toBe("3")
|
|
346
|
+
expect(getIndicator(container)?.className).not.toContain("absolute")
|
|
347
|
+
})
|
|
348
|
+
|
|
349
|
+
it("stays a Server Component", () => {
|
|
350
|
+
expect(renderToStaticMarkup(<Indicator color="green" />)).toContain('data-part="indicator"')
|
|
351
|
+
})
|
|
352
|
+
})
|
|
308
353
|
})
|