@42-central/ui-react 0.26.0 → 0.28.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-YZJUPYPO.js → chunk-2W7H43WL.js} +3 -3
- package/dist/{chunk-YZJUPYPO.js.map → chunk-2W7H43WL.js.map} +1 -1
- package/dist/{chunk-OVT2KZHY.js → chunk-3KARNPW4.js} +3 -3
- package/dist/{chunk-OVT2KZHY.js.map → chunk-3KARNPW4.js.map} +1 -1
- package/dist/chunk-6B2GNPJP.js +43 -0
- package/dist/chunk-6B2GNPJP.js.map +1 -0
- package/dist/{chunk-E52Z2FKU.js → chunk-7BY5I2RB.js} +3 -3
- package/dist/{chunk-E52Z2FKU.js.map → chunk-7BY5I2RB.js.map} +1 -1
- package/dist/{chunk-JFB6O7IY.js → chunk-7KFUFAVP.js} +4 -4
- package/dist/{chunk-JFB6O7IY.js.map → chunk-7KFUFAVP.js.map} +1 -1
- package/dist/{chunk-X3YIHN2U.js → chunk-ASKQ6N5V.js} +3 -3
- package/dist/{chunk-X3YIHN2U.js.map → chunk-ASKQ6N5V.js.map} +1 -1
- package/dist/{chunk-6IRMKF5T.js → chunk-B4GNSSHU.js} +4 -4
- package/dist/{chunk-6IRMKF5T.js.map → chunk-B4GNSSHU.js.map} +1 -1
- package/dist/{chunk-BMEJBY6H.js → chunk-B5YHYI7E.js} +22 -27
- package/dist/chunk-B5YHYI7E.js.map +1 -0
- package/dist/{chunk-PT22KEVD.js → chunk-BGDVUC3B.js} +5 -5
- package/dist/{chunk-PT22KEVD.js.map → chunk-BGDVUC3B.js.map} +1 -1
- package/dist/{chunk-7247WBTV.js → chunk-DJ72KP32.js} +3 -3
- package/dist/{chunk-7247WBTV.js.map → chunk-DJ72KP32.js.map} +1 -1
- package/dist/{chunk-7OGZT7U2.js → chunk-G3AD3NJG.js} +3 -3
- package/dist/{chunk-7OGZT7U2.js.map → chunk-G3AD3NJG.js.map} +1 -1
- package/dist/{chunk-276RL7FX.js → chunk-GJFCIG34.js} +8 -8
- package/dist/{chunk-276RL7FX.js.map → chunk-GJFCIG34.js.map} +1 -1
- package/dist/{chunk-JDPVD2YE.js → chunk-HCHGERDB.js} +3 -3
- package/dist/{chunk-JDPVD2YE.js.map → chunk-HCHGERDB.js.map} +1 -1
- package/dist/{chunk-H7WOMZXO.js → chunk-HWBFRDX7.js} +16 -8
- package/dist/chunk-HWBFRDX7.js.map +1 -0
- package/dist/{chunk-LYGOFMXJ.js → chunk-I4IJOLNA.js} +4 -4
- package/dist/{chunk-LYGOFMXJ.js.map → chunk-I4IJOLNA.js.map} +1 -1
- package/dist/{chunk-7B44J3CF.js → chunk-I53TMAV2.js} +6 -6
- package/dist/{chunk-7B44J3CF.js.map → chunk-I53TMAV2.js.map} +1 -1
- package/dist/{chunk-DSZF2TW6.js → chunk-IA6DCC3N.js} +6 -6
- package/dist/{chunk-DSZF2TW6.js.map → chunk-IA6DCC3N.js.map} +1 -1
- package/dist/{chunk-QEAF57ZQ.js → chunk-ISX3AM32.js} +3 -3
- package/dist/{chunk-QEAF57ZQ.js.map → chunk-ISX3AM32.js.map} +1 -1
- package/dist/{chunk-N42EFOML.js → chunk-K3FZHYJL.js} +6 -6
- package/dist/chunk-K3FZHYJL.js.map +1 -0
- package/dist/{chunk-ZVECQBGG.js → chunk-KNGSO7A3.js} +41 -13
- package/dist/chunk-KNGSO7A3.js.map +1 -0
- package/dist/{chunk-NLSJ6T7V.js → chunk-KYVXPSNW.js} +4 -4
- package/dist/{chunk-NLSJ6T7V.js.map → chunk-KYVXPSNW.js.map} +1 -1
- package/dist/{chunk-J2NW7JID.js → chunk-L5GH7LLD.js} +3 -3
- package/dist/{chunk-J2NW7JID.js.map → chunk-L5GH7LLD.js.map} +1 -1
- package/dist/{chunk-THGJLR5S.js → chunk-NNPSBC7O.js} +5 -5
- package/dist/{chunk-THGJLR5S.js.map → chunk-NNPSBC7O.js.map} +1 -1
- package/dist/{chunk-YMVUQ2L7.js → chunk-P7SH3XWY.js} +6 -6
- package/dist/chunk-P7SH3XWY.js.map +1 -0
- package/dist/{chunk-2CL3FKEY.js → chunk-QEMXXQQO.js} +3 -3
- package/dist/{chunk-2CL3FKEY.js.map → chunk-QEMXXQQO.js.map} +1 -1
- package/dist/{chunk-2NTCQIRP.js → chunk-QRNQQIQM.js} +5 -5
- package/dist/{chunk-2NTCQIRP.js.map → chunk-QRNQQIQM.js.map} +1 -1
- package/dist/{chunk-LKFHUDEW.js → chunk-QVOBLRCM.js} +3 -3
- package/dist/{chunk-LKFHUDEW.js.map → chunk-QVOBLRCM.js.map} +1 -1
- package/dist/{chunk-E3XLWMEB.js → chunk-RKCUXOU2.js} +4 -4
- package/dist/{chunk-E3XLWMEB.js.map → chunk-RKCUXOU2.js.map} +1 -1
- package/dist/{chunk-DMI4KS32.js → chunk-SBZJGFZ6.js} +3 -3
- package/dist/{chunk-DMI4KS32.js.map → chunk-SBZJGFZ6.js.map} +1 -1
- package/dist/{chunk-7P32XCEU.js → chunk-SLUOF7XW.js} +2 -2
- package/dist/chunk-SLUOF7XW.js.map +1 -0
- package/dist/{chunk-SCXXJDKQ.js → chunk-SP6LCCTZ.js} +21 -28
- package/dist/chunk-SP6LCCTZ.js.map +1 -0
- package/dist/{chunk-Y2G47ARQ.js → chunk-TGGNSSOJ.js} +3 -3
- package/dist/{chunk-Y2G47ARQ.js.map → chunk-TGGNSSOJ.js.map} +1 -1
- package/dist/{chunk-2TZU4LSX.js → chunk-ULF5LOBS.js} +3 -3
- package/dist/{chunk-2TZU4LSX.js.map → chunk-ULF5LOBS.js.map} +1 -1
- package/dist/{chunk-D2QIPQ74.js → chunk-W3XX7BYT.js} +2 -2
- package/dist/chunk-W3XX7BYT.js.map +1 -0
- package/dist/{chunk-F374BNL4.js → chunk-YVTM2KRR.js} +12 -8
- package/dist/chunk-YVTM2KRR.js.map +1 -0
- package/dist/colors.css +328 -0
- package/dist/components/action-icon/action-icon.d.ts +6 -5
- package/dist/components/action-icon/action-icon.d.ts.map +1 -1
- package/dist/components/action-icon/index.js +3 -2
- package/dist/components/alert/index.js +2 -2
- package/dist/components/app-shell/index.js +7 -6
- package/dist/components/app-shell/index.js.map +1 -1
- package/dist/components/autocomplete/index.js +4 -4
- package/dist/components/badge/badge.d.ts +1 -1
- package/dist/components/badge/badge.d.ts.map +1 -1
- package/dist/components/badge/index.js +2 -1
- package/dist/components/button/button.d.ts +11 -9
- package/dist/components/button/button.d.ts.map +1 -1
- package/dist/components/button/index.js +3 -2
- package/dist/components/button-multi-select/index.js +4 -3
- package/dist/components/button-multi-select/index.js.map +1 -1
- package/dist/components/button-select/index.js +4 -3
- package/dist/components/button-select/index.js.map +1 -1
- package/dist/components/calendar/index.js +4 -3
- package/dist/components/calendar-heatmap/index.js +2 -2
- package/dist/components/camera/index.js +11 -10
- package/dist/components/clipboard/index.js +3 -2
- package/dist/components/clipboard/index.js.map +1 -1
- package/dist/components/code-block/chrome.js +5 -5
- package/dist/components/code-block/index.js +6 -6
- package/dist/components/combobox/index.js +4 -4
- package/dist/components/combobox-list/index.js +6 -6
- package/dist/components/data-table/data-table-features.d.ts +8 -0
- package/dist/components/data-table/data-table-features.d.ts.map +1 -1
- package/dist/components/data-table/data-table-group.d.ts +128 -0
- package/dist/components/data-table/data-table-group.d.ts.map +1 -0
- package/dist/components/data-table/data-table-grouping.d.ts +72 -0
- package/dist/components/data-table/data-table-grouping.d.ts.map +1 -0
- package/dist/components/data-table/data-table-icons.d.ts +4 -2
- package/dist/components/data-table/data-table-icons.d.ts.map +1 -1
- package/dist/components/data-table/data-table-meta.d.ts +9 -0
- package/dist/components/data-table/data-table-meta.d.ts.map +1 -1
- package/dist/components/data-table/data-table-pagination.d.ts +4 -1
- package/dist/components/data-table/data-table-pagination.d.ts.map +1 -1
- package/dist/components/data-table/data-table-schema.d.ts +4 -0
- package/dist/components/data-table/data-table-schema.d.ts.map +1 -1
- package/dist/components/data-table/data-table-stack.d.ts +16 -3
- package/dist/components/data-table/data-table-stack.d.ts.map +1 -1
- package/dist/components/data-table/data-table-toolbar.d.ts +33 -2
- package/dist/components/data-table/data-table-toolbar.d.ts.map +1 -1
- package/dist/components/data-table/data-table-translations.d.ts +35 -0
- package/dist/components/data-table/data-table-translations.d.ts.map +1 -1
- package/dist/components/data-table/data-table.d.ts +55 -3
- package/dist/components/data-table/data-table.d.ts.map +1 -1
- package/dist/components/data-table/index.d.ts +3 -1
- package/dist/components/data-table/index.d.ts.map +1 -1
- package/dist/components/data-table/index.js +883 -234
- package/dist/components/data-table/index.js.map +1 -1
- package/dist/components/date-picker/index.js +12 -11
- package/dist/components/date-picker/index.js.map +1 -1
- package/dist/components/download-button/index.js +4 -3
- package/dist/components/drawer/index.js +7 -6
- package/dist/components/file-item/index.js +4 -3
- package/dist/components/file-preview/index.js +4 -3
- package/dist/components/file-preview/index.js.map +1 -1
- package/dist/components/file-trigger/index.js +4 -3
- package/dist/components/file-upload/index.js +4 -3
- package/dist/components/file-upload/index.js.map +1 -1
- package/dist/components/hover-card/index.js +3 -3
- package/dist/components/image-cropper/index.js +4 -3
- package/dist/components/kbd/index.js +3 -3
- package/dist/components/lightbox/index.js +9 -8
- package/dist/components/lightbox/index.js.map +1 -1
- package/dist/components/menu/index.js +4 -4
- package/dist/components/modal/index.js +7 -6
- package/dist/components/multi-combobox-list/index.js +6 -6
- package/dist/components/multi-select/index.js +4 -4
- package/dist/components/nav-link/index.js +3 -3
- package/dist/components/nav-link/tanstack.js +3 -3
- package/dist/components/notification/create-notifier.d.ts.map +1 -1
- package/dist/components/notification/index.js +18 -6
- package/dist/components/notification/index.js.map +1 -1
- package/dist/components/notification/types.d.ts +5 -0
- package/dist/components/notification/types.d.ts.map +1 -1
- package/dist/components/number-input/index.js +4 -4
- package/dist/components/overlays/index.js +9 -8
- package/dist/components/overlays/index.js.map +1 -1
- package/dist/components/photo-capture/index.js +13 -12
- package/dist/components/photo-capture/index.js.map +1 -1
- package/dist/components/popover/index.js +3 -3
- package/dist/components/schedule/index.js +7 -6
- package/dist/components/schedule/index.js.map +1 -1
- package/dist/components/select/index.js +5 -5
- package/dist/components/spinner/index.js +1 -1
- package/dist/components/spinner/spinner.d.ts +1 -1
- package/dist/components/spinner/spinner.d.ts.map +1 -1
- package/dist/components/spotlight/index.js +11 -10
- package/dist/components/spotlight/index.js.map +1 -1
- package/dist/components/tags-input/index.js +3 -3
- package/dist/components/theme-icon/index.js +1 -1
- package/dist/components/theme-icon/theme-icon.d.ts.map +1 -1
- package/dist/components/time-input/index.js +5 -5
- package/dist/components/tooltip/index.js +2 -2
- package/dist/components/tree-multi-select/index.js +4 -4
- package/dist/components/tree-select/index.js +4 -4
- package/dist/index.js +2 -2
- package/dist/lib/button-colors.d.ts +25 -0
- package/dist/lib/button-colors.d.ts.map +1 -0
- package/dist/lib/overlay-container.d.ts.map +1 -1
- package/dist/lib/overlay-layer.d.ts +10 -3
- package/dist/lib/overlay-layer.d.ts.map +1 -1
- package/dist/theme.css +14 -6
- package/package.json +1 -1
- package/src/colors.css +328 -0
- package/src/components/action-icon/action-icon.test.tsx +22 -0
- package/src/components/action-icon/action-icon.tsx +24 -28
- package/src/components/badge/badge.test.tsx +53 -10
- package/src/components/badge/badge.tsx +64 -11
- package/src/components/button/button.test.tsx +41 -5
- package/src/components/button/button.tsx +28 -33
- package/src/components/data-table/data-table-features.ts +11 -0
- package/src/components/data-table/data-table-group.test.tsx +1007 -0
- package/src/components/data-table/data-table-group.tsx +474 -0
- package/src/components/data-table/data-table-grouping.ts +160 -0
- package/src/components/data-table/data-table-icons.tsx +8 -1
- package/src/components/data-table/data-table-meta.ts +9 -0
- package/src/components/data-table/data-table-pagination.tsx +5 -1
- package/src/components/data-table/data-table-stack.tsx +165 -43
- package/src/components/data-table/data-table-toolbar.tsx +110 -2
- package/src/components/data-table/data-table-translations.ts +44 -0
- package/src/components/data-table/data-table.tsx +420 -150
- package/src/components/data-table/index.ts +4 -0
- package/src/components/drawer/drawer.tsx +1 -1
- package/src/components/modal/modal.tsx +1 -1
- package/src/components/notification/create-notifier.tsx +18 -2
- package/src/components/notification/notify-in-modal.test.tsx +128 -0
- package/src/components/notification/types.ts +5 -0
- package/src/components/spinner/spinner.tsx +3 -3
- package/src/components/theme-icon/theme-icon.test.tsx +7 -0
- package/src/components/theme-icon/theme-icon.tsx +10 -6
- package/src/lib/button-colors.ts +55 -0
- package/src/lib/overlay-container.tsx +2 -1
- package/src/lib/overlay-layer.test.tsx +63 -1
- package/src/lib/overlay-layer.tsx +29 -6
- package/src/theme.css +14 -6
- package/src/theme.test.ts +14 -10
- package/dist/chunk-7P32XCEU.js.map +0 -1
- package/dist/chunk-BMEJBY6H.js.map +0 -1
- package/dist/chunk-D2QIPQ74.js.map +0 -1
- package/dist/chunk-F374BNL4.js.map +0 -1
- package/dist/chunk-H7WOMZXO.js.map +0 -1
- package/dist/chunk-N42EFOML.js.map +0 -1
- package/dist/chunk-SCXXJDKQ.js.map +0 -1
- package/dist/chunk-YMVUQ2L7.js.map +0 -1
- package/dist/chunk-ZVECQBGG.js.map +0 -1
|
@@ -4,8 +4,8 @@ import { Badge } from "./badge"
|
|
|
4
4
|
|
|
5
5
|
describe("Badge", () => {
|
|
6
6
|
it("renders a non-focusable span by default", () => {
|
|
7
|
-
render(<Badge>12</Badge>)
|
|
8
|
-
const badge = screen.
|
|
7
|
+
render(<Badge testId="badge">12</Badge>)
|
|
8
|
+
const badge = screen.getByTestId("badge")
|
|
9
9
|
expect(badge.tagName).toBe("SPAN")
|
|
10
10
|
expect(badge.getAttribute("tabindex")).toBeNull()
|
|
11
11
|
})
|
|
@@ -14,8 +14,8 @@ describe("Badge", () => {
|
|
|
14
14
|
// :focus-visible never matches a plain span — so that they're already in
|
|
15
15
|
// place when asChild turns the badge into a real control.
|
|
16
16
|
it("carries the kit's focus ring even as a plain span", () => {
|
|
17
|
-
render(<Badge>12</Badge>)
|
|
18
|
-
expect(screen.
|
|
17
|
+
render(<Badge testId="badge">12</Badge>)
|
|
18
|
+
expect(screen.getByTestId("badge").className).toContain("focus-visible:ring-brand-500")
|
|
19
19
|
})
|
|
20
20
|
|
|
21
21
|
it("collapses onto an asChild button that is focusable and keeps the ring", () => {
|
|
@@ -26,15 +26,21 @@ describe("Badge", () => {
|
|
|
26
26
|
)
|
|
27
27
|
|
|
28
28
|
const trigger = screen.getByRole("button", { name: "12 campuses" })
|
|
29
|
-
// One node, not a button wrapping
|
|
30
|
-
|
|
29
|
+
// One node, not a button wrapping the badge: the badge *is* the trigger,
|
|
30
|
+
// and its text is trimmed inside it like on a plain badge.
|
|
31
|
+
expect(trigger.children).toHaveLength(1)
|
|
32
|
+
expect(trigger.firstElementChild?.className).toBe("text-trim")
|
|
31
33
|
expect(trigger.className).toContain("focus-visible:ring-brand-500")
|
|
32
34
|
expect(trigger.className).toContain("focus-visible:ring-offset-2")
|
|
33
35
|
})
|
|
34
36
|
|
|
35
37
|
it("writes data-color so the palette resolves, but leaves the ring alone", () => {
|
|
36
|
-
render(
|
|
37
|
-
|
|
38
|
+
render(
|
|
39
|
+
<Badge color="green" testId="badge">
|
|
40
|
+
Validated
|
|
41
|
+
</Badge>,
|
|
42
|
+
)
|
|
43
|
+
const badge = screen.getByTestId("badge")
|
|
38
44
|
expect(badge.getAttribute("data-color")).toBe("green")
|
|
39
45
|
// Focus stays brand-500 regardless of palette — see focusStyles.
|
|
40
46
|
expect(badge.className).toContain("focus-visible:ring-brand-500")
|
|
@@ -42,10 +48,47 @@ describe("Badge", () => {
|
|
|
42
48
|
|
|
43
49
|
it("omits data-color on the gradient variant", () => {
|
|
44
50
|
render(
|
|
45
|
-
<Badge variant="gradient" color="green">
|
|
51
|
+
<Badge variant="gradient" color="green" testId="badge">
|
|
46
52
|
Pro
|
|
47
53
|
</Badge>,
|
|
48
54
|
)
|
|
49
|
-
expect(screen.
|
|
55
|
+
expect(screen.getByTestId("badge").getAttribute("data-color")).toBeNull()
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
// The trimmed span hugs cap height → baseline, so `items-center` centres
|
|
59
|
+
// the caps rather than Lato's lopsided ascent/descent box.
|
|
60
|
+
describe("text trimming", () => {
|
|
61
|
+
it("wraps a run of text in one text-trim span, keeping its spaces", () => {
|
|
62
|
+
const count = 3
|
|
63
|
+
render(<Badge testId="badge">{count} items</Badge>)
|
|
64
|
+
const badge = screen.getByTestId("badge")
|
|
65
|
+
expect(badge.children).toHaveLength(1)
|
|
66
|
+
expect(badge.firstElementChild?.className).toBe("text-trim")
|
|
67
|
+
expect(badge.firstElementChild?.textContent).toBe("3 items")
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it("leaves icons and other elements as flex siblings of the text", () => {
|
|
71
|
+
render(
|
|
72
|
+
<Badge testId="badge">
|
|
73
|
+
<svg data-testid="icon" />
|
|
74
|
+
Live
|
|
75
|
+
<strong>!</strong>
|
|
76
|
+
</Badge>,
|
|
77
|
+
)
|
|
78
|
+
const kids = [...screen.getByTestId("badge").children]
|
|
79
|
+
expect(kids.map((kid) => kid.tagName)).toEqual(["svg", "SPAN", "STRONG"])
|
|
80
|
+
expect(kids[1]?.className).toBe("text-trim")
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it("renders no empty span for empty or missing children", () => {
|
|
84
|
+
render(
|
|
85
|
+
<Badge testId="badge">
|
|
86
|
+
{""}
|
|
87
|
+
{null}
|
|
88
|
+
{false}
|
|
89
|
+
</Badge>,
|
|
90
|
+
)
|
|
91
|
+
expect(screen.getByTestId("badge").children).toHaveLength(0)
|
|
92
|
+
})
|
|
50
93
|
})
|
|
51
94
|
})
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ark, type HTMLArkProps } from "@ark-ui/react"
|
|
2
2
|
import { cva, type VariantProps } from "class-variance-authority"
|
|
3
|
+
import { Children, type ReactNode } from "react"
|
|
4
|
+
import { composeChildren } from "../../lib/as-child"
|
|
3
5
|
import { cn } from "../../lib/cn"
|
|
4
6
|
import type { Color } from "../../lib/colors"
|
|
5
7
|
import { focusStyles } from "../../lib/focus-styles"
|
|
@@ -41,6 +43,14 @@ const badgeVariants = cva(
|
|
|
41
43
|
"inline-flex items-center",
|
|
42
44
|
"whitespace-nowrap select-none",
|
|
43
45
|
"font-sans font-medium",
|
|
46
|
+
// Optically equal padding on all four sides. Each size sets only its
|
|
47
|
+
// height (`--badge-h`); the inline padding is derived from it so the gap
|
|
48
|
+
// beside the text matches the gap above and below the caps:
|
|
49
|
+
// (height − cap height) / 2 − side bearing
|
|
50
|
+
// `1cap` is the cap height of the badge's own font, so this holds for
|
|
51
|
+
// every size and survives a font swap. The 0.08em is Lato's average
|
|
52
|
+
// glyph side bearing, already part of the visible gap at either end.
|
|
53
|
+
"min-h-(--badge-h) px-[calc((var(--badge-h)_-_1cap)/2_-_0.08em)]",
|
|
44
54
|
// Figma strokes every badge at 0.5px, inside the box. A CSS border cannot
|
|
45
55
|
// draw that: Chrome rounds any border-width under 1px up to 1px. An inset
|
|
46
56
|
// ring (box-shadow) is not rounded — one device pixel on a 2x screen, a
|
|
@@ -86,19 +96,20 @@ const badgeVariants = cva(
|
|
|
86
96
|
},
|
|
87
97
|
// Figma (node 14950-143827) defines sm/md/lg; xs/xl extrapolate one
|
|
88
98
|
// step past either end. Radius follows Figma on every step
|
|
89
|
-
// (`rounded-badge`, 4px), as
|
|
99
|
+
// (`rounded-badge`, 4px), as does md's height. The rest of
|
|
90
100
|
// the scale departs from Figma on purpose (3b408c4c), so there the
|
|
91
101
|
// design catches up to the kit, not the reverse: sm is 12px text, 3px gap, 22px tall
|
|
92
|
-
// (Figma 10/4/20); md has a 6px gap (4); lg is 16px text
|
|
93
|
-
//
|
|
94
|
-
//
|
|
95
|
-
//
|
|
102
|
+
// (Figma 10/4/20); md has a 6px gap (4); lg is 16px text and an 8px
|
|
103
|
+
// gap (14/4). Padding is not a per-size value: the base classes derive
|
|
104
|
+
// it from `--badge-h`, which lands md on Figma's ~6px. Icon size
|
|
105
|
+
// ([&_svg]:size-*) isn't in the Figma spec — scaled by eye to each
|
|
106
|
+
// step, same convention as Button's own size variant.
|
|
96
107
|
size: {
|
|
97
|
-
xs: "
|
|
98
|
-
sm: "
|
|
99
|
-
md: "
|
|
100
|
-
lg: "
|
|
101
|
-
xl: "
|
|
108
|
+
xs: "[--badge-h:--spacing(5)] text-[10px] leading-2.5 gap-0.5 rounded-badge [&_svg]:size-2.5",
|
|
109
|
+
sm: "[--badge-h:--spacing(5.5)] text-xs gap-0.75 rounded-badge [&_svg]:size-3",
|
|
110
|
+
md: "[--badge-h:--spacing(6)] text-sm gap-1.5 rounded-badge [&_svg]:size-3",
|
|
111
|
+
lg: "[--badge-h:--spacing(7)] text-md gap-2 rounded-badge [&_svg]:size-3.5",
|
|
112
|
+
xl: "[--badge-h:--spacing(8)] text-lg gap-3.5 rounded-badge [&_svg]:size-4",
|
|
102
113
|
},
|
|
103
114
|
},
|
|
104
115
|
defaultVariants: {
|
|
@@ -127,6 +138,43 @@ export type BadgeProps = Omit<HTMLArkProps<"span">, "color"> &
|
|
|
127
138
|
gradient?: GradientProps
|
|
128
139
|
}
|
|
129
140
|
|
|
141
|
+
type TextNode = string | number
|
|
142
|
+
const isText = (node: ReactNode): node is TextNode =>
|
|
143
|
+
typeof node === "string" || typeof node === "number"
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Wraps each run of bare text in a `text-trim` span, leaving icons and other
|
|
147
|
+
* elements as they are.
|
|
148
|
+
*
|
|
149
|
+
* Untrimmed, the text's line box carries the font's ascent and descent, which
|
|
150
|
+
* Lato does not split evenly around its caps — so `items-center` centred the
|
|
151
|
+
* line box and left the caps ~1px high at sm/md. Trimmed to cap height →
|
|
152
|
+
* baseline, the span *is* the caps, so `items-center` centres them, and an icon
|
|
153
|
+
* beside them centres on the caps too. It has to be a wrapper: `text-box-trim`
|
|
154
|
+
* applies to block containers and inline boxes, and bare text in a flex
|
|
155
|
+
* container lives in an anonymous flex item that no class can reach.
|
|
156
|
+
*
|
|
157
|
+
* A run is grouped, not each node wrapped: `{count} items` arrives as two
|
|
158
|
+
* children, and splitting them would put the flex `gap` where the space was.
|
|
159
|
+
* The trimmed box ends at the baseline but nothing clips it, so descenders
|
|
160
|
+
* still paint below it.
|
|
161
|
+
*/
|
|
162
|
+
const trimTextRuns = (own: ReactNode): ReactNode => {
|
|
163
|
+
const nodes = Children.toArray(own).filter((node) => node !== "")
|
|
164
|
+
return nodes.flatMap<ReactNode>((node, i) => {
|
|
165
|
+
if (!isText(node)) return [node]
|
|
166
|
+
// Only the first node of a run renders it; the rest are already inside.
|
|
167
|
+
if (i > 0 && isText(nodes[i - 1])) return []
|
|
168
|
+
const end = nodes.findIndex((next, j) => j > i && !isText(next))
|
|
169
|
+
return [
|
|
170
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: a text run has no identity but its position
|
|
171
|
+
<span key={`text-${i}`} className="text-trim">
|
|
172
|
+
{nodes.slice(i, end === -1 ? undefined : end)}
|
|
173
|
+
</span>,
|
|
174
|
+
]
|
|
175
|
+
})
|
|
176
|
+
}
|
|
177
|
+
|
|
130
178
|
export const Badge = ({
|
|
131
179
|
className,
|
|
132
180
|
variant,
|
|
@@ -135,6 +183,8 @@ export const Badge = ({
|
|
|
135
183
|
gradient,
|
|
136
184
|
style,
|
|
137
185
|
testId,
|
|
186
|
+
asChild,
|
|
187
|
+
children,
|
|
138
188
|
...rest
|
|
139
189
|
}: BadgeProps) => {
|
|
140
190
|
const isGradient = variant === "gradient"
|
|
@@ -149,7 +199,10 @@ export const Badge = ({
|
|
|
149
199
|
className,
|
|
150
200
|
)}
|
|
151
201
|
{...props({ "data-testid": testId })}
|
|
202
|
+
asChild={asChild}
|
|
152
203
|
{...rest}
|
|
153
|
-
|
|
204
|
+
>
|
|
205
|
+
{composeChildren(asChild, children, trimTextRuns)}
|
|
206
|
+
</ark.span>
|
|
154
207
|
)
|
|
155
208
|
}
|
|
@@ -135,12 +135,48 @@ describe("Button", () => {
|
|
|
135
135
|
expect(onLinkClick).not.toHaveBeenCalled()
|
|
136
136
|
})
|
|
137
137
|
|
|
138
|
-
it("keeps full contrast while loading, scoping the :disabled
|
|
138
|
+
it("keeps full contrast while loading, scoping the :disabled tints to a plain disabled", () => {
|
|
139
139
|
render(<Button loading>Saving</Button>)
|
|
140
140
|
const loading = screen.getByRole("button", { name: "Saving" })
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
141
|
+
const classes = [...loading.classList]
|
|
142
|
+
expect(classes.some((c) => c.includes("opacity-50"))).toBe(false)
|
|
143
|
+
// Every :disabled colour is gated off while loading, which also sets native disabled.
|
|
144
|
+
const disabledColours = classes.filter(
|
|
145
|
+
(c) => c.startsWith("disabled:") && c.includes("(--btn-"),
|
|
146
|
+
)
|
|
147
|
+
expect(disabledColours.length).toBeGreaterThan(0)
|
|
148
|
+
expect(disabledColours.every((c) => c.startsWith("disabled:not-data-loading:"))).toBe(true)
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
it("keys the disabled tints off data-disabled too, for an asChild element", () => {
|
|
152
|
+
render(<Button disabled>Off</Button>)
|
|
153
|
+
expect([...screen.getByRole("button", { name: "Off" }).classList]).toContain(
|
|
154
|
+
"data-disabled:bg-(--btn-disabled-bg)",
|
|
155
|
+
)
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
it("renders the link variant as bare underlined text, without the size box", () => {
|
|
159
|
+
render(
|
|
160
|
+
<Button variant="link" size="lg" startSlot={<span data-testid="icon" />}>
|
|
161
|
+
Read more
|
|
162
|
+
</Button>,
|
|
163
|
+
)
|
|
164
|
+
const link = screen.getByRole("button", { name: "Read more" })
|
|
165
|
+
const classes = [...link.classList]
|
|
166
|
+
expect(link.getAttribute("data-variant")).toBe("link")
|
|
167
|
+
expect(classes).toEqual(
|
|
168
|
+
expect.arrayContaining(["h-auto", "px-0", "underline", "text-(--btn-link-text)"]),
|
|
169
|
+
)
|
|
170
|
+
expect(classes).not.toContain("h-10")
|
|
171
|
+
expect(classes).not.toContain("no-underline")
|
|
172
|
+
// The slot's negative margin would pull the icon outside the unpadded box.
|
|
173
|
+
expect(screen.getByTestId("icon").parentElement?.className).toContain("ms-0")
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
it("sizes its icons through a zero-specificity rule, so a class on the icon wins", () => {
|
|
177
|
+
render(<Button size="lg">Go</Button>)
|
|
178
|
+
const classes = [...screen.getByRole("button", { name: "Go" }).classList]
|
|
179
|
+
expect(classes).toContain("[:where(&)_svg]:size-5")
|
|
180
|
+
expect(classes.some((c) => c.startsWith("[&_svg]"))).toBe(false)
|
|
145
181
|
})
|
|
146
182
|
})
|
|
@@ -4,6 +4,7 @@ import { ark, type HTMLArkProps } from "@ark-ui/react"
|
|
|
4
4
|
import { cva, type VariantProps } from "class-variance-authority"
|
|
5
5
|
import type { MouseEvent, ReactNode } from "react"
|
|
6
6
|
import { withAsChildContent } from "../../lib/as-child"
|
|
7
|
+
import { buttonColorVariants } from "../../lib/button-colors"
|
|
7
8
|
import { cn } from "../../lib/cn"
|
|
8
9
|
import type { Color } from "../../lib/colors"
|
|
9
10
|
import { focusStyles } from "../../lib/focus-styles"
|
|
@@ -15,13 +16,15 @@ import { Spinner } from "../spinner/spinner"
|
|
|
15
16
|
* Button — interactive but stateless primitive.
|
|
16
17
|
*
|
|
17
18
|
* The new (variant × color) model splits visual treatment from accent palette:
|
|
18
|
-
* - `variant` picks the shape (filled / light / outline / subtle)
|
|
19
|
-
* - `color` picks the palette (brand /
|
|
19
|
+
* - `variant` picks the shape (filled / light / outline / subtle / link)
|
|
20
|
+
* - `color` picks the palette (brand / neutral / red / orange / …)
|
|
20
21
|
*
|
|
21
22
|
* Color is delivered through CSS variables: the component writes a
|
|
22
23
|
* `data-color="…"` attribute and the global rules in `colors.css` resolve
|
|
23
|
-
*
|
|
24
|
-
* the cva matrix only enumerates variants, not
|
|
24
|
+
* the button-only `--btn-*` slots (copied from the Figma Button set) for
|
|
25
|
+
* both light and dark mode. So the cva matrix only enumerates variants, not
|
|
26
|
+
* (variant × color) pairs; the per-variant classes live in
|
|
27
|
+
* `lib/button-colors.ts`, shared with ActionIcon.
|
|
25
28
|
* When `color` is omitted, no `data-color` attribute is rendered and the
|
|
26
29
|
* slot vars cascade from `:root` — which mirrors `neutral` — so the
|
|
27
30
|
* zero-config `<Button>` renders `filled` · `neutral`. Consumers retheme the
|
|
@@ -53,10 +56,10 @@ import { Spinner } from "../spinner/spinner"
|
|
|
53
56
|
* spinner at all. Under `motion-reduce` the swap is instant; the spinner
|
|
54
57
|
* itself still turns.
|
|
55
58
|
*
|
|
56
|
-
* A loading button keeps full contrast —
|
|
57
|
-
* `disabled`. `disabled` alone
|
|
58
|
-
* `:disabled`
|
|
59
|
-
* `loading` too).
|
|
59
|
+
* A loading button keeps full contrast — muting it would read as
|
|
60
|
+
* `disabled`. `disabled` alone switches to the palette's disabled tints
|
|
61
|
+
* (`not-data-loading:` scopes the `:disabled` colours off, since
|
|
62
|
+
* `resolvedDisabled` sets native `disabled` for `loading` too).
|
|
60
63
|
*
|
|
61
64
|
* `loading` doesn't use `pointer-events-none` to block interaction — that
|
|
62
65
|
* also blocks `:hover`, which would make `cursor-progress` unreachable by a
|
|
@@ -77,37 +80,29 @@ const buttonVariants = cva(
|
|
|
77
80
|
"rounded-button border border-transparent",
|
|
78
81
|
"transition-colors-radius",
|
|
79
82
|
focusStyles(),
|
|
80
|
-
"disabled:not-data-loading:pointer-events-none disabled:
|
|
81
|
-
"data-disabled:pointer-events-none data-disabled:opacity-50",
|
|
83
|
+
"disabled:not-data-loading:pointer-events-none data-disabled:pointer-events-none",
|
|
82
84
|
"not-data-loading:hover:cursor-pointer",
|
|
83
85
|
"data-loading:cursor-progress",
|
|
84
|
-
|
|
86
|
+
// Every svg rule is `[:where(&)_svg]`: zero class specificity, so a size
|
|
87
|
+
// class on the icon itself (`<Star className="size-5" />`) or a nested
|
|
88
|
+
// component's own svg rule wins whatever the CSS order. Lucide's `size`
|
|
89
|
+
// prop is only an HTML attribute and still loses. Same fix as Input (#427).
|
|
90
|
+
"[:where(&)_svg]:shrink-0 [:where(&)_svg]:pointer-events-none",
|
|
85
91
|
],
|
|
86
92
|
{
|
|
87
93
|
variants: {
|
|
88
|
-
variant:
|
|
89
|
-
filled: [
|
|
90
|
-
"bg-(--c-solid) text-(--c-on-solid)",
|
|
91
|
-
"not-data-loading:hover:bg-(--c-solid-hover)",
|
|
92
|
-
],
|
|
93
|
-
light: [
|
|
94
|
-
"bg-(--c-soft) text-(--c-text) border-(--c-soft-hover)",
|
|
95
|
-
"not-data-loading:hover:bg-(--c-soft-hover) not-data-loading:hover:border-(--c-solid)",
|
|
96
|
-
],
|
|
97
|
-
outline: [
|
|
98
|
-
"bg-transparent text-(--c-text) border-(--c-solid)/35",
|
|
99
|
-
"not-data-loading:hover:bg-(--c-soft)",
|
|
100
|
-
],
|
|
101
|
-
subtle: ["bg-transparent text-(--c-text)", "not-data-loading:hover:bg-(--c-soft)"],
|
|
102
|
-
},
|
|
94
|
+
variant: buttonColorVariants,
|
|
103
95
|
size: {
|
|
104
|
-
xs: "h-7 px-2 text-xs [&_svg]:size-3 gap-1",
|
|
105
|
-
sm: "h-8 px-3 text-sm [&_svg]:size-3.5 gap-1.5",
|
|
106
|
-
md: "h-9 px-4 text-md [&_svg]:size-4 gap-2",
|
|
107
|
-
lg: "h-10 px-4 text-lg [&_svg]:size-5 gap-3",
|
|
108
|
-
xl: "h-12 px-5 text-xl [&_svg]:size-6 gap-3",
|
|
96
|
+
xs: "h-7 px-2 text-xs [:where(&)_svg]:size-3 gap-1",
|
|
97
|
+
sm: "h-8 px-3 text-sm [:where(&)_svg]:size-3.5 gap-1.5",
|
|
98
|
+
md: "h-9 px-4 text-md [:where(&)_svg]:size-4 gap-2",
|
|
99
|
+
lg: "h-10 px-4 text-lg [:where(&)_svg]:size-5 gap-3",
|
|
100
|
+
xl: "h-12 px-5 text-xl [:where(&)_svg]:size-6 gap-3",
|
|
109
101
|
},
|
|
110
102
|
},
|
|
103
|
+
// Figma's link is bare text: no box, no padding, no fixed height. A
|
|
104
|
+
// compound variant so it lands after (and wins over) the size classes.
|
|
105
|
+
compoundVariants: [{ variant: "link", class: "h-auto px-0 rounded-none border-0" }],
|
|
111
106
|
defaultVariants: {
|
|
112
107
|
variant: "filled",
|
|
113
108
|
size: "md",
|
|
@@ -271,13 +266,13 @@ export const Button = ({
|
|
|
271
266
|
const content = (own: ReactNode) => (
|
|
272
267
|
<>
|
|
273
268
|
{startSlot && (
|
|
274
|
-
<HiddenSlot className={startSlotVariants({ size })}>
|
|
269
|
+
<HiddenSlot className={cn(startSlotVariants({ size }), variant === "link" && "ms-0")}>
|
|
275
270
|
{morph === "start" ? <LoadingSlot loading={loading}>{startSlot}</LoadingSlot> : startSlot}
|
|
276
271
|
</HiddenSlot>
|
|
277
272
|
)}
|
|
278
273
|
{morph === "label" ? <LoadingLabel loading={loading}>{own}</LoadingLabel> : own}
|
|
279
274
|
{endSlot && (
|
|
280
|
-
<HiddenSlot className={endSlotVariants({ size })}>
|
|
275
|
+
<HiddenSlot className={cn(endSlotVariants({ size }), variant === "link" && "me-0")}>
|
|
281
276
|
{morph === "end" ? <LoadingSlot loading={loading}>{endSlot}</LoadingSlot> : endSlot}
|
|
282
277
|
</HiddenSlot>
|
|
283
278
|
)}
|
|
@@ -8,10 +8,13 @@ import type {
|
|
|
8
8
|
} from "@tanstack/react-table"
|
|
9
9
|
import {
|
|
10
10
|
columnFilteringFeature,
|
|
11
|
+
columnGroupingFeature,
|
|
11
12
|
columnResizingFeature,
|
|
12
13
|
columnSizingFeature,
|
|
13
14
|
columnVisibilityFeature,
|
|
15
|
+
createExpandedRowModel,
|
|
14
16
|
createFilteredRowModel,
|
|
17
|
+
createGroupedRowModel,
|
|
15
18
|
createPaginatedRowModel,
|
|
16
19
|
createSortedRowModel,
|
|
17
20
|
filterFn_arrIncludes,
|
|
@@ -21,6 +24,7 @@ import {
|
|
|
21
24
|
filterFn_inNumberRange,
|
|
22
25
|
filterFn_weakEquals,
|
|
23
26
|
globalFilteringFeature,
|
|
27
|
+
rowExpandingFeature,
|
|
24
28
|
rowPaginationFeature,
|
|
25
29
|
rowSelectionFeature,
|
|
26
30
|
rowSortingFeature,
|
|
@@ -57,11 +61,18 @@ export const dataTableFeatures = tableFeatures({
|
|
|
57
61
|
columnVisibilityFeature,
|
|
58
62
|
columnSizingFeature,
|
|
59
63
|
columnResizingFeature,
|
|
64
|
+
// Row grouping (`grouping`) and its fold state (`expanded`). No
|
|
65
|
+
// `rowAggregationFeature`: a group row draws a header, never cells, so there
|
|
66
|
+
// is nothing to aggregate.
|
|
67
|
+
columnGroupingFeature,
|
|
68
|
+
rowExpandingFeature,
|
|
60
69
|
|
|
61
70
|
// v8's `get*RowModel` options moved into these slots. The core row model is
|
|
62
71
|
// automatic in v9 and must not be passed.
|
|
63
72
|
filteredRowModel: createFilteredRowModel(),
|
|
73
|
+
groupedRowModel: createGroupedRowModel(),
|
|
64
74
|
sortedRowModel: createSortedRowModel(),
|
|
75
|
+
expandedRowModel: createExpandedRowModel(),
|
|
65
76
|
paginatedRowModel: createPaginatedRowModel(),
|
|
66
77
|
|
|
67
78
|
/* These two registries are load-bearing, and their failure mode is silent.
|