@42-central/ui-react 0.24.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-YWTOW7PZ.js → chunk-276RL7FX.js} +10 -10
- package/dist/{chunk-YWTOW7PZ.js.map → chunk-276RL7FX.js.map} +1 -1
- package/dist/{chunk-FUNTJZX7.js → chunk-2CL3FKEY.js} +3 -3
- package/dist/{chunk-FUNTJZX7.js.map → chunk-2CL3FKEY.js.map} +1 -1
- package/dist/{chunk-YPFSRZ3T.js → chunk-2NTCQIRP.js} +5 -5
- package/dist/{chunk-YPFSRZ3T.js.map → chunk-2NTCQIRP.js.map} +1 -1
- package/dist/{chunk-D3JYDAUZ.js → chunk-2TZU4LSX.js} +4 -4
- package/dist/{chunk-D3JYDAUZ.js.map → chunk-2TZU4LSX.js.map} +1 -1
- package/dist/{chunk-DJLNGWMM.js → chunk-6IRMKF5T.js} +3 -3
- package/dist/{chunk-DJLNGWMM.js.map → chunk-6IRMKF5T.js.map} +1 -1
- package/dist/{chunk-DT6LKNZF.js → chunk-7247WBTV.js} +5 -4
- package/dist/chunk-7247WBTV.js.map +1 -0
- package/dist/{chunk-F2FSHVO5.js → chunk-7B44J3CF.js} +7 -7
- package/dist/{chunk-F2FSHVO5.js.map → chunk-7B44J3CF.js.map} +1 -1
- package/dist/{chunk-6VYGK3Q3.js → chunk-7E7JNWOC.js} +16 -21
- package/dist/chunk-7E7JNWOC.js.map +1 -0
- package/dist/{chunk-7AQ4MN4M.js → chunk-7OGZT7U2.js} +14 -6
- package/dist/chunk-7OGZT7U2.js.map +1 -0
- package/dist/{chunk-UAYENYS2.js → chunk-AKXALCUN.js} +3 -3
- package/dist/{chunk-UAYENYS2.js.map → chunk-AKXALCUN.js.map} +1 -1
- package/dist/{chunk-BE2LWUHY.js → chunk-BMEJBY6H.js} +5 -3
- package/dist/chunk-BMEJBY6H.js.map +1 -0
- package/dist/{chunk-DHJB4UJD.js → chunk-DMI4KS32.js} +5 -5
- package/dist/{chunk-DHJB4UJD.js.map → chunk-DMI4KS32.js.map} +1 -1
- package/dist/{chunk-FB2G4LNH.js → chunk-DSZF2TW6.js} +7 -7
- package/dist/{chunk-FB2G4LNH.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-MXAACRWE.js → chunk-E52Z2FKU.js} +5 -5
- package/dist/{chunk-MXAACRWE.js.map → chunk-E52Z2FKU.js.map} +1 -1
- package/dist/chunk-F374BNL4.js +129 -0
- package/dist/chunk-F374BNL4.js.map +1 -0
- package/dist/{chunk-3L5GLI67.js → chunk-I4B3N3UX.js} +3 -3
- package/dist/{chunk-3L5GLI67.js.map → chunk-I4B3N3UX.js.map} +1 -1
- package/dist/{chunk-IPYHTCFL.js → chunk-IUK7OJXZ.js} +3 -3
- package/dist/{chunk-IPYHTCFL.js.map → chunk-IUK7OJXZ.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-MRAJ45IM.js → chunk-JDPVD2YE.js} +5 -5
- package/dist/{chunk-MRAJ45IM.js.map → chunk-JDPVD2YE.js.map} +1 -1
- package/dist/{chunk-SZEOTXRZ.js → chunk-JFB6O7IY.js} +5 -5
- package/dist/{chunk-SZEOTXRZ.js.map → chunk-JFB6O7IY.js.map} +1 -1
- package/dist/{chunk-2MXWEIMD.js → chunk-KKLCHLCZ.js} +12 -11
- package/dist/chunk-KKLCHLCZ.js.map +1 -0
- package/dist/{chunk-6N6J2DOE.js → chunk-LIZWCWED.js} +3 -3
- package/dist/{chunk-6N6J2DOE.js.map → chunk-LIZWCWED.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-JVG5ISPT.js → chunk-N42EFOML.js} +4 -4
- package/dist/{chunk-JVG5ISPT.js.map → chunk-N42EFOML.js.map} +1 -1
- package/dist/{chunk-C4NFRSOR.js → chunk-NF2PBGD3.js} +38 -25
- package/dist/chunk-NF2PBGD3.js.map +1 -0
- package/dist/{chunk-DA4QII2N.js → chunk-NLSJ6T7V.js} +4 -4
- package/dist/{chunk-DA4QII2N.js.map → chunk-NLSJ6T7V.js.map} +1 -1
- package/dist/{chunk-UT3TOV2Q.js → chunk-OVT2KZHY.js} +3 -3
- package/dist/{chunk-UT3TOV2Q.js.map → chunk-OVT2KZHY.js.map} +1 -1
- package/dist/{chunk-MW42XVPD.js → chunk-PBSVX5DB.js} +15 -5
- package/dist/chunk-PBSVX5DB.js.map +1 -0
- package/dist/{chunk-SVKN5ZHX.js → chunk-PEHFWGTT.js} +16 -13
- package/dist/chunk-PEHFWGTT.js.map +1 -0
- package/dist/{chunk-J44FJ7PH.js → chunk-PFZMB3US.js} +4 -4
- package/dist/{chunk-J44FJ7PH.js.map → chunk-PFZMB3US.js.map} +1 -1
- package/dist/{chunk-IRNF274I.js → chunk-PT22KEVD.js} +5 -5
- package/dist/{chunk-IRNF274I.js.map → chunk-PT22KEVD.js.map} +1 -1
- package/dist/{chunk-OZMSXYBX.js → chunk-QEAF57ZQ.js} +4 -4
- package/dist/{chunk-OZMSXYBX.js.map → chunk-QEAF57ZQ.js.map} +1 -1
- package/dist/{chunk-SWVUXEBT.js → chunk-SCXXJDKQ.js} +3 -3
- package/dist/{chunk-SWVUXEBT.js.map → chunk-SCXXJDKQ.js.map} +1 -1
- package/dist/{chunk-E5H3YWZV.js → chunk-SOUDKESO.js} +15 -8
- package/dist/chunk-SOUDKESO.js.map +1 -0
- package/dist/{chunk-4FEOMQYR.js → chunk-THGJLR5S.js} +6 -6
- package/dist/{chunk-4FEOMQYR.js.map → chunk-THGJLR5S.js.map} +1 -1
- package/dist/{chunk-TCFB23JT.js → chunk-WERJ44ZN.js} +3 -3
- package/dist/{chunk-TCFB23JT.js.map → chunk-WERJ44ZN.js.map} +1 -1
- package/dist/{chunk-QNKD2SQM.js → chunk-X3YIHN2U.js} +5 -5
- package/dist/{chunk-QNKD2SQM.js.map → chunk-X3YIHN2U.js.map} +1 -1
- package/dist/{chunk-VD6PB3VA.js → chunk-X6DESK37.js} +12 -3
- package/dist/chunk-X6DESK37.js.map +1 -0
- package/dist/{chunk-47LEAR6G.js → chunk-Y2G47ARQ.js} +6 -6
- package/dist/{chunk-47LEAR6G.js.map → chunk-Y2G47ARQ.js.map} +1 -1
- package/dist/{chunk-O7LS6OZR.js → chunk-YMVUQ2L7.js} +4 -4
- package/dist/{chunk-O7LS6OZR.js.map → chunk-YMVUQ2L7.js.map} +1 -1
- package/dist/{chunk-F342ZT7O.js → chunk-ZVECQBGG.js} +13 -7
- package/dist/chunk-ZVECQBGG.js.map +1 -0
- package/dist/components/action-icon/action-icon.d.ts.map +1 -1
- package/dist/components/action-icon/index.js +1 -1
- package/dist/components/alert/index.js +1 -1
- package/dist/components/ambient-background/index.js +14 -26
- 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 +300 -39
- package/dist/components/app-shell/index.js.map +1 -1
- package/dist/components/autocomplete/index.js +5 -5
- 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 +12 -3
- package/dist/components/avatar/index.js.map +1 -1
- package/dist/components/badge/badge.d.ts.map +1 -1
- package/dist/components/badge/index.js +1 -1
- package/dist/components/button/index.js +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 +4 -4
- 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 +4 -4
- package/dist/components/calendar/index.js +4 -4
- package/dist/components/calendar-heatmap/index.js +2 -2
- package/dist/components/camera/index.js +12 -12
- package/dist/components/card/card.d.ts.map +1 -1
- package/dist/components/card/index.js +1 -1
- package/dist/components/carousel/index.js +2 -2
- package/dist/components/checkbox/checkbox.d.ts +3 -2
- package/dist/components/checkbox/checkbox.d.ts.map +1 -1
- package/dist/components/checkbox/index.js +2 -2
- package/dist/components/choice-card-group/index.js +2 -2
- package/dist/components/choice-card-group/index.js.map +1 -1
- package/dist/components/clipboard/index.js +3 -3
- package/dist/components/code-block/chrome.js +3 -3
- package/dist/components/code-block/code-block.d.ts +6 -3
- package/dist/components/code-block/code-block.d.ts.map +1 -1
- package/dist/components/code-block/highlighter.d.ts +16 -15
- package/dist/components/code-block/highlighter.d.ts.map +1 -1
- package/dist/components/code-block/index.d.ts +2 -1
- package/dist/components/code-block/index.d.ts.map +1 -1
- package/dist/components/code-block/index.js +85 -14
- package/dist/components/code-block/index.js.map +1 -1
- package/dist/components/code-block/languages.d.ts +61 -0
- package/dist/components/code-block/languages.d.ts.map +1 -0
- package/dist/components/code-block/static.d.ts +2 -1
- package/dist/components/code-block/static.d.ts.map +1 -1
- package/dist/components/code-block/static.js +99 -10
- package/dist/components/code-block/static.js.map +1 -1
- package/dist/components/combobox/index.js +5 -5
- package/dist/components/combobox-list/index.js +7 -7
- package/dist/components/compare/index.js +2 -2
- package/dist/components/data-table/index.js +32 -32
- package/dist/components/data-table/index.js.map +1 -1
- package/dist/components/date-picker/index.js +14 -14
- package/dist/components/download-button/index.js +2 -2
- package/dist/components/drawer/index.js +5 -5
- package/dist/components/field/field.d.ts +3 -0
- package/dist/components/field/field.d.ts.map +1 -1
- package/dist/components/field/index.js +1 -1
- package/dist/components/file-item/index.js +5 -5
- package/dist/components/file-preview/index.js +5 -5
- package/dist/components/file-trigger/index.js +2 -2
- package/dist/components/file-upload/index.js +6 -6
- package/dist/components/gallery/index.js +2 -2
- 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/image-cropper/index.js +7 -7
- package/dist/components/indicator/index.js +24 -9
- 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/input/index.js +2 -2
- package/dist/components/kbd/index.js +3 -3
- package/dist/components/kbd/kbd.d.ts.map +1 -1
- package/dist/components/lightbox/index.js +8 -8
- package/dist/components/menu/index.js +4 -4
- package/dist/components/modal/index.js +5 -5
- package/dist/components/multi-combobox-list/index.js +7 -7
- package/dist/components/multi-select/index.js +8 -8
- 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 +5 -5
- package/dist/components/overlays/index.js +7 -7
- package/dist/components/password-input/index.js +3 -3
- package/dist/components/photo-capture/index.js +16 -16
- package/dist/components/pills-input/index.js +5 -5
- package/dist/components/pin-input/index.js +2 -2
- package/dist/components/popover/index.js +2 -2
- package/dist/components/radio-group/index.js +1 -1
- package/dist/components/rating/index.js +1 -1
- package/dist/components/schedule/index.js +7 -7
- package/dist/components/segment-group/index.js +4 -4
- 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 +6 -6
- package/dist/components/slider/index.js +2 -2
- package/dist/components/spotlight/index.js +11 -11
- package/dist/components/switch/index.js +14 -19
- package/dist/components/switch/index.js.map +1 -1
- package/dist/components/switch/switch.d.ts +1 -0
- package/dist/components/switch/switch.d.ts.map +1 -1
- package/dist/components/table/index.js +1 -1
- package/dist/components/table/table.d.ts.map +1 -1
- package/dist/components/tabs/index.js +3 -3
- 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 +7 -7
- package/dist/components/text-input/index.js +2 -2
- package/dist/components/textarea/index.js +2 -2
- 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 +9 -9
- package/dist/components/tree-multi-select/index.js +8 -8
- package/dist/components/tree-select/index.js +5 -5
- package/dist/index.js +4 -4
- package/dist/lib/sidebar-rail.d.ts +21 -0
- package/dist/lib/sidebar-rail.d.ts.map +1 -0
- package/dist/theme.css +35 -35
- package/package.json +1 -1
- package/src/as-child.contract.test.tsx +6 -0
- package/src/components/action-icon/action-icon.tsx +3 -1
- package/src/components/ambient-background/starfield.tsx +18 -43
- 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/badge/badge.tsx +11 -6
- package/src/components/button/button.tsx +1 -1
- 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/card/card.tsx +10 -9
- package/src/components/checkbox/checkbox.test.tsx +17 -9
- package/src/components/checkbox/checkbox.tsx +26 -27
- package/src/components/choice-card-group/choice-card-group.tsx +3 -3
- package/src/components/code-block/code-block.tsx +7 -4
- package/src/components/code-block/highlighter.test.ts +79 -1
- package/src/components/code-block/highlighter.ts +76 -30
- package/src/components/code-block/index.ts +2 -0
- package/src/components/code-block/languages.ts +63 -0
- package/src/components/code-block/static.tsx +2 -1
- package/src/components/data-table/data-table-pagination.tsx +5 -5
- package/src/components/data-table/data-table-stack.tsx +2 -2
- package/src/components/field/field.tsx +14 -0
- 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/kbd/kbd.tsx +2 -1
- 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/switch/switch.test.tsx +15 -0
- package/src/components/switch/switch.tsx +27 -27
- package/src/components/table/table.test.tsx +1 -1
- package/src/components/table/table.tsx +14 -11
- 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/components/theme-icon/theme-icon.tsx +46 -12
- package/src/lib/sidebar-rail.ts +24 -0
- package/src/theme.css +35 -35
- package/src/theme.test.ts +0 -1
- package/dist/chunk-2MXWEIMD.js.map +0 -1
- package/dist/chunk-6VYGK3Q3.js.map +0 -1
- package/dist/chunk-7AQ4MN4M.js.map +0 -1
- package/dist/chunk-7CNDZZZ6.js +0 -95
- package/dist/chunk-7CNDZZZ6.js.map +0 -1
- package/dist/chunk-BE2LWUHY.js.map +0 -1
- package/dist/chunk-C4NFRSOR.js.map +0 -1
- package/dist/chunk-DT6LKNZF.js.map +0 -1
- package/dist/chunk-E5H3YWZV.js.map +0 -1
- package/dist/chunk-F342ZT7O.js.map +0 -1
- package/dist/chunk-HRNWWL3Y.js.map +0 -1
- package/dist/chunk-MW42XVPD.js.map +0 -1
- package/dist/chunk-SVKN5ZHX.js.map +0 -1
- package/dist/chunk-VD6PB3VA.js.map +0 -1
|
@@ -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
|
})
|
|
@@ -83,12 +83,16 @@ const indicatorVariants = cva(
|
|
|
83
83
|
// the "positioned, stack-level 0" step, which paints after `children`'s
|
|
84
84
|
// step — now the dot (and, tucked behind just its own box, the pulse) is
|
|
85
85
|
// the thing establishing the context, so it's it that ends up on top.
|
|
86
|
-
"
|
|
86
|
+
"z-0 inline-flex items-center justify-center",
|
|
87
87
|
"font-sans font-medium leading-none whitespace-nowrap select-none",
|
|
88
88
|
"bg-(--c-solid) text-(--c-on-solid)",
|
|
89
89
|
],
|
|
90
90
|
{
|
|
91
91
|
variants: {
|
|
92
|
+
// Overlaid on `children`, or standing in the flow when there are none.
|
|
93
|
+
// `relative` keeps the dot a positioned box either way, so `z-0` still
|
|
94
|
+
// makes it the stacking context the `processing` pulse relies on.
|
|
95
|
+
placement: { overlay: "absolute", standalone: "relative shrink-0" },
|
|
92
96
|
shape: { dot: "rounded-full", label: "" },
|
|
93
97
|
size: { xs: "", sm: "", md: "", lg: "", xl: "" },
|
|
94
98
|
radius: { xs: "", sm: "", md: "", lg: "", xl: "" },
|
|
@@ -110,15 +114,15 @@ const indicatorVariants = cva(
|
|
|
110
114
|
{ shape: "label", radius: "lg", class: "rounded-lg" },
|
|
111
115
|
{ shape: "label", radius: "xl", class: "rounded-xl" },
|
|
112
116
|
],
|
|
113
|
-
defaultVariants: { shape: "dot", size: "md", radius: "xl" },
|
|
117
|
+
defaultVariants: { placement: "overlay", shape: "dot", size: "md", radius: "xl" },
|
|
114
118
|
},
|
|
115
119
|
)
|
|
116
120
|
|
|
117
121
|
export type IndicatorProps = Omit<ComponentPropsWithoutRef<"div">, "children"> &
|
|
118
122
|
WithTestId & {
|
|
119
|
-
/** Which corner (or edge midpoint) of `children` the dot anchors to, straddling it. Default `"top-end"`. */
|
|
123
|
+
/** Which corner (or edge midpoint) of `children` the dot anchors to, straddling it. Default `"top-end"`. Ignored without `children`. */
|
|
120
124
|
position?: IndicatorPosition
|
|
121
|
-
/** Extra px nudge away from the anchor point — a single number for both axes, or `{ x, y }` independently. Ignored on whichever axis a position has no directional edge for (the `center`/`middle` axis of that position)
|
|
125
|
+
/** Extra px nudge away from the anchor point — a single number for both axes, or `{ x, y }` independently. Ignored on whichever axis a position has no directional edge for (the `center`/`middle` axis of that position), and without `children`. */
|
|
122
126
|
offset?: IndicatorOffset
|
|
123
127
|
/** Dot diameter (no `label`) or badge height, off the kit's shared `xs`–`xl` scale. Default `"md"`. */
|
|
124
128
|
size?: Size
|
|
@@ -146,12 +150,12 @@ export type IndicatorProps = Omit<ComponentPropsWithoutRef<"div">, "children"> &
|
|
|
146
150
|
withBorder?: boolean
|
|
147
151
|
/** Corner rounding of the label badge shape once `label` is set — irrelevant to the bare dot, which is always a circle. Default `"xl"`. */
|
|
148
152
|
radius?: Size
|
|
149
|
-
/** Root renders as a `<span>` with `display: inline-block` instead of the default `<div>`/`block` — for wrapping a run of inline content (a word, an icon) that shouldn't force its own line. The tag itself has to change, not just the display: a `<div>` is flow content and is never valid inside phrasing content (e.g. a `<p>`), regardless of its CSS display. Both modes shrink-wrap to `children`'s own intrinsic size either way (the default adds `width: fit-content` — a plain `display: block` box would otherwise stretch to its container's full width, dragging the corner dot away from a small child like an `Avatar` whenever the parent isn't already a flex/grid context). */
|
|
153
|
+
/** Root renders as a `<span>` with `display: inline-block` instead of the default `<div>`/`block` — for wrapping a run of inline content (a word, an icon) that shouldn't force its own line. Without `children` the root is always an inline `<span>`. The tag itself has to change, not just the display: a `<div>` is flow content and is never valid inside phrasing content (e.g. a `<p>`), regardless of its CSS display. Both modes shrink-wrap to `children`'s own intrinsic size either way (the default adds `width: fit-content` — a plain `display: block` box would otherwise stretch to its container's full width, dragging the corner dot away from a small child like an `Avatar` whenever the parent isn't already a flex/grid context). */
|
|
150
154
|
inline?: boolean
|
|
151
155
|
/** Stacking order of the dot/badge overlay. */
|
|
152
156
|
zIndex?: number
|
|
153
|
-
/** The element being decorated.
|
|
154
|
-
children
|
|
157
|
+
/** The element being decorated. Omit it for a standalone dot (or badge) that sits in the flow — a status dot before a word, a count beside a label — with `position`/`offset` ignored. */
|
|
158
|
+
children?: ReactNode
|
|
155
159
|
}
|
|
156
160
|
|
|
157
161
|
/** `offset`'s x/y split, defaulting each axis to 0. */
|
|
@@ -199,6 +203,10 @@ const buildOffsetStyle = (
|
|
|
199
203
|
* on its own, so `alt` supplies the words ("3 unread messages") as visually
|
|
200
204
|
* hidden text instead.
|
|
201
205
|
*
|
|
206
|
+
* Without `children` it's a standalone dot in the flow, for a status before a
|
|
207
|
+
* word. The dot still says nothing on its own: pair it with visible text, or
|
|
208
|
+
* give it an `alt`.
|
|
209
|
+
*
|
|
202
210
|
* No `asChild` — same reasoning as `Skeleton`: the root must stay a real
|
|
203
211
|
* wrapping element around *two* things at once (`children` **and** the
|
|
204
212
|
* absolutely-positioned dot sibling), which is structurally incompatible
|
|
@@ -212,6 +220,11 @@ const buildOffsetStyle = (
|
|
|
212
220
|
* <Indicator processing color="green" position="bottom-end">
|
|
213
221
|
* <ActionIcon><Wifi /></ActionIcon>
|
|
214
222
|
* </Indicator>
|
|
223
|
+
*
|
|
224
|
+
* <span className="inline-flex items-center gap-1.5">
|
|
225
|
+
* <Indicator size="sm" color="pink" />
|
|
226
|
+
* Registered
|
|
227
|
+
* </span>
|
|
215
228
|
*/
|
|
216
229
|
export const Indicator = ({
|
|
217
230
|
className,
|
|
@@ -254,11 +267,20 @@ export const Indicator = ({
|
|
|
254
267
|
// prop's own doc below), so the root tag switches to <span> too — the only
|
|
255
268
|
// way `inline` actually delivers on wrapping a run of inline text without
|
|
256
269
|
// the browser closing the paragraph around it.
|
|
257
|
-
const
|
|
270
|
+
const standalone = children == null
|
|
271
|
+
const Root = inline || standalone ? "span" : "div"
|
|
272
|
+
|
|
273
|
+
// Nothing to decorate and nothing to show: render nothing rather than an
|
|
274
|
+
// empty box that still takes a gap in its parent's flex row.
|
|
275
|
+
if (standalone && !visible) return null
|
|
258
276
|
|
|
259
277
|
return (
|
|
260
278
|
<Root
|
|
261
|
-
className={cn(
|
|
279
|
+
className={cn(
|
|
280
|
+
"relative",
|
|
281
|
+
standalone ? "inline-flex shrink-0 align-middle" : inline ? "inline-block" : "block w-fit",
|
|
282
|
+
className,
|
|
283
|
+
)}
|
|
262
284
|
style={style}
|
|
263
285
|
{...dataProps({ "data-testid": testId })}
|
|
264
286
|
{...rest}
|
|
@@ -273,15 +295,20 @@ export const Indicator = ({
|
|
|
273
295
|
<span
|
|
274
296
|
aria-hidden="true"
|
|
275
297
|
data-part="indicator"
|
|
276
|
-
data-position={position}
|
|
298
|
+
data-position={standalone ? undefined : position}
|
|
277
299
|
data-color={color}
|
|
278
300
|
className={cn(
|
|
279
|
-
indicatorVariants({
|
|
280
|
-
|
|
301
|
+
indicatorVariants({
|
|
302
|
+
placement: standalone ? "standalone" : "overlay",
|
|
303
|
+
shape: hasLabel ? "label" : "dot",
|
|
304
|
+
size,
|
|
305
|
+
radius,
|
|
306
|
+
}),
|
|
307
|
+
!standalone && POSITION_CLASS[position],
|
|
281
308
|
withBorder && "border-2 border-(--indicator-border-color)",
|
|
282
309
|
)}
|
|
283
310
|
style={{
|
|
284
|
-
...buildOffsetStyle(position, offset),
|
|
311
|
+
...(standalone ? null : buildOffsetStyle(position, offset)),
|
|
285
312
|
...(zIndex !== undefined ? { zIndex } : null),
|
|
286
313
|
}}
|
|
287
314
|
>
|
|
@@ -76,7 +76,8 @@ const kbdVariants = cva(
|
|
|
76
76
|
variant: {
|
|
77
77
|
filled: "bg-(--c-solid) text-(--c-on-solid)",
|
|
78
78
|
light: "bg-(--c-soft) text-(--c-text)",
|
|
79
|
-
outline:
|
|
79
|
+
// Button's outline edge: the colour at 35%.
|
|
80
|
+
outline: "bg-transparent text-(--c-text) border-(--c-solid)/35",
|
|
80
81
|
subtle: "bg-transparent text-(--c-text)",
|
|
81
82
|
// The key cap sits on the kit's translucent surface recipe — a 3%/4%
|
|
82
83
|
// overlay plus the hairline `border-brand-900/20 dark:border-white/15`,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { fireEvent, render, screen } from "@testing-library/react"
|
|
1
|
+
import { fireEvent, render, screen, waitFor } from "@testing-library/react"
|
|
2
2
|
import type { ReactNode } from "react"
|
|
3
3
|
import { describe, expect, it, vi } from "vitest"
|
|
4
4
|
import { LinkComponentProvider } from "../../lib/link-component"
|
|
5
|
+
import { SidebarRailContext } from "../../lib/sidebar-rail"
|
|
5
6
|
import { NavLink } from "./nav-link"
|
|
6
7
|
|
|
7
8
|
const StubLink = ({
|
|
@@ -164,3 +165,122 @@ describe("NavLink translations", () => {
|
|
|
164
165
|
)
|
|
165
166
|
})
|
|
166
167
|
})
|
|
168
|
+
|
|
169
|
+
describe("NavLink in a sidebar icon rail", () => {
|
|
170
|
+
const Row = () => (
|
|
171
|
+
<NavLink
|
|
172
|
+
label="Dashboard"
|
|
173
|
+
startSlot={<svg data-icon />}
|
|
174
|
+
endSlot={<b>3</b>}
|
|
175
|
+
linkOptions={{ href: "/d" }}
|
|
176
|
+
>
|
|
177
|
+
<NavLink label="Child" linkOptions={{ href: "/c" }} />
|
|
178
|
+
</NavLink>
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
it("renders no tooltip machinery outside a rail-capable sidebar", () => {
|
|
182
|
+
render(<Row />)
|
|
183
|
+
// endSlot's text ("3") is part of the row's name.
|
|
184
|
+
const link = screen.getByRole("link", { name: /^Dashboard/ })
|
|
185
|
+
expect(link.getAttribute("data-scope")).toBeNull()
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
it("keeps the label as the accessible name, hides the rest behind the rail variant", () => {
|
|
189
|
+
render(
|
|
190
|
+
<SidebarRailContext.Provider value={{ active: true }}>
|
|
191
|
+
<Row />
|
|
192
|
+
</SidebarRailContext.Provider>,
|
|
193
|
+
)
|
|
194
|
+
const link = screen.getByRole("link", { name: /^Dashboard/ })
|
|
195
|
+
expect(link.getAttribute("data-scope")).toBe("tooltip")
|
|
196
|
+
expect(screen.getByText("Dashboard").className).toContain("sidebar-rail:sr-only")
|
|
197
|
+
expect(screen.getByText("3").parentElement?.className).toContain("sidebar-rail:hidden")
|
|
198
|
+
expect(screen.getByRole("button", { name: "Expand" }).className).toContain(
|
|
199
|
+
"sidebar-rail:hidden",
|
|
200
|
+
)
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
it("folds nested rows shut on an active rail, keeping the row's own open state", () => {
|
|
204
|
+
const { rerender } = render(
|
|
205
|
+
<SidebarRailContext.Provider value={{ active: true }}>
|
|
206
|
+
<NavLink label="Projects" startSlot={<svg />} linkOptions={{ href: "/p" }} defaultOpen>
|
|
207
|
+
<NavLink label="Libft" linkOptions={{ href: "/p/libft" }} />
|
|
208
|
+
</NavLink>
|
|
209
|
+
</SidebarRailContext.Provider>,
|
|
210
|
+
)
|
|
211
|
+
// Animated shut (grid rows to 0fr) and inert, rather than display: none.
|
|
212
|
+
const folded = screen.getByText("Libft").closest("div.grid") as HTMLElement
|
|
213
|
+
expect(folded.getAttribute("data-state")).toBe("closed")
|
|
214
|
+
expect(folded.className).toContain("grid-rows-[0fr]")
|
|
215
|
+
expect(folded.className).not.toContain("sidebar-rail:hidden")
|
|
216
|
+
// Out of the tab order while folded (jsdom's role queries ignore inert).
|
|
217
|
+
expect(screen.getByRole("link", { name: "Libft" }).closest("[inert]")).not.toBeNull()
|
|
218
|
+
|
|
219
|
+
rerender(
|
|
220
|
+
<SidebarRailContext.Provider value={{ active: false }}>
|
|
221
|
+
<NavLink label="Projects" startSlot={<svg />} linkOptions={{ href: "/p" }} defaultOpen>
|
|
222
|
+
<NavLink label="Libft" linkOptions={{ href: "/p/libft" }} />
|
|
223
|
+
</NavLink>
|
|
224
|
+
</SidebarRailContext.Provider>,
|
|
225
|
+
)
|
|
226
|
+
expect(folded.getAttribute("data-state")).toBe("open")
|
|
227
|
+
expect(screen.getByRole("link", { name: "Libft" }).closest("[inert]")).toBeNull()
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
it("shows the label as a tooltip on focus while the rail is active", async () => {
|
|
231
|
+
render(
|
|
232
|
+
<SidebarRailContext.Provider value={{ active: true }}>
|
|
233
|
+
<NavLink label="Dashboard" startSlot={<svg />} linkOptions={{ href: "/d" }} />
|
|
234
|
+
</SidebarRailContext.Provider>,
|
|
235
|
+
)
|
|
236
|
+
// zag opens a tooltip on *keyboard* focus only: Tab first.
|
|
237
|
+
fireEvent.keyDown(document.body, { key: "Tab" })
|
|
238
|
+
fireEvent.focus(screen.getByRole("link", { name: "Dashboard" }))
|
|
239
|
+
expect((await screen.findByRole("tooltip")).textContent).toBe("Dashboard")
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
it("keeps its expanded geometry on a rail, so icons don't move as it opens", () => {
|
|
243
|
+
render(
|
|
244
|
+
<SidebarRailContext.Provider value={{ active: true }}>
|
|
245
|
+
<NavLink label="Dashboard" startSlot={<svg />} linkOptions={{ href: "/d" }} />
|
|
246
|
+
</SidebarRailContext.Provider>,
|
|
247
|
+
)
|
|
248
|
+
// The rail is sized to the row (see AppShell's RAIL_WIDTH): only the label
|
|
249
|
+
// hides, nothing re-lays out the row itself.
|
|
250
|
+
const row = screen.getByRole("link", { name: "Dashboard" })
|
|
251
|
+
expect(row.className).not.toMatch(/sidebar-rail:(p|px|size|justify)/)
|
|
252
|
+
})
|
|
253
|
+
|
|
254
|
+
it("never lets the start slot shrink, so an icon can't squish in a narrow row", () => {
|
|
255
|
+
render(<NavLink label="Dashboard" startSlot={<svg data-icon />} linkOptions={{ href: "/d" }} />)
|
|
256
|
+
const icon = document.querySelector("[data-icon]") as Element
|
|
257
|
+
expect(icon.parentElement?.className).toContain("shrink-0")
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
it("closes an open tooltip as soon as the rail opens", async () => {
|
|
261
|
+
const Rail = ({ active }: { active: boolean }) => (
|
|
262
|
+
<SidebarRailContext.Provider value={{ active }}>
|
|
263
|
+
<NavLink label="Dashboard" startSlot={<svg />} linkOptions={{ href: "/d" }} />
|
|
264
|
+
</SidebarRailContext.Provider>
|
|
265
|
+
)
|
|
266
|
+
const { rerender } = render(<Rail active />)
|
|
267
|
+
fireEvent.keyDown(document.body, { key: "Tab" })
|
|
268
|
+
fireEvent.focus(screen.getByRole("link", { name: "Dashboard" }))
|
|
269
|
+
expect(await screen.findByRole("tooltip")).toBeTruthy()
|
|
270
|
+
|
|
271
|
+
rerender(<Rail active={false} />)
|
|
272
|
+
await waitFor(() => expect(screen.queryByRole("tooltip")).toBeNull())
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
it("keeps the tooltip off once the labels are back", async () => {
|
|
276
|
+
render(
|
|
277
|
+
<SidebarRailContext.Provider value={{ active: false }}>
|
|
278
|
+
<NavLink label="Dashboard" startSlot={<svg />} linkOptions={{ href: "/d" }} />
|
|
279
|
+
</SidebarRailContext.Provider>,
|
|
280
|
+
)
|
|
281
|
+
fireEvent.keyDown(document.body, { key: "Tab" })
|
|
282
|
+
fireEvent.focus(screen.getByRole("link", { name: "Dashboard" }))
|
|
283
|
+
await new Promise((resolve) => setTimeout(resolve, 50))
|
|
284
|
+
expect(screen.queryByRole("tooltip")).toBeNull()
|
|
285
|
+
})
|
|
286
|
+
})
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
3
|
import { cva } from "class-variance-authority"
|
|
4
|
-
import { type ElementType, type ReactNode, useId } from "react"
|
|
4
|
+
import { type ElementType, type ReactNode, useId, useState } from "react"
|
|
5
5
|
import { cn } from "../../lib/cn"
|
|
6
6
|
import { focusStyles } from "../../lib/focus-styles"
|
|
7
7
|
import { useLinkComponent } from "../../lib/link-component"
|
|
8
8
|
import { props } from "../../lib/props"
|
|
9
|
+
import { useSidebarRail } from "../../lib/sidebar-rail"
|
|
9
10
|
import type { WithTestId } from "../../lib/test-id"
|
|
10
11
|
import { TEXT_COLOR_CLASSES } from "../../lib/typography-size"
|
|
11
12
|
import { useUncontrolled } from "../../lib/use-uncontrolled"
|
|
12
13
|
import { Collapse } from "../collapse/collapse"
|
|
13
14
|
import { ChevronIcon } from "../popover/icons"
|
|
15
|
+
import { Tooltip } from "../tooltip/tooltip"
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
18
|
* NavLink — a single sidebar/nav row: leading `startSlot`, `label`, trailing
|
|
@@ -37,6 +39,12 @@ import { ChevronIcon } from "../popover/icons"
|
|
|
37
39
|
* `linkComponent` — a router's `Link` would put the `href` straight back.
|
|
38
40
|
*
|
|
39
41
|
* <NavLink label="Dashboard" startSlot={<Home />} linkOptions={{ href: "/dashboard" }} />
|
|
42
|
+
* In a sidebar collapsed to an icon rail (`AppShell.Sidebar collapse="icons"`)
|
|
43
|
+
* the row shows `startSlot` alone: the label stays as the accessible name
|
|
44
|
+
* (visually hidden) and shows as a tooltip on hover and focus; `endSlot` and
|
|
45
|
+
* the chevron are hidden, and nested children fold shut (animated, and inert)
|
|
46
|
+
* until the sidebar is expanded or peeking. Give such rows a `startSlot` — a rail row without one is empty.
|
|
47
|
+
*
|
|
40
48
|
* <NavLink label="Settings" startSlot={<Settings />} defaultOpen>
|
|
41
49
|
* <NavLink label="Profile" linkOptions={{ href: "/settings/profile" }} />
|
|
42
50
|
* <NavLink label="Security" linkOptions={{ href: "/settings/security" }} />
|
|
@@ -46,6 +54,10 @@ import { ChevronIcon } from "../popover/icons"
|
|
|
46
54
|
const navLinkRow = cva(
|
|
47
55
|
[
|
|
48
56
|
"flex min-w-0 flex-1 cursor-pointer items-center gap-2 rounded-md px-2.5 py-2 text-start text-sm",
|
|
57
|
+
// The row's expanded height, held on an icon rail too, where the label is
|
|
58
|
+
// visually hidden and would otherwise take its line height with it — the
|
|
59
|
+
// rows would grow 4px each as the rail opens.
|
|
60
|
+
"min-h-9",
|
|
49
61
|
"outline-none transition-colors",
|
|
50
62
|
"hover:bg-black/5 dark:hover:bg-white/8",
|
|
51
63
|
focusStyles(),
|
|
@@ -63,7 +75,7 @@ const navLinkRow = cva(
|
|
|
63
75
|
)
|
|
64
76
|
|
|
65
77
|
const chevronButton = cn(
|
|
66
|
-
"flex shrink-0 cursor-pointer items-center justify-center rounded-md p-2 text-black/50 transition-colors",
|
|
78
|
+
"flex shrink-0 sidebar-rail:hidden cursor-pointer items-center justify-center rounded-md p-2 text-black/50 transition-colors",
|
|
67
79
|
"hover:bg-black/5 dark:text-white/50 dark:hover:bg-white/8",
|
|
68
80
|
focusStyles(),
|
|
69
81
|
)
|
|
@@ -72,7 +84,7 @@ const chevron = (open: boolean) => (
|
|
|
72
84
|
<span
|
|
73
85
|
aria-hidden="true"
|
|
74
86
|
data-state={open ? "open" : "closed"}
|
|
75
|
-
className="ms-auto flex shrink-0 transition-transform data-[state=open]:rotate-180 [&_svg]:size-4"
|
|
87
|
+
className="ms-auto flex shrink-0 transition-transform sidebar-rail:hidden data-[state=open]:rotate-180 [&_svg]:size-4"
|
|
76
88
|
>
|
|
77
89
|
<ChevronIcon />
|
|
78
90
|
</span>
|
|
@@ -152,12 +164,20 @@ function NavLinkImpl({
|
|
|
152
164
|
const isLink = linkOptions != null
|
|
153
165
|
const Comp = useLinkComponent(linkComponent) ?? "a"
|
|
154
166
|
const itemsId = `nav-link-items-${useId()}`
|
|
167
|
+
const rail = useSidebarRail()
|
|
168
|
+
// Controlled, so the bubble closes the moment the rail opens: Ark's
|
|
169
|
+
// `disabled` only stops a closed tooltip from opening, it doesn't shut one.
|
|
170
|
+
const [tipOpen, setTipOpen] = useState(false)
|
|
155
171
|
|
|
156
172
|
const content = (
|
|
157
173
|
<>
|
|
158
|
-
{
|
|
159
|
-
|
|
160
|
-
|
|
174
|
+
{/* Never shrinks: only the label gives way when the row is narrow. A
|
|
175
|
+
bare SVG icon is a flex item that would otherwise squeeze — and scale
|
|
176
|
+
its drawing down — as an icon rail widens with the label already
|
|
177
|
+
showing, visibly squishing the icon for a frame or two. */}
|
|
178
|
+
{startSlot != null && <span className="flex shrink-0">{startSlot}</span>}
|
|
179
|
+
<span className="min-w-0 flex-1 truncate sidebar-rail:sr-only">{label}</span>
|
|
180
|
+
{endSlot != null && <span className="contents sidebar-rail:hidden">{endSlot}</span>}
|
|
161
181
|
</>
|
|
162
182
|
)
|
|
163
183
|
|
|
@@ -168,32 +188,56 @@ function NavLinkImpl({
|
|
|
168
188
|
"data-testid": testId,
|
|
169
189
|
})
|
|
170
190
|
|
|
191
|
+
const row =
|
|
192
|
+
isLink && disabled ? (
|
|
193
|
+
// No `href`, so no tab stop and nothing for Enter to follow; the
|
|
194
|
+
// explicit role keeps it announced as a (disabled) link.
|
|
195
|
+
<a role="link" {...rowState} className={rowClassName}>
|
|
196
|
+
{content}
|
|
197
|
+
</a>
|
|
198
|
+
) : isLink ? (
|
|
199
|
+
<Comp {...linkOptions} {...rowState} className={rowClassName}>
|
|
200
|
+
{content}
|
|
201
|
+
</Comp>
|
|
202
|
+
) : (
|
|
203
|
+
<button
|
|
204
|
+
type="button"
|
|
205
|
+
{...rowState}
|
|
206
|
+
aria-expanded={hasChildren ? isOpen : undefined}
|
|
207
|
+
{...props({ "aria-controls": hasChildren && itemsId })}
|
|
208
|
+
disabled={disabled}
|
|
209
|
+
onClick={() => hasChildren && setOpen(!isOpen)}
|
|
210
|
+
className={rowClassName}
|
|
211
|
+
>
|
|
212
|
+
{content}
|
|
213
|
+
{hasChildren && chevron(isOpen)}
|
|
214
|
+
</button>
|
|
215
|
+
)
|
|
216
|
+
|
|
171
217
|
return (
|
|
172
218
|
<div>
|
|
173
219
|
<div className="flex items-stretch gap-1">
|
|
174
|
-
{
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
{
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
{
|
|
190
|
-
disabled={disabled}
|
|
191
|
-
onClick={() => hasChildren && setOpen(!isOpen)}
|
|
192
|
-
className={rowClassName}
|
|
220
|
+
{rail ? (
|
|
221
|
+
// Only inside a rail-capable sidebar, so a plain NavLink pays for
|
|
222
|
+
// no tooltip machine. Disabled (not unmounted) while the labels
|
|
223
|
+
// show, so expanding never remounts the row under focus.
|
|
224
|
+
<Tooltip
|
|
225
|
+
label={label}
|
|
226
|
+
position="end"
|
|
227
|
+
asChild
|
|
228
|
+
disabled={!rail.active}
|
|
229
|
+
open={tipOpen && rail.active}
|
|
230
|
+
onOpenChange={({ open }) => setTipOpen(open)}
|
|
231
|
+
openDelay={200}
|
|
232
|
+
// Gone at once when the rail opens, rather than fading out over
|
|
233
|
+
// the label that's appearing beneath it. Important: it ties with
|
|
234
|
+
// the bubble's own data-[state=closed] exit animation otherwise.
|
|
235
|
+
classNames={{ content: rail.active ? undefined : "data-[state=closed]:animate-none!" }}
|
|
193
236
|
>
|
|
194
|
-
{
|
|
195
|
-
|
|
196
|
-
|
|
237
|
+
{row}
|
|
238
|
+
</Tooltip>
|
|
239
|
+
) : (
|
|
240
|
+
row
|
|
197
241
|
)}
|
|
198
242
|
{hasChildren && isLink && (
|
|
199
243
|
<button
|
|
@@ -213,7 +257,12 @@ function NavLinkImpl({
|
|
|
213
257
|
)}
|
|
214
258
|
</div>
|
|
215
259
|
{hasChildren && (
|
|
216
|
-
|
|
260
|
+
// Nested rows have no place on a rail, so they fold shut there — the
|
|
261
|
+
// same Collapse animation, not `display: none`, so they slide open as
|
|
262
|
+
// the rail peeks (and shut as it closes) instead of snapping, and stay
|
|
263
|
+
// inert while folded. `isOpen` itself is untouched: the row's own
|
|
264
|
+
// open state comes back with the labels.
|
|
265
|
+
<Collapse open={isOpen && !rail?.active}>
|
|
217
266
|
<div
|
|
218
267
|
id={itemsId}
|
|
219
268
|
className={cn(
|
|
@@ -214,4 +214,26 @@ describe("SegmentGroup separators under RTL", () => {
|
|
|
214
214
|
const pill = container.querySelector('[data-part="indicator"]') as HTMLElement
|
|
215
215
|
expect(pill.className).not.toMatch(/(^|\s)z-0(\s|$)/)
|
|
216
216
|
})
|
|
217
|
+
|
|
218
|
+
it("spans the container with an even share per segment under `grow`", () => {
|
|
219
|
+
render(<SegmentGroup data={ITEMS} testId="g" grow />)
|
|
220
|
+
const tray = screen.getByTestId("g")
|
|
221
|
+
expect(tray.className).toMatch(/(^|\s)w-full(\s|$)/)
|
|
222
|
+
expect(tray.className).not.toContain("max-w-fit")
|
|
223
|
+
const item = screen.getByTestId("item-list")
|
|
224
|
+
expect(item.className).toMatch(/(^|\s)flex-1(\s|$)/)
|
|
225
|
+
const text = item.querySelector('[data-part="item-text"]') as HTMLElement
|
|
226
|
+
expect(text.className).toMatch(/(^|\s)w-full(\s|$)/)
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
it("hugs its labels without `grow`", () => {
|
|
230
|
+
render(<SegmentGroup data={ITEMS} testId="g" />)
|
|
231
|
+
const tray = screen.getByTestId("g")
|
|
232
|
+
expect(tray.className).toContain("max-w-fit")
|
|
233
|
+
expect(tray.className).not.toMatch(/(^|\s)w-full(\s|$)/)
|
|
234
|
+
const item = screen.getByTestId("item-list")
|
|
235
|
+
expect(item.className).not.toMatch(/(^|\s)flex-1(\s|$)/)
|
|
236
|
+
const text = item.querySelector('[data-part="item-text"]') as HTMLElement
|
|
237
|
+
expect(text.className).not.toMatch(/(^|\s)w-full(\s|$)/)
|
|
238
|
+
})
|
|
217
239
|
})
|
|
@@ -103,6 +103,8 @@ const segItem = cva(
|
|
|
103
103
|
lg: "flex items-center justify-center px-3 text-lg",
|
|
104
104
|
xl: "flex items-center justify-center px-4 text-xl",
|
|
105
105
|
},
|
|
106
|
+
// Fill the (grown) segment so the label centers across its whole share.
|
|
107
|
+
grow: { true: "w-full" },
|
|
106
108
|
},
|
|
107
109
|
defaultVariants: { variant: "default", size: "md" },
|
|
108
110
|
},
|
|
@@ -117,22 +119,30 @@ const segItem = cva(
|
|
|
117
119
|
* `:nth-child(2)`). It flips from a vertical rule to a horizontal one when the
|
|
118
120
|
* group is laid out vertically.
|
|
119
121
|
*/
|
|
120
|
-
const segItemWrap = cva(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
]
|
|
122
|
+
const segItemWrap = cva(
|
|
123
|
+
[
|
|
124
|
+
"relative z-1 inline-flex",
|
|
125
|
+
"before:absolute before:rounded-full before:bg-brand-900/30 dark:before:bg-white/35",
|
|
126
|
+
"group-data-invalid:before:bg-red-500/30",
|
|
127
|
+
"before:transition-opacity before:duration-200",
|
|
128
|
+
// Horizontal: a vertical rule centered on the leading edge, sitting in the gap. Logical
|
|
129
|
+
// (`start`, `-ms-[0.5px]` to center the 1px rule), so under `dir="rtl"` the rule still lands
|
|
130
|
+
// between a segment and the one before it instead of on the far side.
|
|
131
|
+
"before:top-1/2 before:start-0 before:-ms-[0.5px] before:h-1/2 before:w-px before:-translate-y-1/2",
|
|
132
|
+
// Vertical: a horizontal rule centered on the top edge instead (`start-1/4` + `w-1/2` is
|
|
133
|
+
// centered in either direction).
|
|
134
|
+
"in-data-[orientation=vertical]:before:top-0 in-data-[orientation=vertical]:before:start-1/4 in-data-[orientation=vertical]:before:ms-0 in-data-[orientation=vertical]:before:h-px in-data-[orientation=vertical]:before:w-1/2",
|
|
135
|
+
// No separator before the first segment, or flanking the active pill.
|
|
136
|
+
"nth-2:before:hidden",
|
|
137
|
+
"data-[state=checked]:before:opacity-0 data-[state=checked]:[&+*]:before:opacity-0",
|
|
138
|
+
],
|
|
139
|
+
{
|
|
140
|
+
variants: {
|
|
141
|
+
// An even share of the tray per segment, like a tab bar.
|
|
142
|
+
grow: { true: "flex-1" },
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
)
|
|
136
146
|
|
|
137
147
|
/**
|
|
138
148
|
* The sliding pill, mirroring each `Button` surface. Its slide + color transition
|
|
@@ -213,6 +223,8 @@ const segTray = cva(
|
|
|
213
223
|
lg: "gap-0 min-h-10",
|
|
214
224
|
xl: "gap-0 min-h-12",
|
|
215
225
|
},
|
|
226
|
+
// Span the container instead of hugging the labels.
|
|
227
|
+
grow: { true: "flex w-full max-w-none" },
|
|
216
228
|
},
|
|
217
229
|
defaultVariants: { variant: "default" },
|
|
218
230
|
},
|
|
@@ -331,6 +343,9 @@ export type SegmentGroupProps<Data extends SegmentGroupData = SegmentGroupData>
|
|
|
331
343
|
size?: SegmentGroupSize
|
|
332
344
|
variant?: SegmentGroupVariant
|
|
333
345
|
color?: Color
|
|
346
|
+
/** Span the container and give every segment an even share of it, like a
|
|
347
|
+
* tab bar. Without it the group hugs its labels. */
|
|
348
|
+
grow?: boolean
|
|
334
349
|
/** Wires the hidden radio inputs into native form submission. */
|
|
335
350
|
name?: string
|
|
336
351
|
/** Explicit id for label association. */
|
|
@@ -453,6 +468,7 @@ export const SegmentGroup = <const Data extends SegmentGroupData = SegmentGroupD
|
|
|
453
468
|
size = "md",
|
|
454
469
|
variant = "default",
|
|
455
470
|
color,
|
|
471
|
+
grow,
|
|
456
472
|
name,
|
|
457
473
|
id,
|
|
458
474
|
ref,
|
|
@@ -513,7 +529,7 @@ export const SegmentGroup = <const Data extends SegmentGroupData = SegmentGroupD
|
|
|
513
529
|
onBlur={onBlur}
|
|
514
530
|
color={color}
|
|
515
531
|
testId={testId}
|
|
516
|
-
className={cn(segTray({ variant, size }), className, classNames?.root)}
|
|
532
|
+
className={cn(segTray({ variant, size, grow }), className, classNames?.root)}
|
|
517
533
|
>
|
|
518
534
|
{/* The sliding pill. Ark sets `position: absolute` + `--left`/`--top`/
|
|
519
535
|
`--width`/`--height` (the selected segment's rect) inline, so it
|
|
@@ -552,11 +568,11 @@ export const SegmentGroup = <const Data extends SegmentGroupData = SegmentGroupD
|
|
|
552
568
|
value={item.value}
|
|
553
569
|
disabled={item.disabled}
|
|
554
570
|
data-testid={item.testId}
|
|
555
|
-
className={cn(segItemWrap(), classNames?.item)}
|
|
571
|
+
className={cn(segItemWrap({ grow }), classNames?.item)}
|
|
556
572
|
>
|
|
557
573
|
<Ark.ItemText
|
|
558
574
|
data-color={item.color}
|
|
559
|
-
className={cn(segItem({ size, variant }), classNames?.itemText)}
|
|
575
|
+
className={cn(segItem({ size, variant, grow }), classNames?.itemText)}
|
|
560
576
|
>
|
|
561
577
|
{/* `renderItem` owns the label content (with the item's typed payload);
|
|
562
578
|
the ItemText keeps its sizing, checked color, and pill wiring. */}
|
|
@@ -72,6 +72,21 @@ describe("Switch", () => {
|
|
|
72
72
|
expect(screen.getByText("Select row").className).toContain("sr-only")
|
|
73
73
|
})
|
|
74
74
|
|
|
75
|
+
it("aligns the control to the label line when a description sits below", () => {
|
|
76
|
+
const { container } = render(<Switch label="Airplane mode" description="Disables all radios" />)
|
|
77
|
+
const root = container.querySelector("label") as HTMLElement
|
|
78
|
+
// A grid root with control, label and field as direct cells: the control
|
|
79
|
+
// centers on the label row, and the field hangs under the label.
|
|
80
|
+
expect(root.className).toContain("inline-grid")
|
|
81
|
+
expect(Array.from(root.children).map((el) => el.tagName)).toEqual(["SPAN", "SPAN", "DIV"])
|
|
82
|
+
expect(root.lastElementChild?.className).toContain("col-start-2")
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it("keeps a label-only root as an inline row", () => {
|
|
86
|
+
const { container } = render(<Switch label="Airplane mode" />)
|
|
87
|
+
expect((container.querySelector("label") as HTMLElement).className).toContain("inline-flex")
|
|
88
|
+
})
|
|
89
|
+
|
|
75
90
|
it("renders a sr-only label with no extra wrapper around it", () => {
|
|
76
91
|
const { container } = render(<Switch label="Select row" classNames={{ label: "sr-only" }} />)
|
|
77
92
|
const root = container.querySelector("label") as HTMLElement
|