@42-central/ui-react 0.26.0 → 0.27.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-NLSJ6T7V.js → chunk-4D2V4JE4.js} +3 -3
- package/dist/{chunk-NLSJ6T7V.js.map → chunk-4D2V4JE4.js.map} +1 -1
- package/dist/{chunk-7B44J3CF.js → chunk-5H5YOPCF.js} +3 -3
- package/dist/{chunk-7B44J3CF.js.map → chunk-5H5YOPCF.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-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-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-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-YMVUQ2L7.js → chunk-L24N5EON.js} +6 -6
- package/dist/chunk-L24N5EON.js.map +1 -0
- 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-N42EFOML.js → chunk-MCRTAUSZ.js} +6 -6
- package/dist/chunk-MCRTAUSZ.js.map +1 -0
- package/dist/{chunk-276RL7FX.js → chunk-MNYY7UU2.js} +6 -6
- package/dist/{chunk-276RL7FX.js.map → chunk-MNYY7UU2.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-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-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-2TZU4LSX.js → chunk-ULF5LOBS.js} +3 -3
- package/dist/{chunk-2TZU4LSX.js.map → chunk-ULF5LOBS.js.map} +1 -1
- package/dist/components/app-shell/index.js +4 -4
- package/dist/components/autocomplete/index.js +4 -4
- package/dist/components/calendar-heatmap/index.js +2 -2
- package/dist/components/camera/index.js +6 -6
- 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 +877 -229
- package/dist/components/data-table/index.js.map +1 -1
- package/dist/components/date-picker/index.js +7 -7
- package/dist/components/drawer/index.js +4 -4
- package/dist/components/hover-card/index.js +3 -3
- package/dist/components/kbd/index.js +3 -3
- package/dist/components/lightbox/index.js +4 -4
- package/dist/components/menu/index.js +4 -4
- package/dist/components/modal/index.js +4 -4
- 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 +15 -3
- 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 +5 -5
- package/dist/components/photo-capture/index.js +6 -6
- package/dist/components/popover/index.js +3 -3
- package/dist/components/schedule/index.js +3 -3
- package/dist/components/select/index.js +5 -5
- package/dist/components/spotlight/index.js +8 -8
- package/dist/components/tags-input/index.js +3 -3
- 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/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/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/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-H7WOMZXO.js.map +0 -1
- package/dist/chunk-N42EFOML.js.map +0 -1
- package/dist/chunk-YMVUQ2L7.js.map +0 -1
|
@@ -8,6 +8,8 @@ export type {
|
|
|
8
8
|
ColumnFiltersState,
|
|
9
9
|
ColumnSizingState,
|
|
10
10
|
ColumnVisibilityState,
|
|
11
|
+
ExpandedState,
|
|
12
|
+
GroupingState,
|
|
11
13
|
OnChangeFn,
|
|
12
14
|
PaginationState,
|
|
13
15
|
RowSelectionState,
|
|
@@ -40,6 +42,8 @@ export {
|
|
|
40
42
|
type HeaderContext,
|
|
41
43
|
type Row,
|
|
42
44
|
} from "./data-table-features"
|
|
45
|
+
export type { DataTableGroupHeaderContext, DataTableGroupShowMore } from "./data-table-group"
|
|
46
|
+
export type { DataTableGroup } from "./data-table-grouping"
|
|
43
47
|
export type {
|
|
44
48
|
DataTableIconSlot,
|
|
45
49
|
DataTableIcons,
|
|
@@ -201,7 +201,7 @@ const DrawerRoot = ({
|
|
|
201
201
|
>
|
|
202
202
|
{/* A layer itself, registered with whatever it opened from (the page,
|
|
203
203
|
or an enclosing overlay), so what's under it knows it's covered. */}
|
|
204
|
-
<Ark.Context>{(api) => <NestedLayer open={api.open} />}</Ark.Context>
|
|
204
|
+
<Ark.Context>{(api) => <NestedLayer open={api.open} modal />}</Ark.Context>
|
|
205
205
|
<DrawerPlacementContext value={placement}>
|
|
206
206
|
<DialogRootProviders icons={icons} layers={guard.layers}>
|
|
207
207
|
{children}
|
|
@@ -113,7 +113,7 @@ const ModalRoot = ({ onPointerDownOutside, icons, children, ...rest }: ModalRoot
|
|
|
113
113
|
<Ark.Root onPointerDownOutside={guard.onPointerDownOutside} {...rest}>
|
|
114
114
|
{/* A layer itself, registered with whatever it opened from (the page,
|
|
115
115
|
or an enclosing overlay), so what's under it knows it's covered. */}
|
|
116
|
-
<Ark.Context>{(api) => <NestedLayer open={api.open} />}</Ark.Context>
|
|
116
|
+
<Ark.Context>{(api) => <NestedLayer open={api.open} modal />}</Ark.Context>
|
|
117
117
|
<DialogRootProviders icons={icons} layers={guard.layers}>
|
|
118
118
|
{children}
|
|
119
119
|
</DialogRootProviders>
|
|
@@ -17,6 +17,7 @@ import type { UnavailableProps } from "../../lib/available-if"
|
|
|
17
17
|
import { cn } from "../../lib/cn"
|
|
18
18
|
import type { Color } from "../../lib/colors"
|
|
19
19
|
import { useMergedRefs } from "../../lib/merge-refs"
|
|
20
|
+
import { isModalOpen } from "../../lib/overlay-layer"
|
|
20
21
|
import { useDocumentVisibility } from "../../lib/use-document-visibility"
|
|
21
22
|
import {
|
|
22
23
|
NOTIFICATION_DEFAULT_TRANSLATIONS,
|
|
@@ -266,7 +267,8 @@ function ToasterItem({
|
|
|
266
267
|
const { id } = toast
|
|
267
268
|
// The store keeps `type` and `color` side by side; the card takes one or the
|
|
268
269
|
// other. At most one is ever set (see `toData`), so pick whichever is.
|
|
269
|
-
|
|
270
|
+
// `raised` is the region's business, not the card's.
|
|
271
|
+
const { type, color, raised: _raised, ...fields } = toast
|
|
270
272
|
const hue: ToastHue = type ? { type } : { color }
|
|
271
273
|
|
|
272
274
|
const presence = usePresence({
|
|
@@ -392,6 +394,11 @@ export function createNotifier(options: CreateNotifierOptions = {}): Notifier {
|
|
|
392
394
|
icon: o.icon,
|
|
393
395
|
duration: o.duration ?? (type === "loading" ? Number.POSITIVE_INFINITY : defaultDuration),
|
|
394
396
|
withCloseButton: o.withCloseButton ?? true,
|
|
397
|
+
// A toast is feedback on what the user just did, so if they did it in a
|
|
398
|
+
// modal it must show over the modal. Only ever set, never cleared: the
|
|
399
|
+
// store merges a re-create by id, so a promise settling after the modal
|
|
400
|
+
// closed keeps its place. See `--toast-raised-z` in theme.css.
|
|
401
|
+
...(isModalOpen() && { raised: true }),
|
|
395
402
|
}
|
|
396
403
|
}
|
|
397
404
|
|
|
@@ -527,17 +534,26 @@ export function createNotifier(options: CreateNotifierOptions = {}): Notifier {
|
|
|
527
534
|
const maxHeight = toasts.reduce((max, toast) => Math.max(max, heightOf(toast)), 0)
|
|
528
535
|
const stackOverflow = placement.startsWith("bottom") ? Math.max(0, maxHeight - frontHeight) : 0
|
|
529
536
|
|
|
537
|
+
const raised = toasts.some((toast) => toast.raised)
|
|
538
|
+
|
|
530
539
|
const region = (
|
|
531
540
|
<section
|
|
532
541
|
aria-label={translations.regionLabel}
|
|
533
542
|
data-scope="notifications"
|
|
534
543
|
data-placement={placement}
|
|
535
544
|
data-expand={expand ? "" : undefined}
|
|
545
|
+
data-raised={raised ? "" : undefined}
|
|
546
|
+
// zag's modal dialog aria-hides everything outside it, which would
|
|
547
|
+
// silence a toast raised from inside it. It skips live announcers.
|
|
548
|
+
data-live-announcer=""
|
|
536
549
|
// Slide direction for the enter/exit keyframes: from below for bottom
|
|
537
550
|
// placements, from above for top.
|
|
538
551
|
style={{ ["--toast-from" as string]: placement.startsWith("top") ? "-100%" : "100%" }}
|
|
539
552
|
className={cn(
|
|
540
|
-
"pointer-events-none fixed
|
|
553
|
+
"pointer-events-none fixed justify-center flex",
|
|
554
|
+
// Under modals by default; above them while it holds a toast created
|
|
555
|
+
// from inside one (theme.css, OVERLAY STACKING).
|
|
556
|
+
raised ? "z-(--toast-raised-z,200)" : "z-(--toast-z,100)",
|
|
541
557
|
REGION_POSITION[placement],
|
|
542
558
|
// Phones (< xs): pin to the bottom, full-bleed, above the safe area.
|
|
543
559
|
"max-xs:inset-x-0! max-xs:bottom-[calc(1rem+env(safe-area-inset-bottom))]! max-xs:top-auto! max-xs:translate-x-0!",
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/** biome-ignore-all lint/style/noNonNullAssertion: a missing node fails the test anyway */
|
|
2
|
+
|
|
3
|
+
import { act, render, screen } from "@testing-library/react"
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"
|
|
5
|
+
import { Drawer } from "../drawer/drawer"
|
|
6
|
+
import { Modal } from "../modal/modal"
|
|
7
|
+
import { createNotifier } from "./create-notifier"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* #440: a toast created from inside a modal is feedback on what was done in
|
|
11
|
+
* it, so it has to reach the user over the modal: painted above it, announced,
|
|
12
|
+
* and dismissable without taking the modal along. Toasts that were on screen
|
|
13
|
+
* before the modal opened stay under it.
|
|
14
|
+
*
|
|
15
|
+
* Fake timers for the same reason as `lib/overlay-layer.test.tsx`: zag arms its
|
|
16
|
+
* outside listeners (and its aria-hiding) a few frames after the layer mounts.
|
|
17
|
+
*/
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
vi.useFakeTimers({
|
|
20
|
+
toFake: [
|
|
21
|
+
"setTimeout",
|
|
22
|
+
"clearTimeout",
|
|
23
|
+
"requestAnimationFrame",
|
|
24
|
+
"cancelAnimationFrame",
|
|
25
|
+
"performance",
|
|
26
|
+
],
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
vi.useRealTimers()
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const settle = () => act(() => vi.advanceTimersByTimeAsync(150))
|
|
34
|
+
|
|
35
|
+
const region = () => document.querySelector<HTMLElement>('[data-scope="notifications"]')!
|
|
36
|
+
|
|
37
|
+
const setup = (Surface: "modal" | "drawer" = "modal") => {
|
|
38
|
+
const { notify, Notifications } = createNotifier({ duration: Number.POSITIVE_INFINITY })
|
|
39
|
+
const onOpenChange = vi.fn()
|
|
40
|
+
const view = (open: boolean) =>
|
|
41
|
+
Surface === "modal" ? (
|
|
42
|
+
<>
|
|
43
|
+
<Modal open={open} onOpenChange={onOpenChange} title="Edit slot">
|
|
44
|
+
body
|
|
45
|
+
</Modal>
|
|
46
|
+
<Notifications />
|
|
47
|
+
</>
|
|
48
|
+
) : (
|
|
49
|
+
<>
|
|
50
|
+
<Drawer open={open} onOpenChange={onOpenChange} title="Edit slot">
|
|
51
|
+
body
|
|
52
|
+
</Drawer>
|
|
53
|
+
<Notifications />
|
|
54
|
+
</>
|
|
55
|
+
)
|
|
56
|
+
const utils = render(view(false))
|
|
57
|
+
return {
|
|
58
|
+
notify,
|
|
59
|
+
open: async () => {
|
|
60
|
+
utils.rerender(view(true))
|
|
61
|
+
await settle()
|
|
62
|
+
},
|
|
63
|
+
close: async () => {
|
|
64
|
+
utils.rerender(view(false))
|
|
65
|
+
await settle()
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
describe("notify while a modal is open", () => {
|
|
71
|
+
it("leaves the region in its own band with no modal open", async () => {
|
|
72
|
+
const { notify } = setup()
|
|
73
|
+
act(() => void notify.error("Failed"))
|
|
74
|
+
await settle()
|
|
75
|
+
expect(region().hasAttribute("data-raised")).toBe(false)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it.each(["modal", "drawer"] as const)("raises a toast created from a %s", async (surface) => {
|
|
79
|
+
const { notify, open } = setup(surface)
|
|
80
|
+
await open()
|
|
81
|
+
act(() => void notify.error("Failed"))
|
|
82
|
+
await settle()
|
|
83
|
+
expect(region().hasAttribute("data-raised")).toBe(true)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it("leaves a toast that was already on screen under the modal", async () => {
|
|
87
|
+
const { notify, open } = setup()
|
|
88
|
+
act(() => void notify.success("Saved earlier"))
|
|
89
|
+
await open()
|
|
90
|
+
await settle()
|
|
91
|
+
expect(region().hasAttribute("data-raised")).toBe(false)
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it("keeps a raised toast raised after the modal closes", async () => {
|
|
95
|
+
const { notify, open, close } = setup()
|
|
96
|
+
await open()
|
|
97
|
+
act(() => void notify.error("Failed"))
|
|
98
|
+
await close()
|
|
99
|
+
expect(region().hasAttribute("data-raised")).toBe(true)
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it("keeps the raise when a promise toast settles after the modal closed", async () => {
|
|
103
|
+
const { notify, open, close } = setup()
|
|
104
|
+
await open()
|
|
105
|
+
let reject!: (reason: unknown) => void
|
|
106
|
+
act(() => {
|
|
107
|
+
notify.promise(new Promise((_, r) => (reject = r)), { loading: "Saving…", error: "Failed" })
|
|
108
|
+
})
|
|
109
|
+
await close()
|
|
110
|
+
await act(async () => reject(new Error("409")))
|
|
111
|
+
await settle()
|
|
112
|
+
expect(screen.getByText("Failed")).toBeTruthy()
|
|
113
|
+
expect(region().hasAttribute("data-raised")).toBe(true)
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it("is not aria-hidden by the modal, so the error is announced", async () => {
|
|
117
|
+
const { notify, open } = setup()
|
|
118
|
+
await open()
|
|
119
|
+
act(() => void notify.error("Failed"))
|
|
120
|
+
await settle()
|
|
121
|
+
expect(region().closest("[aria-hidden='true']")).toBeNull()
|
|
122
|
+
expect(screen.getByRole("alert").textContent).toContain("Failed")
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
// A press on a toast not dismissing the modal is tested against the guard
|
|
126
|
+
// itself in `lib/overlay-layer.test.tsx`: jsdom doesn't reproduce zag's
|
|
127
|
+
// outside dismissal from a press on a portaled sibling reliably.
|
|
128
|
+
})
|
|
@@ -64,4 +64,9 @@ export type ToastFields = {
|
|
|
64
64
|
/** Render the close (×) button. Takes precedence over `withCollapse` (on the
|
|
65
65
|
* ready-made `Notification`). */
|
|
66
66
|
withCloseButton?: boolean
|
|
67
|
+
/** Created while a Modal, Drawer or Lightbox was open: the region paints
|
|
68
|
+
* above modals (`--toast-raised-z`) while this toast is on screen. Set by the
|
|
69
|
+
* notifier, never by the caller, and kept once set, so a toast that was
|
|
70
|
+
* above a modal never drops under it mid-life. */
|
|
71
|
+
raised?: boolean
|
|
67
72
|
}
|
|
@@ -17,7 +17,8 @@ import { createContext, type ReactNode, type RefObject, useContext, useMemo } fr
|
|
|
17
17
|
* Being a descendant of a surface that already outranks the page, the panel
|
|
18
18
|
* stays above it structurally, whatever its own z-index band says — which is
|
|
19
19
|
* also what frees `--toast-z` to sit between the overlay and modal bands
|
|
20
|
-
* instead of above both
|
|
20
|
+
* instead of above both. A toast created while a modal is open moves up to
|
|
21
|
+
* `--toast-raised-z` instead (see `theme.css`).
|
|
21
22
|
*
|
|
22
23
|
* `Schedule` publishes its scroller the same way, for a different reason: its
|
|
23
24
|
* popovers should scroll and clip with the grid, not float over the page.
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { act, fireEvent, render, screen } from "@testing-library/react"
|
|
1
|
+
import { act, fireEvent, render, renderHook, screen } from "@testing-library/react"
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"
|
|
3
3
|
import { Drawer } from "../components/drawer/drawer"
|
|
4
4
|
import { Menu } from "../components/menu"
|
|
5
5
|
import { Modal } from "../components/modal/modal"
|
|
6
6
|
import { Popover } from "../components/popover/popover"
|
|
7
|
+
import { isModalOpen, useLayerGuard } from "./overlay-layer"
|
|
7
8
|
|
|
8
9
|
// Zag arms its outside-pointer listeners a few hops after the layer mounts (a
|
|
9
10
|
// microtask, an animation frame, then a timer) and dispatches the outside event
|
|
@@ -156,3 +157,64 @@ describe("nested overlay layers", () => {
|
|
|
156
157
|
expect(screen.getByRole("dialog")).toBeTruthy()
|
|
157
158
|
})
|
|
158
159
|
})
|
|
160
|
+
|
|
161
|
+
/** zag's outside event as it really arrives: dispatched on the layer's own
|
|
162
|
+
* content node, with the pressed node only in `detail.originalEvent`. */
|
|
163
|
+
const outsideEvent = (pressed: Element) => {
|
|
164
|
+
const originalEvent = new Event("pointerdown")
|
|
165
|
+
Object.defineProperty(originalEvent, "target", { value: pressed })
|
|
166
|
+
return new CustomEvent("pointerdown.outside", { cancelable: true, detail: { originalEvent } })
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const getButton = () => {
|
|
170
|
+
const button = document.querySelector("button")
|
|
171
|
+
if (!button) throw new Error("no button")
|
|
172
|
+
return button
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
describe("toasts are never outside a layer (#440)", () => {
|
|
176
|
+
it("vetoes the dismiss when the press lands on a toast", () => {
|
|
177
|
+
document.body.innerHTML =
|
|
178
|
+
'<section data-scope="notifications"><div><button>×</button></div></section>'
|
|
179
|
+
const { result } = renderHook(() => useLayerGuard())
|
|
180
|
+
const event = outsideEvent(getButton())
|
|
181
|
+
result.current.onPointerDownOutside(event)
|
|
182
|
+
expect(event.defaultPrevented).toBe(true)
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
it("lets any other outside press through", () => {
|
|
186
|
+
document.body.innerHTML = "<main><button>page</button></main>"
|
|
187
|
+
const { result } = renderHook(() => useLayerGuard())
|
|
188
|
+
const event = outsideEvent(getButton())
|
|
189
|
+
result.current.onPointerDownOutside(event)
|
|
190
|
+
expect(event.defaultPrevented).toBe(false)
|
|
191
|
+
})
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
describe("isModalOpen", () => {
|
|
195
|
+
it.each([
|
|
196
|
+
["Modal", (open: boolean) => <Modal open={open} onOpenChange={() => {}} title="T" />],
|
|
197
|
+
["Drawer", (open: boolean) => <Drawer open={open} onOpenChange={() => {}} title="T" />],
|
|
198
|
+
] as const)("is true exactly while a %s is open", async (_, view) => {
|
|
199
|
+
const { rerender, unmount } = render(view(false))
|
|
200
|
+
expect(isModalOpen()).toBe(false)
|
|
201
|
+
rerender(view(true))
|
|
202
|
+
await settle()
|
|
203
|
+
expect(isModalOpen()).toBe(true)
|
|
204
|
+
rerender(view(false))
|
|
205
|
+
await settle()
|
|
206
|
+
expect(isModalOpen()).toBe(false)
|
|
207
|
+
unmount()
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
it("ignores page-level pickers", async () => {
|
|
211
|
+
render(
|
|
212
|
+
<Popover.Root defaultOpen>
|
|
213
|
+
<Popover.Trigger>open</Popover.Trigger>
|
|
214
|
+
<Popover.Content>panel</Popover.Content>
|
|
215
|
+
</Popover.Root>,
|
|
216
|
+
)
|
|
217
|
+
await settle()
|
|
218
|
+
expect(isModalOpen()).toBe(false)
|
|
219
|
+
})
|
|
220
|
+
})
|
|
@@ -44,6 +44,26 @@ const PAGE_LAYERS: OverlayLayers = new Set()
|
|
|
44
44
|
|
|
45
45
|
const OverlayLayerContext = createContext<OverlayLayers>(PAGE_LAYERS)
|
|
46
46
|
|
|
47
|
+
/** The modal layers open right now, anywhere on the page: every open
|
|
48
|
+
* `Modal`, `Drawer` and `Lightbox`, however deeply nested. Module scope, not
|
|
49
|
+
* context, because its one reader (`notify()`) runs outside React. Not
|
|
50
|
+
* derivable from `PAGE_LAYERS`: a Drawer opened from a page Popover
|
|
51
|
+
* registers into the popover's set, not the page's. */
|
|
52
|
+
const OPEN_MODALS = new Set<symbol>()
|
|
53
|
+
|
|
54
|
+
/** Whether a Modal, Drawer or Lightbox is open right now. The notifier asks
|
|
55
|
+
* when a toast is created, to raise it above the modal (`--toast-raised-z`). */
|
|
56
|
+
export const isModalOpen = () => OPEN_MODALS.size > 0
|
|
57
|
+
|
|
58
|
+
/** A press on a toast is never "outside" a layer. Toasts raised from a modal
|
|
59
|
+
* paint above it, and dismissing one must not take the modal (and the form
|
|
60
|
+
* in it) along. zag dispatches its outside event on the layer's own content
|
|
61
|
+
* node, so the pressed node is the original event's target, in `detail`. */
|
|
62
|
+
const isToastEvent = (event: Event) => {
|
|
63
|
+
const target = (event as CustomEvent<{ originalEvent?: Event }>).detail?.originalEvent?.target
|
|
64
|
+
return target instanceof Element && target.closest('[data-scope="notifications"]') != null
|
|
65
|
+
}
|
|
66
|
+
|
|
47
67
|
/** For a parent layer. Spread `onPointerDownOutside` onto the Ark root
|
|
48
68
|
* (composed with the caller's own) and wrap the children that may open nested
|
|
49
69
|
* layers in `OverlayLayerProvider`. A ref'd set, not state: it's read synchronously while
|
|
@@ -53,7 +73,7 @@ export const useLayerGuard = <E extends Event>(onPointerDownOutside?: (event: E)
|
|
|
53
73
|
const guard = useCallback(
|
|
54
74
|
(event: E) => {
|
|
55
75
|
onPointerDownOutside?.(event)
|
|
56
|
-
if (layers.size > 0) event.preventDefault()
|
|
76
|
+
if (layers.size > 0 || isToastEvent(event)) event.preventDefault()
|
|
57
77
|
},
|
|
58
78
|
[layers, onPointerDownOutside],
|
|
59
79
|
)
|
|
@@ -72,23 +92,26 @@ export const OverlayLayerProvider = ({
|
|
|
72
92
|
* none encloses it) while `open`. Keyed on
|
|
73
93
|
* `open`, not presence, so a panel playing its exit animation no longer holds
|
|
74
94
|
* the parent's next click. A layout effect so the registration is in place
|
|
75
|
-
* before the browser can deliver the next pointerdown.
|
|
76
|
-
|
|
95
|
+
* before the browser can deliver the next pointerdown. `modal` marks a
|
|
96
|
+
* Modal, Drawer or Lightbox, which `isModalOpen` counts. */
|
|
97
|
+
export const useNestedLayer = (open: boolean, { modal = false }: { modal?: boolean } = {}) => {
|
|
77
98
|
const parent = useContext(OverlayLayerContext)
|
|
78
99
|
useIsomorphicLayoutEffect(() => {
|
|
79
100
|
if (!open) return
|
|
80
101
|
const token = Symbol()
|
|
81
102
|
parent.add(token)
|
|
103
|
+
if (modal) OPEN_MODALS.add(token)
|
|
82
104
|
return () => {
|
|
83
105
|
parent.delete(token)
|
|
106
|
+
OPEN_MODALS.delete(token)
|
|
84
107
|
}
|
|
85
|
-
}, [open, parent])
|
|
108
|
+
}, [open, modal, parent])
|
|
86
109
|
}
|
|
87
110
|
|
|
88
111
|
/** `useNestedLayer` as an element, for call sites that only have the machine's
|
|
89
112
|
* `open` inside a render prop (`<Ark.Context>{(api) => …}</Ark.Context>`). */
|
|
90
|
-
export const NestedLayer = ({ open }: { open: boolean }) => {
|
|
91
|
-
useNestedLayer(open)
|
|
113
|
+
export const NestedLayer = ({ open, modal }: { open: boolean; modal?: boolean }) => {
|
|
114
|
+
useNestedLayer(open, { modal })
|
|
92
115
|
return null
|
|
93
116
|
}
|
|
94
117
|
|
package/src/theme.css
CHANGED
|
@@ -1295,10 +1295,17 @@ body {
|
|
|
1295
1295
|
==========================================
|
|
1296
1296
|
One scale for every floating surface, in the order they need to paint:
|
|
1297
1297
|
|
|
1298
|
-
--overlay-z
|
|
1299
|
-
--toast-z
|
|
1300
|
-
--modal-z
|
|
1301
|
-
--
|
|
1298
|
+
--overlay-z popover, menu, hover-card, select, combobox, date-picker
|
|
1299
|
+
--toast-z the notifier region
|
|
1300
|
+
--modal-z modal + drawer + lightbox (backdrop and positioner)
|
|
1301
|
+
--toast-raised-z the notifier region, while it holds a toast created
|
|
1302
|
+
with a modal open (feedback on what was done in it)
|
|
1303
|
+
--tooltip-z tooltip
|
|
1304
|
+
|
|
1305
|
+
Bands are 50 apart, and stay that way: each one adds zag's `--layer-index`
|
|
1306
|
+
(nesting depth) on top of its base, so the gap is how deep a band can nest
|
|
1307
|
+
before it collides with the next. Insert a new band by moving the ones
|
|
1308
|
+
above it up, not by halving a gap. `theme.test.ts` holds the spacing.
|
|
1302
1309
|
|
|
1303
1310
|
Two facts about `@zag-js/popper` decide *where* these values have to be
|
|
1304
1311
|
declared, and both are easy to get wrong:
|
|
@@ -1339,7 +1346,8 @@ body {
|
|
|
1339
1346
|
--overlay-z: 50;
|
|
1340
1347
|
--toast-z: 100;
|
|
1341
1348
|
--modal-z: 150;
|
|
1342
|
-
--
|
|
1349
|
+
--toast-raised-z: 200;
|
|
1350
|
+
--tooltip-z: 250;
|
|
1343
1351
|
}
|
|
1344
1352
|
|
|
1345
1353
|
[data-scope="popover"][data-part="content"],
|
|
@@ -1354,7 +1362,7 @@ body {
|
|
|
1354
1362
|
/* A tooltip can show up over anything hoverable, an open picker included. It
|
|
1355
1363
|
isn't a dismissable layer, so there's no `--layer-index` to add. */
|
|
1356
1364
|
[data-scope="tooltip"][data-part="content"] {
|
|
1357
|
-
z-index: var(--tooltip-z,
|
|
1365
|
+
z-index: var(--tooltip-z, 250);
|
|
1358
1366
|
}
|
|
1359
1367
|
|
|
1360
1368
|
/* ==========================================
|
package/src/theme.test.ts
CHANGED
|
@@ -149,12 +149,12 @@ describe("exit animations are always state-driven", () => {
|
|
|
149
149
|
describe("theme.css overlay stacking", () => {
|
|
150
150
|
const rootBlock = themeCss.match(/:root \{[\s\S]*?\n\}/g)?.join("\n") ?? ""
|
|
151
151
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
)
|
|
152
|
+
/** The scale, bottom to top. */
|
|
153
|
+
const BANDS = ["--overlay-z", "--toast-z", "--modal-z", "--toast-raised-z", "--tooltip-z"]
|
|
154
|
+
|
|
155
|
+
it.each(BANDS)("declares %s on :root so consumers can retune the band", (token) => {
|
|
156
|
+
expect(rootBlock).toMatch(new RegExp(`${token}:\\s*\\d+;`))
|
|
157
|
+
})
|
|
158
158
|
|
|
159
159
|
/** Every scope whose panel has to be ranked against another portal. Adding a
|
|
160
160
|
* floating component means adding it here *and* to the rule in theme.css —
|
|
@@ -196,12 +196,16 @@ describe("theme.css overlay stacking", () => {
|
|
|
196
196
|
expect(offenders).toEqual([])
|
|
197
197
|
})
|
|
198
198
|
|
|
199
|
-
|
|
199
|
+
/** Each band adds zag's `--layer-index` (nesting depth) to its base, so the
|
|
200
|
+
* gap to the next band is how deep it can nest before the two collide. */
|
|
201
|
+
it("keeps the bands in order, at least 50 apart", () => {
|
|
200
202
|
const band = (token: string) => Number(rootBlock.match(new RegExp(`${token}:\\s*(\\d+);`))?.[1])
|
|
203
|
+
const tooClose = BANDS.slice(1)
|
|
204
|
+
.map((above, i) => ({ below: BANDS[i] ?? "", above }))
|
|
205
|
+
.map(({ below, above }) => ({ below, above, gap: band(above) - band(below) }))
|
|
206
|
+
.filter(({ gap }) => !(gap >= 50))
|
|
201
207
|
|
|
202
|
-
expect(
|
|
203
|
-
expect(band("--toast-z")).toBeLessThan(band("--modal-z"))
|
|
204
|
-
expect(band("--modal-z")).toBeLessThan(band("--tooltip-z"))
|
|
208
|
+
expect(tooClose).toEqual([])
|
|
205
209
|
})
|
|
206
210
|
})
|
|
207
211
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/overlay-container.tsx"],"names":[],"mappings":";;;;AAsCA,IAAM,uBAAA,GAA0B,cAAoD,IAAI,CAAA;AAUjF,IAAM,wBAAA,GAA2B,CAAC,EAAE,KAAA,EAAO,QAAA,EAAS,qBACzD,GAAA,CAAC,uBAAA,CAAwB,QAAA,EAAxB,EAAiC,KAAA,EAAe,QAAA,EAAS;AAMrD,IAAM,mBAAA,GAAsB,CACjC,QAAA,KAC8C;AAC9C,EAAA,MAAM,SAAA,GAAY,WAAW,uBAAuB,CAAA;AAGpD,EAAA,MAAM,GAAA,GAAM,OAAA,CAAQ,MAAO,QAAA,GAAW,EAAE,OAAA,EAAS,QAAA,EAAS,GAAI,IAAA,EAAO,CAAC,QAAQ,CAAC,CAAA;AAC/E,EAAA,OAAO,OAAO,SAAA,IAAa,MAAA;AAC7B","file":"chunk-7P32XCEU.js","sourcesContent":["\"use client\"\n\nimport { createContext, type ReactNode, type RefObject, useContext, useMemo } from \"react\"\n\n/**\n * Shared \"where do nested overlays portal to\" context.\n *\n * Every floating surface in this kit portals to `document.body` by default so\n * it escapes clipping ancestors. That's right at page level, but it breaks down\n * inside a Modal/Drawer: the panel becomes a *sibling* of the dialog rather\n * than a descendant, so the only thing keeping it visible is a z-index tall\n * enough to clear `--modal-z` — and any number picked for that is wrong the\n * moment dialogs and overlays nest the other way around.\n *\n * So `Modal`/`Drawer` publish their own positioner here (see their\n * `Positioner` parts), and every overlay opened inside one portals *into* it.\n * Being a descendant of a surface that already outranks the page, the panel\n * stays above it structurally, whatever its own z-index band says — which is\n * also what frees `--toast-z` to sit between the overlay and modal bands\n * instead of above both (see `theme.css`).\n *\n * `Schedule` publishes its scroller the same way, for a different reason: its\n * popovers should scroll and clip with the grid, not float over the page.\n *\n * Modal and Drawer deliberately don't *consume* this: dialog-on-dialog order\n * is already handled by `--modal-z` plus zag's `--layer-index`, and nesting one\n * fixed, scroll-locking container inside another buys nothing.\n */\n/**\n * A ref, not the element. The element only exists after its first commit, so\n * publishing it as state costs every provider a second render of its whole\n * subtree just to hand the node down — and each portal a third, to move there.\n * Ark's `Portal` reads `container.current` itself when it first renders, so a\n * ref is enough: an overlay that mounts once the container is attached (a\n * lazily mounted panel, opened later) lands in the right place on its first\n * render, and one mounted in the same commit as the container is moved there\n * by `Portal`'s own mount effect, by which time the ref is set.\n */\nconst OverlayContainerContext = createContext<RefObject<HTMLElement | null> | null>(null)\n\nexport type OverlayContainerProviderProps = {\n /** A ref to the element nested overlays should portal into — a\n * Modal/Drawer positioner, a Schedule scroller. Still `null` (not yet\n * attached) reads as \"no container\", i.e. `document.body`. */\n value: RefObject<HTMLElement | null>\n children?: ReactNode\n}\n\nexport const OverlayContainerProvider = ({ value, children }: OverlayContainerProviderProps) => (\n <OverlayContainerContext.Provider value={value}>{children}</OverlayContainerContext.Provider>\n)\n\n/** Resolves an overlay's portal target, shaped for Ark's `<Portal container>`:\n * `override` (a per-instance `container` prop) wins; else the enclosing\n * provider's ref; else `undefined` — Ark falls back to `document.body`. */\nexport const useOverlayContainer = (\n override?: HTMLElement | null,\n): RefObject<HTMLElement | null> | undefined => {\n const inherited = useContext(OverlayContainerContext)\n // Ark's `Portal` keys its container effect on this object's identity, so\n // keep it stable while the element is.\n const own = useMemo(() => (override ? { current: override } : null), [override])\n return own ?? inherited ?? undefined\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/overlay-layer.tsx"],"names":[],"mappings":";;;;AA0CA,IAAM,WAAA,uBAAiC,GAAA,EAAI;AAE3C,IAAM,mBAAA,GAAsB,cAA6B,WAAW,CAAA;AAM7D,IAAM,aAAA,GAAgB,CAAkB,oBAAA,KAA8C;AAC3F,EAAA,MAAM,MAAA,GAAS,MAAA,iBAAsB,IAAI,GAAA,EAAK,CAAA,CAAE,OAAA;AAChD,EAAA,MAAM,KAAA,GAAQ,WAAA;AAAA,IACZ,CAAC,KAAA,KAAa;AACZ,MAAA,oBAAA,GAAuB,KAAK,CAAA;AAC5B,MAAA,IAAI,MAAA,CAAO,IAAA,GAAO,CAAA,EAAG,KAAA,CAAM,cAAA,EAAe;AAAA,IAC5C,CAAA;AAAA,IACA,CAAC,QAAQ,oBAAoB;AAAA,GAC/B;AACA,EAAA,OAAO,EAAE,MAAA,EAAQ,oBAAA,EAAsB,KAAA,EAAM;AAC/C;AAEO,IAAM,uBAAuB,CAAC;AAAA,EACnC,KAAA;AAAA,EACA;AACF,CAAA,qBAGM,GAAA,CAAC,mBAAA,CAAoB,QAAA,EAApB,EAA6B,OAAe,QAAA,EAAS;AAOrD,IAAM,cAAA,GAAiB,CAAC,IAAA,KAAkB;AAC/C,EAAA,MAAM,MAAA,GAAS,WAAW,mBAAmB,CAAA;AAC7C,EAAA,yBAAA,CAA0B,MAAM;AAC9B,IAAA,IAAI,CAAC,IAAA,EAAM;AACX,IAAA,MAAM,wBAAQ,MAAA,EAAO;AACrB,IAAA,MAAA,CAAO,IAAI,KAAK,CAAA;AAChB,IAAA,OAAO,MAAM;AACX,MAAA,MAAA,CAAO,OAAO,KAAK,CAAA;AAAA,IACrB,CAAA;AAAA,EACF,CAAA,EAAG,CAAC,IAAA,EAAM,MAAM,CAAC,CAAA;AACnB;AAIO,IAAM,WAAA,GAAc,CAAC,EAAE,IAAA,EAAK,KAAyB;AAC1D,EAAA,cAAA,CAAe,IAAI,CAAA;AACnB,EAAA,OAAO,IAAA;AACT;AAOO,IAAM,kBAAkB,MAAuB;AACpD,EAAA,MAAM,MAAA,GAAS,WAAW,mBAAmB,CAAA;AAC7C,EAAA,OAAO,YAAY,MAAM,MAAA,CAAO,OAAO,CAAA,EAAG,CAAC,MAAM,CAAC,CAAA;AACpD","file":"chunk-H7WOMZXO.js","sourcesContent":["\"use client\"\n\nimport { createContext, type ReactNode, useCallback, useContext, useRef } from \"react\"\nimport { useIsomorphicLayoutEffect } from \"./use-isomorphic-layout-effect\"\n\n/**\n * One outside click dismisses one layer.\n *\n * Every dismissable surface (zag's `trackDismissableElement`) listens for\n * pointerdown on the whole document and closes itself when the target falls\n * outside it. Nested layers don't coordinate: a click on a Modal's backdrop\n * while a DatePicker inside it is open lands outside *both*, so both close —\n * the picker and the dialog the user was filling in. Zag only spares the\n * parent when the child is pointer-blocking (pickers aren't) or was removed a\n * tick earlier (the parent's listener runs first, so it never is), and its\n * `layerStack` isn't exported for us to ask.\n *\n * So the kit tracks it itself. A parent (`Modal`, `Drawer`, `Popover`) owns a\n * set of open children and vetoes its own outside-dismiss while that set is\n * non-empty; every floating panel registers with its nearest parent while\n * open. The click that would have cascaded closes the innermost layer only,\n * and the next one closes the parent.\n *\n * Context rather than DOM queries because context crosses portals: the\n * registration reaches the right parent wherever the panel was portaled to —\n * the parent's positioner, `document.body`, a custom `container`, or nowhere\n * (`withinPortal={false}`).\n *\n * Pointer-down only. Escape is already top-most-only in zag, and focus can't\n * leave a modal for a sibling layer it doesn't own.\n *\n * The same sets answer a second question: is anything open above me? A\n * component reads its nearest set with `useLayerCovered` (that is how\n * `useHotkey` yields to an overlay). Outside every overlay, the nearest set is\n * the page's own: `Modal` and `Drawer` register into it while open just like a\n * picker does, so a page-level reader sees them, and a reader inside a Modal\n * sees only what opened from that Modal.\n */\nexport type OverlayLayers = Set<symbol>\n\n/** The page's set: what a layer registers into when no overlay encloses it.\n * Nothing guards it (the page has no outside to dismiss), it only counts. */\nconst PAGE_LAYERS: OverlayLayers = new Set()\n\nconst OverlayLayerContext = createContext<OverlayLayers>(PAGE_LAYERS)\n\n/** For a parent layer. Spread `onPointerDownOutside` onto the Ark root\n * (composed with the caller's own) and wrap the children that may open nested\n * layers in `OverlayLayerProvider`. A ref'd set, not state: it's read synchronously while\n * zag dispatches the outside event, and changing it must not re-render. */\nexport const useLayerGuard = <E extends Event>(onPointerDownOutside?: (event: E) => void) => {\n const layers = useRef<OverlayLayers>(new Set()).current\n const guard = useCallback(\n (event: E) => {\n onPointerDownOutside?.(event)\n if (layers.size > 0) event.preventDefault()\n },\n [layers, onPointerDownOutside],\n )\n return { layers, onPointerDownOutside: guard }\n}\n\nexport const OverlayLayerProvider = ({\n value,\n children,\n}: {\n value: OverlayLayers\n children?: ReactNode\n}) => <OverlayLayerContext.Provider value={value}>{children}</OverlayLayerContext.Provider>\n\n/** For a child layer: registers with the nearest parent (the page's set when\n * none encloses it) while `open`. Keyed on\n * `open`, not presence, so a panel playing its exit animation no longer holds\n * the parent's next click. A layout effect so the registration is in place\n * before the browser can deliver the next pointerdown. */\nexport const useNestedLayer = (open: boolean) => {\n const parent = useContext(OverlayLayerContext)\n useIsomorphicLayoutEffect(() => {\n if (!open) return\n const token = Symbol()\n parent.add(token)\n return () => {\n parent.delete(token)\n }\n }, [open, parent])\n}\n\n/** `useNestedLayer` as an element, for call sites that only have the machine's\n * `open` inside a render prop (`<Ark.Context>{(api) => …}</Ark.Context>`). */\nexport const NestedLayer = ({ open }: { open: boolean }) => {\n useNestedLayer(open)\n return null\n}\n\n/** Whether a layer is open above the component calling this, right now: a\n * Modal, Drawer, Popover or picker that opened from the same layer (from the\n * page, for a component outside every overlay). Returns a reader, not a\n * value, so it is checked when it matters (a key press) and opening a layer\n * never re-renders the caller. */\nexport const useLayerCovered = (): (() => boolean) => {\n const layers = useContext(OverlayLayerContext)\n return useCallback(() => layers.size > 0, [layers])\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/modal/modal.tsx"],"names":["Ark"],"mappings":";;;;;;;;;;;;AA2CA,IAAM,gBAAgB,GAAA,CAAI;AAAA,EACxB,8HAAA;AAAA,EACA;AACF,CAAC,CAAA;AAED,IAAM,eAAA,GAAkB,GAAA;AAAA,EACtB,gHAAA;AAAA,EACA;AAAA,IACE,QAAA,EAAU;AAAA,MACR,QAAA,EAAU;AAAA,QACR,MAAA,EAAQ,gBAAA;AAAA,QACR,GAAA,EAAK,wBAAA;AAAA,QACL,MAAA,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AEO,IAAM,KAAA,GAAQ,MAAA,CAAO,MAAA,CAAO,cAAA,EAAgB;AAAA,EACjD,IAAA,EAAM,SAAA;AAAA,EACN,OAAA,EAAS,YAAA;AAAA,EACT,OAAA,EAAS,YAAA;AAAA,EACT,QAAA,EAAU,aAAA;AAAA,EACV,UAAA,EAAY,eAAA;AAAA,EACZ,OAAA,EAAS,YAAA;AAAA,EACT,KAAA,EAAO,UAAA;AAAA,EACP,WAAA,EAAa,gBAAA;AAAA,EACb,YAAA,EAAc,iBAAA;AAAA,EACd,MAAA,EAAQ,WAAA;AAAA,EACR,IAAA,EAAM,SAAA;AAAA,EACN,MAAA,EAAQ;AACV,CAAC","file":"chunk-N42EFOML.js","sourcesContent":["\"use client\"\n\nimport { Dialog as Ark } from \"@ark-ui/react/dialog\"\nimport { Portal } from \"@ark-ui/react/portal\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport { type ComponentPropsWithoutRef, type ReactNode, useRef } from \"react\"\nimport type { NoAsChild } from \"../../lib/as-child\"\nimport { cn } from \"../../lib/cn\"\nimport { OverlayContainerProvider } from \"../../lib/overlay-container\"\nimport { NestedLayer, useLayerGuard } from \"../../lib/overlay-layer\"\nimport { props } from \"../../lib/props\"\nimport type { Size } from \"../../lib/sizes\"\nimport type { WithTestId } from \"../../lib/test-id\"\nimport { TEXT_COLOR_CLASSES } from \"../../lib/typography-size\"\nimport {\n createDialogParts,\n DIALOG_PADDING,\n type DialogCloseTriggerProps,\n type DialogIconSlot,\n type DialogIcons,\n DialogRootProviders,\n type DialogSectionProps,\n useDialogNameCheck,\n} from \"../overlays/dialog-parts\"\n\n/**\n * Modal — centered overlay dialog on top of Ark UI's Dialog state machine.\n * Ark owns focus-trap, scroll-lock, RTL, the `Esc` / click-outside behaviour\n * and the `data-state=\"open|closed\"` attribute that drives our enter/exit\n * animations (keyframes live in `theme.css`). This wrapper provides the styled\n * parts and a flatter props API.\n *\n * - High-level form: `<Modal open title size … >children</Modal>` renders the\n * full Portal → Backdrop → Positioner → Content → Header + Body scaffold.\n * This is what the imperative overlays manager mounts.\n * - Low-level parts (`Modal.Root`, `Modal.Content`, `Modal.Title`, …) are\n * exposed for full control / trigger-based composition.\n *\n * Surface padding flows through the `--modal-px` CSS var set on the content, so\n * `Modal.Header` / `Modal.Body` / `Modal.Footer` stay in rhythm without prop\n * plumbing — and keep a sensible fallback when used standalone.\n */\n\nconst modalBackdrop = cva([\n \"fixed inset-0 z-[calc(var(--modal-z,150)+var(--layer-index,0))] bg-black/50 backdrop-blur-lg pointer-events-auto select-none\",\n \"data-[state=open]:animate-fade-in data-[state=closed]:animate-fade-out\",\n])\n\nconst modalPositioner = cva(\n \"fixed inset-0 z-[calc(var(--modal-z,150)+var(--layer-index,0))] flex flex-col items-center overflow-y-auto p-4\",\n {\n variants: {\n position: {\n center: \"justify-center\",\n top: \"justify-start mt-[8vh]\",\n bottom: \"justify-end mb-[8vh]\",\n },\n },\n defaultVariants: { position: \"center\" },\n },\n)\n\nconst modalContent = cva(\n [\n \"relative flex w-full flex-col\",\n \"max-h-[calc(100dvh-2rem)]\",\n \"bg-brand-50 text-brand-950 border border-brand-900/20 shadow-2xl\",\n \"dark:bg-brand-950 dark:text-white dark:border-white/15\",\n \"focus:outline-none\",\n \"data-[state=open]:animate-modal-in data-[state=closed]:animate-modal-out\",\n ],\n {\n variants: {\n size: {\n xs: \"max-w-(--width-xs)\", // 24rem\n sm: \"max-w-(--width-sm)\", // 30rem\n md: \"max-w-(--width-md)\", // 35rem\n lg: \"max-w-(--width-lg)\", // 40rem\n xl: \"max-w-(--width-xl)\", // 48rem\n full: \"max-w-[calc(100vw-2rem)] min-h-[calc(100dvh-2rem)]\",\n },\n radius: {\n none: \"rounded-none\",\n sm: \"rounded-sm\",\n md: \"rounded-md\",\n lg: \"rounded-xl\",\n xl: \"rounded-2xl\",\n },\n },\n defaultVariants: { size: \"md\", radius: \"sm\" },\n },\n)\n\n// ---------------------------------------------------------------------------\n// Low-level parts (styled Ark parts + kit conveniences)\n// ---------------------------------------------------------------------------\n\nexport type ModalIconSlot = DialogIconSlot\nexport type ModalIcons = DialogIcons\n\nexport type ModalRootProps = ComponentPropsWithoutRef<typeof Ark.Root> & {\n /** Replaces the default icons: `close`. `Modal.CloseTrigger`'s `children` win over it. */\n icons?: ModalIcons\n}\n\n/** Ark's root, plus the nested-layer guard: while a picker opened inside the\n * dialog is open, an outside click closes the picker only, not the dialog\n * under it. It is also a layer of its own while open, so a hotkey on the page\n * (or in an enclosing overlay) yields to it. See `lib/overlay-layer.tsx`. */\nconst ModalRoot = ({ onPointerDownOutside, icons, children, ...rest }: ModalRootProps) => {\n const guard = useLayerGuard(onPointerDownOutside)\n return (\n <Ark.Root onPointerDownOutside={guard.onPointerDownOutside} {...rest}>\n {/* A layer itself, registered with whatever it opened from (the page,\n or an enclosing overlay), so what's under it knows it's covered. */}\n <Ark.Context>{(api) => <NestedLayer open={api.open} />}</Ark.Context>\n <DialogRootProviders icons={icons} layers={guard.layers}>\n {children}\n </DialogRootProviders>\n </Ark.Root>\n )\n}\nconst ModalTrigger = Ark.Trigger\nconst ModalContext = Ark.Context\n\nexport type ModalBackdropProps = ComponentPropsWithoutRef<typeof Ark.Backdrop> & WithTestId\n\nconst ModalBackdrop = ({ className, testId, ...rest }: ModalBackdropProps) => (\n <Ark.Backdrop\n className={cn(modalBackdrop(), className)}\n {...props({ \"data-testid\": testId })}\n {...rest}\n />\n)\n\nexport type ModalPosition = VariantProps<typeof modalPositioner>[\"position\"]\nexport type ModalPositionerProps = NoAsChild<ComponentPropsWithoutRef<typeof Ark.Positioner>> &\n WithTestId & {\n position?: ModalPosition\n }\n\nconst ModalPositioner = ({\n className,\n position,\n testId,\n children,\n asChild: _asChild,\n ...rest\n}: ModalPositionerProps) => {\n // A ref, not state: overlays read it when they portal, so nothing has to\n // re-render once it attaches (see `lib/overlay-container.tsx`).\n const positioner = useRef<HTMLDivElement>(null)\n return (\n <Ark.Positioner\n ref={positioner}\n className={cn(modalPositioner({ position }), className)}\n {...props({ \"data-testid\": testId })}\n {...rest}\n >\n <OverlayContainerProvider value={positioner}>{children}</OverlayContainerProvider>\n </Ark.Positioner>\n )\n}\n\nexport type ModalContentProps = ComponentPropsWithoutRef<typeof Ark.Content> &\n VariantProps<typeof modalContent> &\n WithTestId\n\nconst ModalContent = ({ className, size, radius, testId, ...rest }: ModalContentProps) => {\n const nameCheck = useDialogNameCheck(\"Modal\")\n return (\n <Ark.Content\n ref={nameCheck}\n className={cn(modalContent({ size, radius }), className)}\n {...props({ \"data-testid\": testId })}\n {...rest}\n />\n )\n}\n\nexport type ModalTitleProps = ComponentPropsWithoutRef<typeof Ark.Title> & WithTestId\n\nconst ModalTitle = ({ className, testId, ...rest }: ModalTitleProps) => (\n <Ark.Title\n className={cn(\"text-xl font-semibold leading-tight\", className)}\n {...props({ \"data-testid\": testId })}\n {...rest}\n />\n)\n\nexport type ModalDescriptionProps = ComponentPropsWithoutRef<typeof Ark.Description> & WithTestId\n\nconst ModalDescription = ({ className, testId, ...rest }: ModalDescriptionProps) => (\n <Ark.Description\n className={cn(\"text-sm\", TEXT_COLOR_CLASSES.muted, className)}\n {...props({ \"data-testid\": testId })}\n {...rest}\n />\n)\n\nexport type ModalCloseTriggerProps = DialogCloseTriggerProps\nexport type ModalHeaderProps = DialogSectionProps\nexport type ModalBodyProps = DialogSectionProps\nexport type ModalFooterProps = DialogSectionProps\n\nconst {\n CloseTrigger: ModalCloseTrigger,\n Header: ModalHeader,\n Body: ModalBody,\n Footer: ModalFooter,\n} = createDialogParts(\"modal\", Ark.CloseTrigger)\n\n// ---------------------------------------------------------------------------\n// High-level props-driven Modal\n// ---------------------------------------------------------------------------\n\ntype ArkRootProps = ComponentPropsWithoutRef<typeof Ark.Root>\n\nexport type ModalSize = NonNullable<VariantProps<typeof modalContent>[\"size\"]>\nexport type ModalRadius = NonNullable<VariantProps<typeof modalContent>[\"radius\"]>\n\nexport type ModalClassNames = Partial<\n Record<\n | \"backdrop\"\n | \"positioner\"\n | \"content\"\n | \"header\"\n | \"title\"\n | \"description\"\n | \"body\"\n | \"closeButton\",\n string\n >\n>\n\nexport type ModalProps = Omit<\n ArkRootProps,\n \"open\" | \"defaultOpen\" | \"onOpenChange\" | \"children\" | \"role\"\n> &\n WithTestId & {\n /** Controlled open state. */\n open?: boolean\n /** Uncontrolled initial open state. */\n defaultOpen?: boolean\n /** Fires with the next open state. Flattened from Ark's `{ open }`. */\n onOpenChange?: (open: boolean) => void\n /** Header title; renders the header when set, and names the dialog. */\n title?: ReactNode\n /** Id of an element inside the modal that names it, when there is no `title`. For a\n * plain string, use `aria-label`. */\n \"aria-labelledby\"?: string\n /** Optional subtitle under the title. */\n description?: ReactNode\n size?: ModalSize\n radius?: ModalRadius\n /** Vertically center the modal (vs. anchored near the top). */\n position?: ModalPosition\n /** Render the default close button in the header. @default true */\n withCloseButton?: boolean\n /**\n * Render the dimming backdrop. Set `false` when an ancestor (e.g. the modals\n * manager) draws a single shared backdrop for the whole overlay stack.\n * @default true\n */\n withBackdrop?: boolean\n /** Inner padding token; sets `--modal-px`. @default \"md\" */\n padding?: Size\n closeOnEscape?: boolean\n closeOnInteractOutside?: boolean\n /** Use `alertdialog` semantics (confirm flows). @default \"dialog\" */\n role?: \"dialog\" | \"alertdialog\"\n /** Fires after the exit animation completes; the manager unmounts on this. */\n onExitComplete?: () => void\n /** Fires on close (any source) */\n onClose?: () => void\n /** Portal target. Defaults to `document.body`. */\n container?: HTMLElement | null\n children?: ReactNode\n className?: string\n classNames?: ModalClassNames\n /** Overrides the default close button's accessible name (`closeTriggerLabel`, default\n * `\"Close\"`). The compound `ModalCloseTrigger` part takes a plain `aria-label` instead. */\n translations?: ModalTranslations\n /** Replaces the default icons: `close`, the header's close button. */\n icons?: ModalIcons\n }\n\n/** The ready-made modal's wording — `closeTriggerLabel` follows Ark's naming for the\n * same control. */\nexport type ModalTranslations = { closeTriggerLabel?: string }\n\nconst ModalComponent = ({\n open,\n defaultOpen,\n onOpenChange,\n onClose,\n title,\n description,\n \"aria-labelledby\": ariaLabelledby,\n size,\n radius,\n position,\n withCloseButton = true,\n withBackdrop = true,\n padding = \"md\",\n closeOnEscape,\n closeOnInteractOutside,\n role,\n onExitComplete,\n container,\n children,\n className,\n classNames,\n testId,\n translations,\n icons,\n ...rest\n}: ModalProps) => {\n const hasHeader = title != null || description != null || withCloseButton\n\n return (\n <ModalRoot\n open={open}\n defaultOpen={defaultOpen}\n onOpenChange={({ open: next }) => {\n onOpenChange?.(next)\n if (!next) onClose?.()\n }}\n closeOnEscape={closeOnEscape}\n // Decoupled from `modal` on purpose: Ark's dialog derives this default\n // from `modal` (`modal && !alertdialog`), so when the overlays manager\n // draws its own shared backdrop and passes `withBackdrop={false}` —\n // forcing `modal={false}` below — outside-click would silently stop\n // dismissing. Default to Ark's intended behaviour instead: dismiss for\n // regular dialogs, keep `alertdialog`s sticky (explicit choice required).\n closeOnInteractOutside={closeOnInteractOutside ?? role !== \"alertdialog\"}\n role={role}\n // Unmount the whole content tree (incl. the `fixed inset-0` positioner)\n // on close — otherwise the positioner lingers as a transparent overlay\n // that swallows page clicks. `lazyMount` keeps it out of the DOM until\n // first open. Both flow to the parts' presence via Ark's Root context.\n lazyMount\n unmountOnExit\n modal={withBackdrop}\n onExitComplete={onExitComplete}\n icons={icons}\n {...rest}\n >\n <Portal container={container ? { current: container } : undefined}>\n {withBackdrop && <ModalBackdrop className={classNames?.backdrop} />}\n <ModalPositioner\n position={position}\n className={cn(\"overflow-clip\", classNames?.positioner)}\n >\n <ModalContent\n size={size}\n radius={radius}\n style={{ [\"--modal-px\" as string]: DIALOG_PADDING[padding] }}\n className={cn(className, classNames?.content)}\n testId={testId}\n aria-labelledby={ariaLabelledby}\n >\n {hasHeader && (\n <ModalHeader className={classNames?.header}>\n <div className=\"flex flex-col gap-1\">\n {title != null && <ModalTitle className={classNames?.title}>{title}</ModalTitle>}\n {description != null && (\n <ModalDescription className={classNames?.description}>\n {description}\n </ModalDescription>\n )}\n </div>\n {withCloseButton && (\n <ModalCloseTrigger\n aria-label={translations?.closeTriggerLabel}\n className={classNames?.closeButton}\n />\n )}\n </ModalHeader>\n )}\n <ModalBody\n className={cn(\n !hasHeader && \"pt-(--modal-px,1.25rem)\",\n \"pb-(--modal-px,1.25rem)\",\n classNames?.body,\n )}\n >\n {children}\n </ModalBody>\n </ModalContent>\n </ModalPositioner>\n </Portal>\n </ModalRoot>\n )\n}\n\nexport const Modal = Object.assign(ModalComponent, {\n Root: ModalRoot,\n Trigger: ModalTrigger,\n Context: ModalContext,\n Backdrop: ModalBackdrop,\n Positioner: ModalPositioner,\n Content: ModalContent,\n Title: ModalTitle,\n Description: ModalDescription,\n CloseTrigger: ModalCloseTrigger,\n Header: ModalHeader,\n Body: ModalBody,\n Footer: ModalFooter,\n})\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/drawer/drawer.tsx"],"names":["Ark"],"mappings":";;;;;;;;;;;;AAiDA,IAAM,kBAAA,GAAqB;AAAA,EACzB,KAAA,EAAO,OAAA;AAAA,EACP,GAAA,EAAK,KAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,MAAA,EAAQ;AACV,CAAA;AAGA,IAAM,sBAAA,GAAyB,cAA+B,KAAK,CAAA;AAEnE,IAAM,iBAAiB,GAAA,CAAI;AAAA,EACzB,8HAAA;AAAA,EACA;AACF,CAAC,CAAA;AAED,IAAM,gBAAA,GAAmB,GAAA;AAAA,EACvB,oFAAA;AAAA,EACA;AAAA,IACE,QAAA,EAAU;AAAA,MACR,SAAA,EAAW;AAAA,QACT,KAAA,EAAO,6BAAA;AAAA,QACP,GAAA,EAAK,2BAAA;AAAA,QACL,GAAA,EAAK,6BAAA;AAAA,QACL,MAAA,EAAQ;AAAA;AACV,KACF;AAAA,IACA,eAAA,EAAiB,EAAE,SAAA,EAAW,KAAA;AAAM;AAExC,CAAA;AASA,IAAM,mBAAmB,CAAC;AAAA,EACxB,SAAA;AAAA,EACA,Q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,EAAY,gBAAA;AAAA,EACZ,OAAA,EAAS,aAAA;AAAA,EACT,KAAA,EAAO,WAAA;AAAA,EACP,WAAA,EAAa,iBAAA;AAAA,EACb,YAAA,EAAc,kBAAA;AAAA,EACd,OAAA,EAAS,aAAA;AAAA,EACT,MAAA,EAAQ,YAAA;AAAA,EACR,IAAA,EAAM,UAAA;AAAA,EACN,MAAA,EAAQ;AACV,CAAC","file":"chunk-YMVUQ2L7.js","sourcesContent":["\"use client\"\n\nimport { Drawer as Ark } from \"@ark-ui/react/drawer\"\nimport { Portal } from \"@ark-ui/react/portal\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport {\n type ComponentPropsWithoutRef,\n createContext,\n type ReactNode,\n useContext,\n useRef,\n} from \"react\"\nimport type { NoAsChild } from \"../../lib/as-child\"\nimport { cn } from \"../../lib/cn\"\nimport { OverlayContainerProvider } from \"../../lib/overlay-container\"\nimport { NestedLayer, useLayerGuard } from \"../../lib/overlay-layer\"\nimport { props } from \"../../lib/props\"\nimport type { Size } from \"../../lib/sizes\"\nimport type { WithTestId } from \"../../lib/test-id\"\nimport { TEXT_COLOR_CLASSES } from \"../../lib/typography-size\"\nimport {\n createDialogParts,\n DIALOG_PADDING,\n type DialogCloseTriggerProps,\n type DialogIconSlot,\n type DialogIcons,\n DialogRootProviders,\n type DialogSectionProps,\n useDialogNameCheck,\n} from \"../overlays/dialog-parts\"\n\n/**\n * Drawer — edge-anchored panel on top of Ark UI's Drawer state machine. Ark\n * owns swipe-to-dismiss, snap points, focus-trap, scroll-lock and the\n * `data-state=\"open|closed\"` attribute; this wrapper adds an RTL-aware\n * `placement` (Ark has none). It is set once, on `Drawer.Root`, which derives\n * Ark's logical `swipeDirection` from it and shares it with the parts through\n * context; the positioner and content write it as `data-placement`. The slide\n * animation and the docked border are pure CSS keyed on `[data-placement]`\n * (see `theme.css`), so `start`/`end` flip automatically under `dir=\"rtl\"`.\n *\n * Mirrors `Modal`'s dual API: high-level `<Drawer open placement size … >` plus\n * low-level parts (`Drawer.Root`, `Drawer.Content`, …). Padding flows through\n * the `--drawer-px` CSS var.\n */\n\nexport type DrawerPlacement = \"start\" | \"end\" | \"top\" | \"bottom\"\n\n/** placement → Ark logical swipe axis (RTL handled by Ark for start/end). */\nconst PLACEMENT_TO_SWIPE = {\n start: \"start\",\n end: \"end\",\n top: \"up\",\n bottom: \"down\",\n} as const\n\n/** The root's placement, so the parts dock themselves without repeating it. */\nconst DrawerPlacementContext = createContext<DrawerPlacement>(\"end\")\n\nconst drawerBackdrop = cva([\n \"fixed inset-0 z-[calc(var(--modal-z,150)+var(--layer-index,0))] bg-black/50 backdrop-blur-lg pointer-events-auto select-none\",\n \"data-[state=open]:animate-fade-in data-[state=closed]:animate-fade-out\",\n])\n\nconst drawerPositioner = cva(\n \"fixed inset-0 z-[calc(var(--modal-z,150)+var(--layer-index,0))] flex overflow-clip\",\n {\n variants: {\n placement: {\n start: \"items-stretch justify-start\",\n end: \"items-stretch justify-end\",\n top: \"items-start justify-stretch\",\n bottom: \"items-end justify-stretch\",\n },\n },\n defaultVariants: { placement: \"end\" },\n },\n)\n\nexport type DrawerPositionerProps = NoAsChild<ComponentPropsWithoutRef<typeof Ark.Positioner>> &\n WithTestId\n\n/** Docks itself to the root's `placement`. Publishes itself as the portal\n * target for any overlay opened inside the drawer, so a Menu/Select/DatePicker\n * in a drawer body stays above the panel instead of behind it. See\n * `lib/overlay-container.tsx`. */\nconst DrawerPositioner = ({\n className,\n children,\n testId,\n asChild: _asChild,\n ...rest\n}: DrawerPositionerProps) => {\n const placement = useContext(DrawerPlacementContext)\n const positioner = useRef<HTMLDivElement>(null)\n return (\n <Ark.Positioner\n ref={positioner}\n className={cn(drawerPositioner({ placement }), className)}\n {...props({ \"data-testid\": testId })}\n {...rest}\n data-placement={placement}\n >\n <OverlayContainerProvider value={positioner}>{children}</OverlayContainerProvider>\n </Ark.Positioner>\n )\n}\n\nconst drawerContent = cva(\n [\n \"relative flex flex-col overflow-hidden\",\n \"bg-brand-50 text-brand-950 shadow-2xl\",\n \"dark:bg-brand-950 dark:text-white\",\n \"focus:outline-none\",\n // border on the docked edge only — keyed by data-placement in theme.css\n \"data-[placement=start]:border-e data-[placement=end]:border-s\",\n \"data-[placement=top]:border-b data-[placement=bottom]:border-t\",\n \"border-brand-900/20 dark:border-white/15\",\n \"data-[state=open]:animate-drawer-in data-[state=closed]:animate-drawer-out\",\n ],\n {\n variants: {\n // Internal: Content reads it from the root's context.\n placement: {\n start: \"h-full max-w-[90vw]\",\n end: \"h-full max-w-[90vw]\",\n top: \"w-full max-h-[90dvh]\",\n bottom: \"w-full max-h-[90dvh]\",\n },\n // Width for inline placements, height for block ones: see compoundVariants.\n size: { xs: \"\", sm: \"\", md: \"\", lg: \"\", xl: \"\" },\n // Only the two corners away from the docked edge round: see compoundVariants.\n radius: { none: \"\", sm: \"\", md: \"\", lg: \"\", xl: \"\" },\n },\n compoundVariants: [\n { placement: [\"start\", \"end\"], size: \"xs\", class: \"w-[18rem]\" },\n { placement: [\"start\", \"end\"], size: \"sm\", class: \"w-[22rem]\" },\n { placement: [\"start\", \"end\"], size: \"md\", class: \"w-[28rem]\" },\n { placement: [\"start\", \"end\"], size: \"lg\", class: \"w-[34rem]\" },\n { placement: [\"start\", \"end\"], size: \"xl\", class: \"w-[42rem]\" },\n { placement: [\"top\", \"bottom\"], size: \"xs\", class: \"h-[30dvh]\" },\n { placement: [\"top\", \"bottom\"], size: \"sm\", class: \"h-[40dvh]\" },\n { placement: [\"top\", \"bottom\"], size: \"md\", class: \"h-[55dvh]\" },\n { placement: [\"top\", \"bottom\"], size: \"lg\", class: \"h-[70dvh]\" },\n { placement: [\"top\", \"bottom\"], size: \"xl\", class: \"h-[85dvh]\" },\n // Logical corners, so `start`/`end` mirror under RTL with the panel.\n { placement: \"start\", radius: \"sm\", class: \"rounded-e-sm\" },\n { placement: \"start\", radius: \"md\", class: \"rounded-e-md\" },\n { placement: \"start\", radius: \"lg\", class: \"rounded-e-xl\" },\n { placement: \"start\", radius: \"xl\", class: \"rounded-e-2xl\" },\n { placement: \"end\", radius: \"sm\", class: \"rounded-s-sm\" },\n { placement: \"end\", radius: \"md\", class: \"rounded-s-md\" },\n { placement: \"end\", radius: \"lg\", class: \"rounded-s-xl\" },\n { placement: \"end\", radius: \"xl\", class: \"rounded-s-2xl\" },\n { placement: \"top\", radius: \"sm\", class: \"rounded-b-sm\" },\n { placement: \"top\", radius: \"md\", class: \"rounded-b-md\" },\n { placement: \"top\", radius: \"lg\", class: \"rounded-b-xl\" },\n { placement: \"top\", radius: \"xl\", class: \"rounded-b-2xl\" },\n { placement: \"bottom\", radius: \"sm\", class: \"rounded-t-sm\" },\n { placement: \"bottom\", radius: \"md\", class: \"rounded-t-md\" },\n { placement: \"bottom\", radius: \"lg\", class: \"rounded-t-xl\" },\n { placement: \"bottom\", radius: \"xl\", class: \"rounded-t-2xl\" },\n ],\n defaultVariants: { placement: \"end\", size: \"md\", radius: \"none\" },\n },\n)\n\n// ---------------------------------------------------------------------------\n// Low-level parts\n// ---------------------------------------------------------------------------\n\nexport type DrawerIconSlot = DialogIconSlot\nexport type DrawerIcons = DialogIcons\n\nexport type DrawerRootProps = ComponentPropsWithoutRef<typeof Ark.Root> & {\n /** RTL-aware docking edge, shared with `Drawer.Positioner` and `Drawer.Content`. Also\n * sets Ark's `swipeDirection`, unless you pass one. @default \"end\" */\n placement?: DrawerPlacement\n /** Replaces the default icons: `close`. `Drawer.CloseTrigger`'s `children` win over it. */\n icons?: DrawerIcons\n}\n\n/** Ark's root, plus the nested-layer guard: while a picker opened inside the\n * drawer is open, an outside click closes the picker only, not the drawer\n * under it. It is also a layer of its own while open, so a hotkey on the page\n * (or in an enclosing overlay) yields to it. See `lib/overlay-layer.tsx`. */\nconst DrawerRoot = ({\n placement = \"end\",\n swipeDirection,\n onPointerDownOutside,\n icons,\n children,\n ...rest\n}: DrawerRootProps) => {\n const guard = useLayerGuard(onPointerDownOutside)\n return (\n <Ark.Root\n swipeDirection={swipeDirection ?? PLACEMENT_TO_SWIPE[placement]}\n onPointerDownOutside={guard.onPointerDownOutside}\n {...rest}\n >\n {/* A layer itself, registered with whatever it opened from (the page,\n or an enclosing overlay), so what's under it knows it's covered. */}\n <Ark.Context>{(api) => <NestedLayer open={api.open} />}</Ark.Context>\n <DrawerPlacementContext value={placement}>\n <DialogRootProviders icons={icons} layers={guard.layers}>\n {children}\n </DialogRootProviders>\n </DrawerPlacementContext>\n </Ark.Root>\n )\n}\nconst DrawerTrigger = Ark.Trigger\nconst DrawerContext = Ark.Context\n\nexport type DrawerBackdropProps = ComponentPropsWithoutRef<typeof Ark.Backdrop> & WithTestId\n\nconst DrawerBackdrop = ({ className, testId, ...rest }: DrawerBackdropProps) => (\n <Ark.Backdrop\n className={cn(drawerBackdrop(), className)}\n {...props({ \"data-testid\": testId })}\n {...rest}\n />\n)\n\nexport type DrawerTitleProps = ComponentPropsWithoutRef<typeof Ark.Title> & WithTestId\n\nconst DrawerTitle = ({ className, testId, ...rest }: DrawerTitleProps) => (\n <Ark.Title\n className={cn(\"text-xl font-semibold leading-tight\", className)}\n {...props({ \"data-testid\": testId })}\n {...rest}\n />\n)\n\nexport type DrawerDescriptionProps = ComponentPropsWithoutRef<typeof Ark.Description> & WithTestId\n\nconst DrawerDescription = ({ className, testId, ...rest }: DrawerDescriptionProps) => (\n <Ark.Description\n className={cn(\"text-sm\", TEXT_COLOR_CLASSES.muted, className)}\n {...props({ \"data-testid\": testId })}\n {...rest}\n />\n)\n\nexport type DrawerSize = NonNullable<VariantProps<typeof drawerContent>[\"size\"]>\nexport type DrawerRadius = NonNullable<VariantProps<typeof drawerContent>[\"radius\"]>\n\nexport type DrawerContentProps = ComponentPropsWithoutRef<typeof Ark.Content> &\n WithTestId & {\n /** Width for `start`/`end` drawers, height for `top`/`bottom` ones. @default \"md\" */\n size?: DrawerSize\n /** Rounds the two corners away from the docked edge. @default \"none\" */\n radius?: DrawerRadius\n }\n\n/** The panel. It sizes and rounds itself for the root's `placement`, and writes\n * it as `data-placement`, which the slide animation and the docked border key on. */\nconst DrawerContent = ({ className, size, radius, testId, ...rest }: DrawerContentProps) => {\n const placement = useContext(DrawerPlacementContext)\n const nameCheck = useDialogNameCheck(\"Drawer\")\n return (\n <Ark.Content\n ref={nameCheck}\n className={cn(drawerContent({ placement, size, radius }), className)}\n {...props({ \"data-testid\": testId })}\n {...rest}\n data-placement={placement}\n />\n )\n}\n\nexport type DrawerCloseTriggerProps = DialogCloseTriggerProps\nexport type DrawerHeaderProps = DialogSectionProps\nexport type DrawerBodyProps = DialogSectionProps\nexport type DrawerFooterProps = DialogSectionProps\n\nconst {\n CloseTrigger: DrawerCloseTrigger,\n Header: DrawerHeader,\n Body: DrawerBody,\n Footer: DrawerFooter,\n} = createDialogParts(\"drawer\", Ark.CloseTrigger)\n\nexport type DrawerGrabberProps = NoAsChild<ComponentPropsWithoutRef<typeof Ark.Grabber>> &\n WithTestId\n\nconst DrawerGrabber = ({ className, testId, asChild: _asChild, ...rest }: DrawerGrabberProps) => (\n <Ark.Grabber\n className={cn(\n \"flex shrink-0 cursor-grab touch-none items-center justify-center py-2\",\n className,\n )}\n {...props({ \"data-testid\": testId })}\n {...rest}\n >\n <Ark.GrabberIndicator className=\"h-1.5 w-20 rounded-full bg-brand-900/10 dark:bg-white/16\" />\n </Ark.Grabber>\n)\n\n// ---------------------------------------------------------------------------\n// High-level props-driven Drawer\n// ---------------------------------------------------------------------------\n\ntype ArkRootProps = ComponentPropsWithoutRef<typeof Ark.Root>\n\nexport type DrawerClassNames = Partial<\n Record<\n | \"backdrop\"\n | \"positioner\"\n | \"content\"\n | \"header\"\n | \"title\"\n | \"description\"\n | \"body\"\n | \"grabber\"\n | \"closeButton\",\n string\n >\n>\n\nexport type DrawerProps = Omit<\n ArkRootProps,\n \"open\" | \"defaultOpen\" | \"onOpenChange\" | \"children\" | \"swipeDirection\" | \"role\"\n> &\n WithTestId & {\n /** Controlled open state. */\n open?: boolean\n /** Uncontrolled initial open state. */\n defaultOpen?: boolean\n /** Fires with the next open state. Flattened from Ark's `{ open }`. */\n onOpenChange?: (open: boolean) => void\n /** Fires on close (any source) — Escape, backdrop click, swipe, or a controlled `onOpenChange`. */\n onClose?: () => void\n /** RTL-aware docking edge. @default \"end\" */\n placement?: DrawerPlacement\n /** Width for `start`/`end` drawers, height for `top`/`bottom` ones. @default \"md\" */\n size?: DrawerSize\n /** Rounds the two corners away from the docked edge. @default \"none\" */\n radius?: DrawerRadius\n /** Header title; also the drawer's accessible name. */\n title?: ReactNode\n description?: ReactNode\n /** Accessible name for a drawer without a `title` (a navigation panel, say). */\n \"aria-label\"?: string\n /** Id of an element inside the drawer that names it, when there is no `title`. */\n \"aria-labelledby\"?: string\n /** Render the default close button in the header. @default true */\n withCloseButton?: boolean\n /** Show the drag grabber handle. @default false */\n withGrabber?: boolean\n /**\n * Render the dimming backdrop. Set `false` when an ancestor (e.g. the modals\n * manager) draws a single shared backdrop for the whole overlay stack.\n * @default true\n */\n withBackdrop?: boolean\n /** Inner padding token; sets `--drawer-px`. @default \"md\" */\n padding?: Size\n closeOnEscape?: boolean\n /** Close on a click outside the drawer. @default true, false for an `alertdialog` */\n closeOnInteractOutside?: boolean\n /** Use `alertdialog` semantics (confirm flows). @default \"dialog\" */\n role?: \"dialog\" | \"alertdialog\"\n /** Fires after the exit animation completes — the manager unmounts on this. */\n onExitComplete?: () => void\n /** Portal target. Defaults to `document.body`. */\n container?: HTMLElement | null\n children?: ReactNode\n className?: string\n classNames?: DrawerClassNames\n /** Overrides the default close button's accessible name (`closeTriggerLabel`, default\n * `\"Close\"`). The compound `DrawerCloseTrigger` part takes a plain `aria-label` instead. */\n translations?: DrawerTranslations\n /** Replaces the default icons: `close`, the header's close button. */\n icons?: DrawerIcons\n }\n\n/** The ready-made drawer's wording — `closeTriggerLabel` follows Ark's naming for the\n * same control. */\nexport type DrawerTranslations = { closeTriggerLabel?: string }\n\nconst DrawerComponent = ({\n open,\n defaultOpen,\n onOpenChange,\n onClose,\n placement = \"end\",\n size,\n radius,\n title,\n description,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledby,\n withCloseButton = true,\n withGrabber = false,\n withBackdrop = true,\n padding = \"md\",\n closeOnEscape,\n closeOnInteractOutside,\n role,\n onExitComplete,\n container,\n children,\n className,\n classNames,\n testId,\n translations,\n icons,\n ...rest\n}: DrawerProps) => {\n const hasHeader = title != null || description != null || withCloseButton\n\n return (\n <DrawerRoot\n open={open}\n defaultOpen={defaultOpen}\n onOpenChange={({ open: next }) => {\n onOpenChange?.(next)\n if (!next) onClose?.()\n }}\n placement={placement}\n closeOnEscape={closeOnEscape}\n // Spelled out to match Modal, whose Ark dialog derives this default from\n // `modal` (so the overlays manager's `withBackdrop={false}` would stop\n // outside clicks there). Ark's drawer defaults it to `true` for every role\n // instead, so here the one behaviour this changes is the `alertdialog`:\n // it stays sticky, as on Modal, unless the caller opts in explicitly.\n closeOnInteractOutside={closeOnInteractOutside ?? role !== \"alertdialog\"}\n role={role}\n // Unmount the whole content tree (incl. the `fixed inset-0` positioner)\n // on close — otherwise the positioner lingers as a transparent overlay\n // that swallows page clicks. `lazyMount` keeps it out of the DOM until\n // first open.\n lazyMount\n unmountOnExit\n modal={withBackdrop}\n onExitComplete={onExitComplete}\n icons={icons}\n {...rest}\n >\n <Portal container={container ? { current: container } : undefined}>\n {withBackdrop && <DrawerBackdrop className={classNames?.backdrop} />}\n <DrawerPositioner className={classNames?.positioner}>\n <DrawerContent\n size={size}\n radius={radius}\n style={{ [\"--drawer-px\" as string]: DIALOG_PADDING[padding] }}\n className={cn(className, classNames?.content)}\n testId={testId}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledby}\n >\n {withGrabber && <DrawerGrabber className={classNames?.grabber} />}\n {hasHeader && (\n <DrawerHeader className={classNames?.header}>\n <div className=\"flex flex-col gap-1\">\n {title != null && (\n <DrawerTitle className={classNames?.title}>{title}</DrawerTitle>\n )}\n {description != null && (\n <DrawerDescription className={classNames?.description}>\n {description}\n </DrawerDescription>\n )}\n </div>\n {withCloseButton && (\n <DrawerCloseTrigger\n aria-label={translations?.closeTriggerLabel}\n className={classNames?.closeButton}\n />\n )}\n </DrawerHeader>\n )}\n <DrawerBody\n className={cn(\n !hasHeader && !withGrabber && \"pt-(--drawer-px,1.25rem)\",\n \"pb-(--drawer-px,1.25rem)\",\n classNames?.body,\n )}\n >\n {children}\n </DrawerBody>\n </DrawerContent>\n </DrawerPositioner>\n </Portal>\n </DrawerRoot>\n )\n}\n\nexport const Drawer = Object.assign(DrawerComponent, {\n Root: DrawerRoot,\n Trigger: DrawerTrigger,\n Context: DrawerContext,\n Backdrop: DrawerBackdrop,\n Positioner: DrawerPositioner,\n Content: DrawerContent,\n Title: DrawerTitle,\n Description: DrawerDescription,\n CloseTrigger: DrawerCloseTrigger,\n Grabber: DrawerGrabber,\n Header: DrawerHeader,\n Body: DrawerBody,\n Footer: DrawerFooter,\n})\n"]}
|