@manakind/ui-core 0.27.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/dialog/dialog.css +6 -6
- package/dist/dialog/dialog.d.ts +3 -3
- package/dist/dialog/dialog.js.map +1 -1
- package/dist/side-panel-layout/side-panel-context.d.ts +1 -1
- package/dist/side-panel-layout/side-panel-context.js.map +1 -1
- package/dist/side-panel-layout/side-panel-layout.css +38 -18
- package/dist/side-panel-layout/side-panel-layout.d.ts +21 -12
- package/dist/side-panel-layout/side-panel-layout.d.ts.map +1 -1
- package/dist/side-panel-layout/side-panel-layout.js +20 -11
- package/dist/side-panel-layout/side-panel-layout.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -97,7 +97,7 @@ separately, so an app can load only what it renders.
|
|
|
97
97
|
| `@manakind/ui-core/css/slider` | Slider structural CSS |
|
|
98
98
|
| `@manakind/ui-core/section` | `Section` |
|
|
99
99
|
| `@manakind/ui-core/split-layout` | `SplitLayout`, `SplitMain`, `SplitAside` |
|
|
100
|
-
| `@manakind/ui-core/side-panel-layout` | `SidePanelLayout`, the
|
|
100
|
+
| `@manakind/ui-core/side-panel-layout` | `SidePanelLayout`, the drawer a `Dialog` with `presentation="side"` opens in |
|
|
101
101
|
| `@manakind/ui-core/form-layout` | `FormLayout`, `FormActions` |
|
|
102
102
|
| `@manakind/ui-core/wizard-layout` | `WizardLayout`, `WizardHeader`, `WizardContent`, `WizardFooter` |
|
|
103
103
|
| `@manakind/ui-core/centered-layout` | `CenteredLayout` |
|
package/dist/dialog/dialog.css
CHANGED
|
@@ -54,11 +54,11 @@
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
/*
|
|
57
|
-
* In a SidePanelLayout's
|
|
58
|
-
*
|
|
59
|
-
* in the page rather than over it,
|
|
60
|
-
*
|
|
61
|
-
* into view.
|
|
57
|
+
* In a SidePanelLayout's slot, which sizes it: a band above the content,
|
|
58
|
+
* or from `lg` a drawer as tall as the viewport below the header. The
|
|
59
|
+
* body scrolls past that height. It sits in the page rather than over it,
|
|
60
|
+
* so it draws no shadow, and its scroll margin keeps it clear of the
|
|
61
|
+
* app's sticky header when it is scrolled into view.
|
|
62
62
|
*/
|
|
63
63
|
&.ds-dialog--side {
|
|
64
64
|
max-inline-size: none;
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
|
|
117
117
|
/*
|
|
118
118
|
* Only the body scrolls. `min-block-size: 0` lets it shrink below its
|
|
119
|
-
* content inside
|
|
119
|
+
* content inside a side panel, which is what keeps the title and the
|
|
120
120
|
* actions in view when the content is taller than the viewport.
|
|
121
121
|
*
|
|
122
122
|
* A scroll container clips whatever is drawn past its padding, and a
|
package/dist/dialog/dialog.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import './dialog.css';
|
|
|
4
4
|
export type DialogRole = 'dialog' | 'alertdialog';
|
|
5
5
|
/** How wide the panel may grow: a message or short form, or a form with fields side by side. */
|
|
6
6
|
export type DialogSize = 'md' | 'lg';
|
|
7
|
-
/** Over the page with the rest of it shut off, or in a
|
|
7
|
+
/** Over the page with the rest of it shut off, or in a drawer beside it. */
|
|
8
8
|
export type DialogPresentation = 'modal' | 'side';
|
|
9
9
|
export interface DialogProps {
|
|
10
10
|
/**
|
|
@@ -86,13 +86,13 @@ export interface DialogProps {
|
|
|
86
86
|
size?: DialogSize;
|
|
87
87
|
/**
|
|
88
88
|
* `modal` (the default) floats the panel over a dimmed page. `side` opens
|
|
89
|
-
* it in the
|
|
89
|
+
* it in the drawer of the nearest `SidePanelLayout`, beside the content,
|
|
90
90
|
* which stays in view and usable: a form for one item of a list the user
|
|
91
91
|
* may want to browse while filling it in. A side panel traps no focus,
|
|
92
92
|
* locks no scroll and stays open on a click outside. Escape closes it
|
|
93
93
|
* while focus is in it or on no control, and leaves an Escape pressed on a
|
|
94
94
|
* control in the page to that control. On close, focus returns as from a
|
|
95
|
-
* modal unless the user had moved it onto the page. It
|
|
95
|
+
* modal unless the user had moved it onto the page. It is as wide as a `md` dialog, so `size`
|
|
96
96
|
* does not apply. Opening another side dialog in the layout closes this
|
|
97
97
|
* one through `onOpenChange`; a controlled dialog should honour it.
|
|
98
98
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog.js","sourceRoot":"","sources":["../../src/dialog/dialog.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAIL,WAAW,EACX,UAAU,EACV,eAAe,EACf,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAsB,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AACnG,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AA6G3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,UAAU,MAAM,CAAC,EACrB,KAAK,EACL,WAAW,EACX,QAAQ,EACR,OAAO,EACP,OAAO,EACP,IAAI,EACJ,WAAW,EACX,YAAY,EACZ,IAAI,GAAG,QAAQ,EACf,eAAe,EACf,aAAa,EACb,UAAU,GAAG,OAAO,EACpB,SAAS,GAAG,KAAK,EACjB,IAAI,GAAG,IAAI,EACX,YAAY,GAAG,OAAO,EACtB,SAAS,GACG;IACZ,MAAM,WAAW,GAAG,IAAI,KAAK,QAAQ,CAAC;IACtC,MAAM,IAAI,GAAG,UAAU,CAA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,cAAc,CAAC,GAAG,EAAE,CACvC,aAAa,CAAC,QAAQ,CAAC,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAC,CAC7D,CAAC;QACF,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC3B,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC1B,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;IACrC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACL,cAAK,GAAG,EAAE,OAAO,EAAE,SAAS,EAAC,iBAAiB,EAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,YACjF,cAAK,SAAS,EAAC,yBAAyB,YAAE,QAAQ,GAAO,GACrD,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { Dialog as ArkDialog, useDialogContext } from '@ark-ui/react/dialog';\nimport { Portal } from '@ark-ui/react/portal';\nimport {\n type ReactElement,\n type ReactNode,\n type RefObject,\n useCallback,\n useContext,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { IconButton } from '../button/icon-button';\nimport type { IconSource } from '../icon/icon';\nimport { PortalContainerContext } from '../portal-container';\nimport { type SidePanelSlot, SidePanelSlotContext } from '../side-panel-layout/side-panel-context';\nimport './dialog.css';\nimport { cx } from '../cx';\nimport { Cross } from '../fallback-glyphs';\n\nexport type DialogRole = 'dialog' | 'alertdialog';\n\n/** How wide the panel may grow: a message or short form, or a form with fields side by side. */\nexport type DialogSize = 'md' | 'lg';\n\n/** Over the page with the rest of it shut off, or in a column beside it. */\nexport type DialogPresentation = 'modal' | 'side';\n\nexport interface DialogProps {\n /**\n * The dialog's name: rendered as its `<h2>` heading and announced when it\n * opens (`aria-labelledby`). Write it as a short statement or question —\n * \"Remove “Site foreman”?\".\n */\n title: ReactNode;\n /**\n * One or two sentences under the title, announced with it\n * (`aria-describedby`). For a confirmation, say what the action does and\n * what it leaves alone.\n */\n description?: ReactNode;\n /** Body content. Scrolls inside the panel when it outgrows the viewport. */\n children?: ReactNode;\n /**\n * The footer's buttons, end-aligned, in reading order: the dismissive one\n * first, the committing one last. They wrap onto a second line on a narrow\n * screen. Wrap a dismissive button in `DialogClose` to make it close.\n */\n actions?: ReactNode;\n /**\n * The one element that opens the dialog, such as a `Button`. Focus returns\n * to it when the dialog closes, unless `finalFocusRef` names another\n * element. Leave it out to open the dialog with `open` from elsewhere.\n */\n trigger?: ReactElement;\n /** Controlled open state. Pair with `onOpenChange`. */\n open?: boolean;\n /** Initial open state when uncontrolled. */\n defaultOpen?: boolean;\n /**\n * Fired with the requested state whenever the dialog asks to open (its\n * trigger) or close (a `DialogClose`, the close button, Escape, or for\n * `role=\"dialog\"` a click outside). A controlled dialog stays as it is\n * until `open` changes.\n */\n onOpenChange?: (open: boolean) => void;\n /**\n * `dialog` (default) shows a close button and closes on Escape and on a\n * click outside. `alertdialog` is for confirmations: no close button, and a\n * click outside does nothing, so the explicit cancel action is the way\n * out. Escape still cancels.\n */\n role?: DialogRole;\n /**\n * Where focus lands when the dialog opens. Defaults to the first focusable\n * element: the close button of a `dialog`, the first action of an\n * `alertdialog` with no focusable body. Point an alertdialog at its least\n * destructive action.\n */\n initialFocusRef?: RefObject<HTMLElement | null>;\n /**\n * Where focus lands when the dialog closes, in place of the trigger. Use it\n * when the confirmed action removes the trigger, such as a row's Remove\n * button: focus would return to an element that is about to unmount and\n * fall to the page body. Point it at something that stays, such as the\n * list's heading, which needs `tabIndex={-1}` to take focus.\n *\n * The ref is read as the dialog closes, however it closes. Fill it in the\n * committing action, so Cancel and Escape still return focus to the\n * trigger, which is still there. While the ref holds no element, focus\n * returns to the trigger as usual.\n */\n finalFocusRef?: RefObject<HTMLElement | null>;\n /** Accessible name of the close button. Translate it with the rest of the UI. */\n closeLabel?: string;\n /**\n * Glyph for the close button. Defaults to a plain built-in cross so\n * `@manakind/ui-core` renders on its own; products pass their own icon set,\n * as they do for Select's indicators.\n */\n closeIcon?: IconSource;\n /**\n * How wide the panel may grow: `md` (the default) for a message or a short\n * form, `lg` for a form with fields side by side.\n */\n size?: DialogSize;\n /**\n * `modal` (the default) floats the panel over a dimmed page. `side` opens\n * it in the column of the nearest `SidePanelLayout`, beside the content,\n * which stays in view and usable: a form for one item of a list the user\n * may want to browse while filling it in. A side panel traps no focus,\n * locks no scroll and stays open on a click outside. Escape closes it\n * while focus is in it or on no control, and leaves an Escape pressed on a\n * control in the page to that control. On close, focus returns as from a\n * modal unless the user had moved it onto the page. It takes the column's width, so `size`\n * does not apply. Opening another side dialog in the layout closes this\n * one through `onOpenChange`; a controlled dialog should honour it.\n *\n * Outside a `SidePanelLayout`, for `role=\"alertdialog\"`, which must hold\n * the user until they answer, and inside another dialog, the dialog opens\n * as a modal.\n */\n presentation?: DialogPresentation;\n /** Extra class names appended to the panel's `ds-dialog`. */\n className?: string;\n}\n\n/**\n * A modal dialog: a raised panel over a dimmed page, built on Ark UI.\n *\n * Ark owns the behaviour: the focus trap, focus returning to the trigger\n * (or to `finalFocusRef`), Escape, the page's scroll lock, `aria-modal`, and the title and\n * description wiring. This wrapper adds the `ds-` classes, the\n * `--ds-dialog-*` bindings, and a slot API in place of Ark's anatomy.\n *\n * ```tsx\n * <Dialog\n * role=\"alertdialog\"\n * title=\"Remove “Site foreman”?\"\n * description=\"2 people and 1 Landfall lose this type; nothing else is deleted.\"\n * trigger={<Button variant=\"secondary\">Remove</Button>}\n * initialFocusRef={cancelRef}\n * actions={\n * <>\n * <DialogClose>\n * <Button ref={cancelRef} variant=\"secondary\">Cancel</Button>\n * </DialogClose>\n * <Button variant=\"danger\" onClick={remove}>Remove</Button>\n * </>\n * }\n * />\n * ```\n *\n * The committing action is the consumer's own button. To close after it\n * runs, control the dialog with `open` and set it false in the handler, or\n * wrap the button in `DialogClose` when closing at once is right.\n *\n * The backdrop and panel portal into `<body>` at `z-index: 50`, the layer\n * the product apps use for their own overlays. A Select or Menu inside the\n * dialog portals into its panel (see `PortalContainerContext`) and opens at\n * 60, above it. Nothing is mounted while the dialog is closed.\n */\nexport function Dialog({\n title,\n description,\n children,\n actions,\n trigger,\n open,\n defaultOpen,\n onOpenChange,\n role = 'dialog',\n initialFocusRef,\n finalFocusRef,\n closeLabel = 'Close',\n closeIcon = Cross,\n size = 'md',\n presentation = 'modal',\n className,\n}: DialogProps) {\n const dismissible = role === 'dialog';\n const slot = useContext(SidePanelSlotContext);\n const side = presentation === 'side' && dismissible && slot ? slot : undefined;\n const panelRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLButtonElement>(null);\n const [sidePanel, setSidePanel] = useState<HTMLDivElement | null>(null);\n const sidePanelRef = useCallback((element: HTMLDivElement | null) => {\n panelRef.current = element;\n setSidePanel(element);\n }, []);\n const handleOpenChange = (details: { open: boolean }) => onOpenChange?.(details.open);\n // Zag types this as returning `HTMLElement | null`, but its focus trap\n // reads undefined as \"the first focusable element\" and, given null, fails\n // to start at all, leaving the page reachable by Tab.\n const initialFocusEl = (() => initialFocusRef?.current ?? undefined) as () => HTMLElement | null;\n const finalFocusEl = () => finalFocusRef?.current ?? null;\n // Zag's dismiss layer takes Escape anywhere in the document. A side panel\n // leaves the page usable, so an Escape meant for a control on the page,\n // such as a ReorderControl dropping its draft, must not close it too.\n const keepEscapeOnThePage = (event: KeyboardEvent) => {\n const target = event.target;\n const onThePage =\n target instanceof Node &&\n target !== target.ownerDocument?.body &&\n !panelRef.current?.contains(target);\n if (onThePage) event.preventDefault();\n };\n const panel = (\n <PortalContainerContext.Provider value={panelRef}>\n <div className=\"ds-dialog__header\">\n <div className=\"ds-dialog__heading\">\n <ArkDialog.Title className=\"ds-dialog__title\">{title}</ArkDialog.Title>\n {description && (\n <ArkDialog.Description className=\"ds-dialog__description\">\n {description}\n </ArkDialog.Description>\n )}\n </div>\n {dismissible && (\n <ArkDialog.CloseTrigger asChild>\n <IconButton\n icon={closeIcon}\n aria-label={closeLabel}\n variant=\"tertiary\"\n size=\"sm\"\n className=\"ds-dialog__close\"\n />\n </ArkDialog.CloseTrigger>\n )}\n </div>\n {children && <DialogBody>{children}</DialogBody>}\n {actions && <div className=\"ds-dialog__actions\">{actions}</div>}\n </PortalContainerContext.Provider>\n );\n const content = (\n <SidePanelSlotContext.Provider value={undefined}>{panel}</SidePanelSlotContext.Provider>\n );\n\n return (\n <ArkDialog.Root\n open={open}\n defaultOpen={defaultOpen}\n onOpenChange={handleOpenChange}\n role={role}\n modal={!side}\n closeOnInteractOutside={dismissible && !side}\n onEscapeKeyDown={side ? keepEscapeOnThePage : undefined}\n initialFocusEl={initialFocusEl}\n finalFocusEl={finalFocusEl}\n lazyMount\n unmountOnExit\n >\n {trigger && (\n <ArkDialog.Trigger ref={triggerRef} asChild>\n {trigger}\n </ArkDialog.Trigger>\n )}\n {side ? (\n side.container &&\n createPortal(\n <ArkDialog.Content\n ref={sidePanelRef}\n className={cx('ds-dialog', 'ds-dialog--side', className)}\n >\n <SidePanelSeat\n claim={side.claim}\n panel={sidePanel}\n triggerRef={triggerRef}\n finalFocusRef={finalFocusRef}\n />\n {content}\n </ArkDialog.Content>,\n side.container,\n )\n ) : (\n <Portal>\n <ArkDialog.Backdrop className=\"ds-dialog__backdrop\" />\n <ArkDialog.Positioner className=\"ds-dialog__positioner\">\n <ArkDialog.Content\n ref={panelRef}\n className={cx('ds-dialog', size === 'lg' && 'ds-dialog--lg', className)}\n >\n {content}\n </ArkDialog.Content>\n </ArkDialog.Positioner>\n </Portal>\n )}\n </ArkDialog.Root>\n );\n}\n\n/**\n * What a side panel needs that Ark leaves to a modal's focus trap: the slot,\n * taken on open so any other panel closes; the panel scrolled into view,\n * since below the `lg` step it sits above the content in the page's flow;\n * and focus put back on close. Focus moves when it was inside the panel or\n * on nothing, as after a save whose button disabled itself and so dropped\n * focus, so closing the panel never pulls the user out of the list they\n * moved to but never leaves them on the page's body either.\n * It goes where the trap would send it: `finalFocusRef`'s element, else the\n * trigger, else what had focus when the panel opened. The trigger is named\n * outright because Safari does not focus a button on click.\n *\n * The panel arrives as state from its callback ref: a child's layout effect\n * runs before its parent's ref is attached. A layout effect, because its\n * cleanup runs while the panel is still in the document and can still hold\n * focus, and before Ark moves focus into the panel a frame after it opens.\n * It runs once per opening: the callbacks and refs it reads at close are\n * kept current beside it, so a re-render never closes and reopens the seat.\n */\nfunction SidePanelSeat({\n claim,\n panel,\n triggerRef,\n finalFocusRef,\n}: {\n claim: SidePanelSlot['claim'];\n panel: HTMLDivElement | null;\n triggerRef: RefObject<HTMLElement | null>;\n finalFocusRef?: RefObject<HTMLElement | null>;\n}) {\n const dialog = useDialogContext();\n const latest = useRef({ setOpen: dialog.setOpen, finalFocusRef });\n useLayoutEffect(() => {\n latest.current = { setOpen: dialog.setOpen, finalFocusRef };\n });\n\n useLayoutEffect(() => {\n if (!panel) return;\n const opener = panel.ownerDocument.activeElement;\n const release = claim(() => latest.current.setOpen(false));\n panel.scrollIntoView({ block: 'nearest' });\n return () => {\n release();\n const active = panel.ownerDocument.activeElement;\n const movedToThePage =\n active && active !== panel.ownerDocument.body && !panel.contains(active);\n if (movedToThePage) return;\n const target = [latest.current.finalFocusRef?.current, triggerRef.current, opener].find(\n (element) => element instanceof HTMLElement && element.isConnected,\n );\n if (target instanceof HTMLElement) target.focus();\n };\n }, [claim, panel, triggerRef]);\n\n return null;\n}\n\n/**\n * The scrolling body. While its content overflows it joins the tab order, so\n * a keyboard user can focus it and scroll; a body with nothing to scroll\n * stays out of the way.\n *\n * Two boxes are observed because either can change the answer: the outer one\n * resizes with the viewport, the inner one with the content.\n */\nfunction DialogBody({ children }: { children: ReactNode }) {\n const [scrollable, setScrollable] = useState(false);\n const observe = useCallback((scroller: HTMLDivElement | null) => {\n const content = scroller?.firstElementChild;\n if (!scroller || !content) return;\n const observer = new ResizeObserver(() =>\n setScrollable(scroller.scrollHeight > scroller.clientHeight),\n );\n observer.observe(scroller);\n observer.observe(content);\n return () => observer.disconnect();\n }, []);\n\n return (\n <div ref={observe} className=\"ds-dialog__body\" tabIndex={scrollable ? 0 : undefined}>\n <div className=\"ds-dialog__body-content\">{children}</div>\n </div>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dialog.js","sourceRoot":"","sources":["../../src/dialog/dialog.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAIL,WAAW,EACX,UAAU,EACV,eAAe,EACf,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAsB,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AACnG,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AA6G3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,UAAU,MAAM,CAAC,EACrB,KAAK,EACL,WAAW,EACX,QAAQ,EACR,OAAO,EACP,OAAO,EACP,IAAI,EACJ,WAAW,EACX,YAAY,EACZ,IAAI,GAAG,QAAQ,EACf,eAAe,EACf,aAAa,EACb,UAAU,GAAG,OAAO,EACpB,SAAS,GAAG,KAAK,EACjB,IAAI,GAAG,IAAI,EACX,YAAY,GAAG,OAAO,EACtB,SAAS,GACG;IACZ,MAAM,WAAW,GAAG,IAAI,KAAK,QAAQ,CAAC;IACtC,MAAM,IAAI,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAC;IAC9C,MAAM,IAAI,GAAG,YAAY,KAAK,MAAM,IAAI,WAAW,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AC,YAAY,CAAC,CAC7D,CAAC;QACF,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC3B,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC1B,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;IACrC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACL,cAAK,GAAG,EAAE,OAAO,EAAE,SAAS,EAAC,iBAAiB,EAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,YACjF,cAAK,SAAS,EAAC,yBAAyB,YAAE,QAAQ,GAAO,GACrD,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { Dialog as ArkDialog, useDialogContext } from '@ark-ui/react/dialog';\nimport { Portal } from '@ark-ui/react/portal';\nimport {\n type ReactElement,\n type ReactNode,\n type RefObject,\n useCallback,\n useContext,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { IconButton } from '../button/icon-button';\nimport type { IconSource } from '../icon/icon';\nimport { PortalContainerContext } from '../portal-container';\nimport { type SidePanelSlot, SidePanelSlotContext } from '../side-panel-layout/side-panel-context';\nimport './dialog.css';\nimport { cx } from '../cx';\nimport { Cross } from '../fallback-glyphs';\n\nexport type DialogRole = 'dialog' | 'alertdialog';\n\n/** How wide the panel may grow: a message or short form, or a form with fields side by side. */\nexport type DialogSize = 'md' | 'lg';\n\n/** Over the page with the rest of it shut off, or in a drawer beside it. */\nexport type DialogPresentation = 'modal' | 'side';\n\nexport interface DialogProps {\n /**\n * The dialog's name: rendered as its `<h2>` heading and announced when it\n * opens (`aria-labelledby`). Write it as a short statement or question —\n * \"Remove “Site foreman”?\".\n */\n title: ReactNode;\n /**\n * One or two sentences under the title, announced with it\n * (`aria-describedby`). For a confirmation, say what the action does and\n * what it leaves alone.\n */\n description?: ReactNode;\n /** Body content. Scrolls inside the panel when it outgrows the viewport. */\n children?: ReactNode;\n /**\n * The footer's buttons, end-aligned, in reading order: the dismissive one\n * first, the committing one last. They wrap onto a second line on a narrow\n * screen. Wrap a dismissive button in `DialogClose` to make it close.\n */\n actions?: ReactNode;\n /**\n * The one element that opens the dialog, such as a `Button`. Focus returns\n * to it when the dialog closes, unless `finalFocusRef` names another\n * element. Leave it out to open the dialog with `open` from elsewhere.\n */\n trigger?: ReactElement;\n /** Controlled open state. Pair with `onOpenChange`. */\n open?: boolean;\n /** Initial open state when uncontrolled. */\n defaultOpen?: boolean;\n /**\n * Fired with the requested state whenever the dialog asks to open (its\n * trigger) or close (a `DialogClose`, the close button, Escape, or for\n * `role=\"dialog\"` a click outside). A controlled dialog stays as it is\n * until `open` changes.\n */\n onOpenChange?: (open: boolean) => void;\n /**\n * `dialog` (default) shows a close button and closes on Escape and on a\n * click outside. `alertdialog` is for confirmations: no close button, and a\n * click outside does nothing, so the explicit cancel action is the way\n * out. Escape still cancels.\n */\n role?: DialogRole;\n /**\n * Where focus lands when the dialog opens. Defaults to the first focusable\n * element: the close button of a `dialog`, the first action of an\n * `alertdialog` with no focusable body. Point an alertdialog at its least\n * destructive action.\n */\n initialFocusRef?: RefObject<HTMLElement | null>;\n /**\n * Where focus lands when the dialog closes, in place of the trigger. Use it\n * when the confirmed action removes the trigger, such as a row's Remove\n * button: focus would return to an element that is about to unmount and\n * fall to the page body. Point it at something that stays, such as the\n * list's heading, which needs `tabIndex={-1}` to take focus.\n *\n * The ref is read as the dialog closes, however it closes. Fill it in the\n * committing action, so Cancel and Escape still return focus to the\n * trigger, which is still there. While the ref holds no element, focus\n * returns to the trigger as usual.\n */\n finalFocusRef?: RefObject<HTMLElement | null>;\n /** Accessible name of the close button. Translate it with the rest of the UI. */\n closeLabel?: string;\n /**\n * Glyph for the close button. Defaults to a plain built-in cross so\n * `@manakind/ui-core` renders on its own; products pass their own icon set,\n * as they do for Select's indicators.\n */\n closeIcon?: IconSource;\n /**\n * How wide the panel may grow: `md` (the default) for a message or a short\n * form, `lg` for a form with fields side by side.\n */\n size?: DialogSize;\n /**\n * `modal` (the default) floats the panel over a dimmed page. `side` opens\n * it in the drawer of the nearest `SidePanelLayout`, beside the content,\n * which stays in view and usable: a form for one item of a list the user\n * may want to browse while filling it in. A side panel traps no focus,\n * locks no scroll and stays open on a click outside. Escape closes it\n * while focus is in it or on no control, and leaves an Escape pressed on a\n * control in the page to that control. On close, focus returns as from a\n * modal unless the user had moved it onto the page. It is as wide as a `md` dialog, so `size`\n * does not apply. Opening another side dialog in the layout closes this\n * one through `onOpenChange`; a controlled dialog should honour it.\n *\n * Outside a `SidePanelLayout`, for `role=\"alertdialog\"`, which must hold\n * the user until they answer, and inside another dialog, the dialog opens\n * as a modal.\n */\n presentation?: DialogPresentation;\n /** Extra class names appended to the panel's `ds-dialog`. */\n className?: string;\n}\n\n/**\n * A modal dialog: a raised panel over a dimmed page, built on Ark UI.\n *\n * Ark owns the behaviour: the focus trap, focus returning to the trigger\n * (or to `finalFocusRef`), Escape, the page's scroll lock, `aria-modal`, and the title and\n * description wiring. This wrapper adds the `ds-` classes, the\n * `--ds-dialog-*` bindings, and a slot API in place of Ark's anatomy.\n *\n * ```tsx\n * <Dialog\n * role=\"alertdialog\"\n * title=\"Remove “Site foreman”?\"\n * description=\"2 people and 1 Landfall lose this type; nothing else is deleted.\"\n * trigger={<Button variant=\"secondary\">Remove</Button>}\n * initialFocusRef={cancelRef}\n * actions={\n * <>\n * <DialogClose>\n * <Button ref={cancelRef} variant=\"secondary\">Cancel</Button>\n * </DialogClose>\n * <Button variant=\"danger\" onClick={remove}>Remove</Button>\n * </>\n * }\n * />\n * ```\n *\n * The committing action is the consumer's own button. To close after it\n * runs, control the dialog with `open` and set it false in the handler, or\n * wrap the button in `DialogClose` when closing at once is right.\n *\n * The backdrop and panel portal into `<body>` at `z-index: 50`, the layer\n * the product apps use for their own overlays. A Select or Menu inside the\n * dialog portals into its panel (see `PortalContainerContext`) and opens at\n * 60, above it. Nothing is mounted while the dialog is closed.\n */\nexport function Dialog({\n title,\n description,\n children,\n actions,\n trigger,\n open,\n defaultOpen,\n onOpenChange,\n role = 'dialog',\n initialFocusRef,\n finalFocusRef,\n closeLabel = 'Close',\n closeIcon = Cross,\n size = 'md',\n presentation = 'modal',\n className,\n}: DialogProps) {\n const dismissible = role === 'dialog';\n const slot = useContext(SidePanelSlotContext);\n const side = presentation === 'side' && dismissible && slot ? slot : undefined;\n const panelRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLButtonElement>(null);\n const [sidePanel, setSidePanel] = useState<HTMLDivElement | null>(null);\n const sidePanelRef = useCallback((element: HTMLDivElement | null) => {\n panelRef.current = element;\n setSidePanel(element);\n }, []);\n const handleOpenChange = (details: { open: boolean }) => onOpenChange?.(details.open);\n // Zag types this as returning `HTMLElement | null`, but its focus trap\n // reads undefined as \"the first focusable element\" and, given null, fails\n // to start at all, leaving the page reachable by Tab.\n const initialFocusEl = (() => initialFocusRef?.current ?? undefined) as () => HTMLElement | null;\n const finalFocusEl = () => finalFocusRef?.current ?? null;\n // Zag's dismiss layer takes Escape anywhere in the document. A side panel\n // leaves the page usable, so an Escape meant for a control on the page,\n // such as a ReorderControl dropping its draft, must not close it too.\n const keepEscapeOnThePage = (event: KeyboardEvent) => {\n const target = event.target;\n const onThePage =\n target instanceof Node &&\n target !== target.ownerDocument?.body &&\n !panelRef.current?.contains(target);\n if (onThePage) event.preventDefault();\n };\n const panel = (\n <PortalContainerContext.Provider value={panelRef}>\n <div className=\"ds-dialog__header\">\n <div className=\"ds-dialog__heading\">\n <ArkDialog.Title className=\"ds-dialog__title\">{title}</ArkDialog.Title>\n {description && (\n <ArkDialog.Description className=\"ds-dialog__description\">\n {description}\n </ArkDialog.Description>\n )}\n </div>\n {dismissible && (\n <ArkDialog.CloseTrigger asChild>\n <IconButton\n icon={closeIcon}\n aria-label={closeLabel}\n variant=\"tertiary\"\n size=\"sm\"\n className=\"ds-dialog__close\"\n />\n </ArkDialog.CloseTrigger>\n )}\n </div>\n {children && <DialogBody>{children}</DialogBody>}\n {actions && <div className=\"ds-dialog__actions\">{actions}</div>}\n </PortalContainerContext.Provider>\n );\n const content = (\n <SidePanelSlotContext.Provider value={undefined}>{panel}</SidePanelSlotContext.Provider>\n );\n\n return (\n <ArkDialog.Root\n open={open}\n defaultOpen={defaultOpen}\n onOpenChange={handleOpenChange}\n role={role}\n modal={!side}\n closeOnInteractOutside={dismissible && !side}\n onEscapeKeyDown={side ? keepEscapeOnThePage : undefined}\n initialFocusEl={initialFocusEl}\n finalFocusEl={finalFocusEl}\n lazyMount\n unmountOnExit\n >\n {trigger && (\n <ArkDialog.Trigger ref={triggerRef} asChild>\n {trigger}\n </ArkDialog.Trigger>\n )}\n {side ? (\n side.container &&\n createPortal(\n <ArkDialog.Content\n ref={sidePanelRef}\n className={cx('ds-dialog', 'ds-dialog--side', className)}\n >\n <SidePanelSeat\n claim={side.claim}\n panel={sidePanel}\n triggerRef={triggerRef}\n finalFocusRef={finalFocusRef}\n />\n {content}\n </ArkDialog.Content>,\n side.container,\n )\n ) : (\n <Portal>\n <ArkDialog.Backdrop className=\"ds-dialog__backdrop\" />\n <ArkDialog.Positioner className=\"ds-dialog__positioner\">\n <ArkDialog.Content\n ref={panelRef}\n className={cx('ds-dialog', size === 'lg' && 'ds-dialog--lg', className)}\n >\n {content}\n </ArkDialog.Content>\n </ArkDialog.Positioner>\n </Portal>\n )}\n </ArkDialog.Root>\n );\n}\n\n/**\n * What a side panel needs that Ark leaves to a modal's focus trap: the slot,\n * taken on open so any other panel closes; the panel scrolled into view,\n * since below the `lg` step it sits above the content in the page's flow;\n * and focus put back on close. Focus moves when it was inside the panel or\n * on nothing, as after a save whose button disabled itself and so dropped\n * focus, so closing the panel never pulls the user out of the list they\n * moved to but never leaves them on the page's body either.\n * It goes where the trap would send it: `finalFocusRef`'s element, else the\n * trigger, else what had focus when the panel opened. The trigger is named\n * outright because Safari does not focus a button on click.\n *\n * The panel arrives as state from its callback ref: a child's layout effect\n * runs before its parent's ref is attached. A layout effect, because its\n * cleanup runs while the panel is still in the document and can still hold\n * focus, and before Ark moves focus into the panel a frame after it opens.\n * It runs once per opening: the callbacks and refs it reads at close are\n * kept current beside it, so a re-render never closes and reopens the seat.\n */\nfunction SidePanelSeat({\n claim,\n panel,\n triggerRef,\n finalFocusRef,\n}: {\n claim: SidePanelSlot['claim'];\n panel: HTMLDivElement | null;\n triggerRef: RefObject<HTMLElement | null>;\n finalFocusRef?: RefObject<HTMLElement | null>;\n}) {\n const dialog = useDialogContext();\n const latest = useRef({ setOpen: dialog.setOpen, finalFocusRef });\n useLayoutEffect(() => {\n latest.current = { setOpen: dialog.setOpen, finalFocusRef };\n });\n\n useLayoutEffect(() => {\n if (!panel) return;\n const opener = panel.ownerDocument.activeElement;\n const release = claim(() => latest.current.setOpen(false));\n panel.scrollIntoView({ block: 'nearest' });\n return () => {\n release();\n const active = panel.ownerDocument.activeElement;\n const movedToThePage =\n active && active !== panel.ownerDocument.body && !panel.contains(active);\n if (movedToThePage) return;\n const target = [latest.current.finalFocusRef?.current, triggerRef.current, opener].find(\n (element) => element instanceof HTMLElement && element.isConnected,\n );\n if (target instanceof HTMLElement) target.focus();\n };\n }, [claim, panel, triggerRef]);\n\n return null;\n}\n\n/**\n * The scrolling body. While its content overflows it joins the tab order, so\n * a keyboard user can focus it and scroll; a body with nothing to scroll\n * stays out of the way.\n *\n * Two boxes are observed because either can change the answer: the outer one\n * resizes with the viewport, the inner one with the content.\n */\nfunction DialogBody({ children }: { children: ReactNode }) {\n const [scrollable, setScrollable] = useState(false);\n const observe = useCallback((scroller: HTMLDivElement | null) => {\n const content = scroller?.firstElementChild;\n if (!scroller || !content) return;\n const observer = new ResizeObserver(() =>\n setScrollable(scroller.scrollHeight > scroller.clientHeight),\n );\n observer.observe(scroller);\n observer.observe(content);\n return () => observer.disconnect();\n }, []);\n\n return (\n <div ref={observe} className=\"ds-dialog__body\" tabIndex={scrollable ? 0 : undefined}>\n <div className=\"ds-dialog__body-content\">{children}</div>\n </div>\n );\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export interface SidePanelSlot {
|
|
2
2
|
/**
|
|
3
|
-
* The
|
|
3
|
+
* The drawer a `Dialog` with `presentation="side"` portals its panel into.
|
|
4
4
|
* Null until the layout has mounted it: a side dialog open on mount waits
|
|
5
5
|
* for it rather than rendering into `<body>` first.
|
|
6
6
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"side-panel-context.js","sourceRoot":"","sources":["../../src/side-panel-layout/side-panel-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAiBtC;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAA4B,SAAS,CAAC,CAAC","sourcesContent":["import { createContext } from 'react';\n\nexport interface SidePanelSlot {\n /**\n * The
|
|
1
|
+
{"version":3,"file":"side-panel-context.js","sourceRoot":"","sources":["../../src/side-panel-layout/side-panel-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAiBtC;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAA4B,SAAS,CAAC,CAAC","sourcesContent":["import { createContext } from 'react';\n\nexport interface SidePanelSlot {\n /**\n * The drawer a `Dialog` with `presentation=\"side\"` portals its panel into.\n * Null until the layout has mounted it: a side dialog open on mount waits\n * for it rather than rendering into `<body>` first.\n */\n container: HTMLDivElement | null;\n /**\n * Takes the slot for a panel that just opened and asks the panel holding\n * it to close, so one panel shows at a time. Returns the release to call\n * when the panel closes.\n */\n claim: (close: () => void) => () => void;\n}\n\n/**\n * The slot a `SidePanelLayout` keeps beside its content. Outside a layout\n * there is none, and a side dialog opens as a modal.\n */\nexport const SidePanelSlotContext = createContext<SidePanelSlot | undefined>(undefined);\n"]}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
@layer components {
|
|
2
2
|
/*
|
|
3
|
-
* The panel
|
|
3
|
+
* The panel slot stays empty until a side Dialog portals into it; React
|
|
4
4
|
* leaves no text node, so `:empty` tells whether a panel is open. Below the
|
|
5
|
-
* `lg` step the panel goes above the content, in the flow
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* `lg` step the panel goes above the content, in the flow, as a band across
|
|
6
|
+
* the layout's width: the layout sits outside the page's padding, so the
|
|
7
|
+
* panel squares its corners and keeps only its top and bottom borders, and
|
|
8
|
+
* the page's own padding spaces the content from it. Breakpoints are
|
|
9
|
+
* viewport tokens written as literals (`check:breakpoints`).
|
|
9
10
|
*/
|
|
10
11
|
.ds-side-panel-layout {
|
|
11
12
|
display: flex;
|
|
12
13
|
flex-direction: column;
|
|
13
|
-
gap: var(--ds-side-panel-layout-gap);
|
|
14
14
|
min-width: 0;
|
|
15
15
|
|
|
16
16
|
& > .ds-side-panel-layout__main {
|
|
@@ -26,28 +26,48 @@
|
|
|
26
26
|
&:empty {
|
|
27
27
|
display: none;
|
|
28
28
|
}
|
|
29
|
+
|
|
30
|
+
& > .ds-dialog {
|
|
31
|
+
border-inline-width: 0;
|
|
32
|
+
border-radius: 0;
|
|
33
|
+
}
|
|
29
34
|
}
|
|
30
35
|
}
|
|
31
36
|
|
|
37
|
+
/*
|
|
38
|
+
* From `lg` the panel is a drawer at the layout's end edge, outside the
|
|
39
|
+
* content's own padding: absolutely placed in the layout, which reserves
|
|
40
|
+
* its width with padding, so the content gives up the room rather than
|
|
41
|
+
* being covered. The drawer runs the layout's full height; the dialog in
|
|
42
|
+
* it sticks under the app's header and fills the viewport below it, its
|
|
43
|
+
* body scrolling inside, so the drawer always reaches from the header to
|
|
44
|
+
* the bottom of the screen. While a panel is open the layout is at least
|
|
45
|
+
* that tall, so a short page doesn't cut the drawer off.
|
|
46
|
+
*/
|
|
32
47
|
@media (width >= 64rem) {
|
|
33
48
|
.ds-side-panel-layout {
|
|
34
|
-
|
|
35
|
-
grid-template-columns: minmax(0, 1fr);
|
|
36
|
-
align-items: start;
|
|
49
|
+
position: relative;
|
|
37
50
|
|
|
38
51
|
&:has(> .ds-side-panel-layout__panel:not(:empty)) {
|
|
39
|
-
|
|
52
|
+
padding-inline-end: var(--ds-dialog-max-inline-size);
|
|
53
|
+
min-block-size: calc(100dvh - var(--ds-sticky-offset-top));
|
|
40
54
|
}
|
|
41
55
|
|
|
42
56
|
& > .ds-side-panel-layout__panel {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
position: absolute;
|
|
58
|
+
inset-block: 0;
|
|
59
|
+
inset-inline-end: 0;
|
|
60
|
+
inline-size: var(--ds-dialog-max-inline-size);
|
|
61
|
+
display: block;
|
|
62
|
+
|
|
63
|
+
& > .ds-dialog {
|
|
64
|
+
position: sticky;
|
|
65
|
+
top: var(--ds-sticky-offset-top);
|
|
66
|
+
block-size: calc(100dvh - var(--ds-sticky-offset-top));
|
|
67
|
+
max-block-size: none;
|
|
68
|
+
border-width: 0;
|
|
69
|
+
border-inline-start-width: 1px;
|
|
70
|
+
}
|
|
51
71
|
}
|
|
52
72
|
}
|
|
53
73
|
}
|
|
@@ -2,27 +2,36 @@ import { ark } from '@ark-ui/react/factory';
|
|
|
2
2
|
import { type ComponentProps } from 'react';
|
|
3
3
|
import './side-panel-layout.css';
|
|
4
4
|
/**
|
|
5
|
-
* No `asChild`: the layout renders its content and panel
|
|
5
|
+
* No `asChild`: the layout renders its content and its panel slot, and Ark's
|
|
6
6
|
* `asChild` clones exactly one.
|
|
7
7
|
*/
|
|
8
8
|
export type SidePanelLayoutProps = Omit<ComponentProps<typeof ark.div>, 'asChild'>;
|
|
9
9
|
/**
|
|
10
10
|
* Content with room for a side panel: a `Dialog` with `presentation="side"`
|
|
11
|
-
* opened anywhere inside it
|
|
12
|
-
*
|
|
11
|
+
* opened anywhere inside it opens beside the content and narrows it, so the
|
|
12
|
+
* list it was opened from stays in view and usable.
|
|
13
13
|
*
|
|
14
|
-
* From the `lg` viewport step up the panel
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
14
|
+
* From the `lg` viewport step up the panel is a drawer at the layout's end
|
|
15
|
+
* edge, from under the app's header (`--ds-sticky-offset-top`) to the bottom
|
|
16
|
+
* of the viewport, and the content gives up its width rather than being
|
|
17
|
+
* covered. Put the layout outside the page's own padding, around the page
|
|
18
|
+
* template, so the drawer meets the window's edge, directly under the app's
|
|
19
|
+
* header and with nothing after it in the page: the drawer is as tall as the
|
|
20
|
+
* viewport below the header and can't leave the layout, so content above the
|
|
21
|
+
* layout pushes its foot off the screen and content after it lifts its top
|
|
22
|
+
* under the header. Below `lg` the panel goes above the content, in the
|
|
23
|
+
* page's flow, and pushes it down. With no panel open the content takes the
|
|
24
|
+
* whole width. One panel shows at a time: opening another closes the one
|
|
25
|
+
* that was open.
|
|
19
26
|
*
|
|
20
27
|
* ```tsx
|
|
21
28
|
* <SidePanelLayout>
|
|
22
|
-
* <
|
|
23
|
-
*
|
|
24
|
-
* <
|
|
25
|
-
*
|
|
29
|
+
* <PageLayout>
|
|
30
|
+
* <ActionList />
|
|
31
|
+
* <Dialog presentation="side" title="Add action" trigger={<Button>Add action</Button>}>
|
|
32
|
+
* <ActionForm />
|
|
33
|
+
* </Dialog>
|
|
34
|
+
* </PageLayout>
|
|
26
35
|
* </SidePanelLayout>
|
|
27
36
|
* ```
|
|
28
37
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"side-panel-layout.d.ts","sourceRoot":"","sources":["../../src/side-panel-layout/side-panel-layout.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAC5C,OAAO,EAAE,KAAK,cAAc,EAA0C,MAAM,OAAO,CAAC;AAGpF,OAAO,yBAAyB,CAAC;AAEjC;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,GAAG,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC,CAAC;AAEnF
|
|
1
|
+
{"version":3,"file":"side-panel-layout.d.ts","sourceRoot":"","sources":["../../src/side-panel-layout/side-panel-layout.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAC5C,OAAO,EAAE,KAAK,cAAc,EAA0C,MAAM,OAAO,CAAC;AAGpF,OAAO,yBAAyB,CAAC;AAEjC;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,GAAG,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC,CAAC;AAEnF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,eAAe,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,oBAAoB,2CAqBtF"}
|
|
@@ -6,21 +6,30 @@ import { SidePanelSlotContext } from './side-panel-context';
|
|
|
6
6
|
import './side-panel-layout.css';
|
|
7
7
|
/**
|
|
8
8
|
* Content with room for a side panel: a `Dialog` with `presentation="side"`
|
|
9
|
-
* opened anywhere inside it
|
|
10
|
-
*
|
|
9
|
+
* opened anywhere inside it opens beside the content and narrows it, so the
|
|
10
|
+
* list it was opened from stays in view and usable.
|
|
11
11
|
*
|
|
12
|
-
* From the `lg` viewport step up the panel
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
12
|
+
* From the `lg` viewport step up the panel is a drawer at the layout's end
|
|
13
|
+
* edge, from under the app's header (`--ds-sticky-offset-top`) to the bottom
|
|
14
|
+
* of the viewport, and the content gives up its width rather than being
|
|
15
|
+
* covered. Put the layout outside the page's own padding, around the page
|
|
16
|
+
* template, so the drawer meets the window's edge, directly under the app's
|
|
17
|
+
* header and with nothing after it in the page: the drawer is as tall as the
|
|
18
|
+
* viewport below the header and can't leave the layout, so content above the
|
|
19
|
+
* layout pushes its foot off the screen and content after it lifts its top
|
|
20
|
+
* under the header. Below `lg` the panel goes above the content, in the
|
|
21
|
+
* page's flow, and pushes it down. With no panel open the content takes the
|
|
22
|
+
* whole width. One panel shows at a time: opening another closes the one
|
|
23
|
+
* that was open.
|
|
17
24
|
*
|
|
18
25
|
* ```tsx
|
|
19
26
|
* <SidePanelLayout>
|
|
20
|
-
* <
|
|
21
|
-
*
|
|
22
|
-
* <
|
|
23
|
-
*
|
|
27
|
+
* <PageLayout>
|
|
28
|
+
* <ActionList />
|
|
29
|
+
* <Dialog presentation="side" title="Add action" trigger={<Button>Add action</Button>}>
|
|
30
|
+
* <ActionForm />
|
|
31
|
+
* </Dialog>
|
|
32
|
+
* </PageLayout>
|
|
24
33
|
* </SidePanelLayout>
|
|
25
34
|
* ```
|
|
26
35
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"side-panel-layout.js","sourceRoot":"","sources":["../../src/side-panel-layout/side-panel-layout.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAC5C,OAAO,EAAuB,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpF,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAsB,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,yBAAyB,CAAC;AAQjC
|
|
1
|
+
{"version":3,"file":"side-panel-layout.js","sourceRoot":"","sources":["../../src/side-panel-layout/side-panel-layout.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAC5C,OAAO,EAAuB,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpF,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC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port { cx } from '../cx';\nimport { type SidePanelSlot, SidePanelSlotContext } from './side-panel-context';\nimport './side-panel-layout.css';\n\n/**\n * No `asChild`: the layout renders its content and its panel slot, and Ark's\n * `asChild` clones exactly one.\n */\nexport type SidePanelLayoutProps = Omit<ComponentProps<typeof ark.div>, 'asChild'>;\n\n/**\n * Content with room for a side panel: a `Dialog` with `presentation=\"side\"`\n * opened anywhere inside it opens beside the content and narrows it, so the\n * list it was opened from stays in view and usable.\n *\n * From the `lg` viewport step up the panel is a drawer at the layout's end\n * edge, from under the app's header (`--ds-sticky-offset-top`) to the bottom\n * of the viewport, and the content gives up its width rather than being\n * covered. Put the layout outside the page's own padding, around the page\n * template, so the drawer meets the window's edge, directly under the app's\n * header and with nothing after it in the page: the drawer is as tall as the\n * viewport below the header and can't leave the layout, so content above the\n * layout pushes its foot off the screen and content after it lifts its top\n * under the header. Below `lg` the panel goes above the content, in the\n * page's flow, and pushes it down. With no panel open the content takes the\n * whole width. One panel shows at a time: opening another closes the one\n * that was open.\n *\n * ```tsx\n * <SidePanelLayout>\n * <PageLayout>\n * <ActionList />\n * <Dialog presentation=\"side\" title=\"Add action\" trigger={<Button>Add action</Button>}>\n * <ActionForm />\n * </Dialog>\n * </PageLayout>\n * </SidePanelLayout>\n * ```\n */\nexport function SidePanelLayout({ className, children, ...props }: SidePanelLayoutProps) {\n const [container, setContainer] = useState<HTMLDivElement | null>(null);\n const closeHolder = useRef<(() => void) | null>(null);\n const claim = useCallback((close: () => void) => {\n const previous = closeHolder.current;\n closeHolder.current = close;\n previous?.();\n return () => {\n if (closeHolder.current === close) closeHolder.current = null;\n };\n }, []);\n const slot = useMemo<SidePanelSlot>(() => ({ container, claim }), [container, claim]);\n\n return (\n <SidePanelSlotContext.Provider value={slot}>\n <ark.div className={cx('ds-side-panel-layout', className)} {...props}>\n <div className=\"ds-side-panel-layout__main\">{children}</div>\n <div ref={setContainer} className=\"ds-side-panel-layout__panel\" />\n </ark.div>\n </SidePanelSlotContext.Provider>\n );\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manakind/ui-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -380,7 +380,7 @@
|
|
|
380
380
|
},
|
|
381
381
|
"devDependencies": {
|
|
382
382
|
"@manakind/ds-config": "*",
|
|
383
|
-
"@manakind/manuia-tokens": "0.
|
|
383
|
+
"@manakind/manuia-tokens": "0.27.0",
|
|
384
384
|
"@testing-library/jest-dom": "^6.9.1",
|
|
385
385
|
"@testing-library/react": "^16.3.2",
|
|
386
386
|
"@testing-library/user-event": "^14.6.1",
|