@manakind/ui-core 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/README.md +2 -0
- package/dist/dialog/dialog.css +14 -0
- package/dist/dialog/dialog.d.ts +20 -1
- package/dist/dialog/dialog.d.ts.map +1 -1
- package/dist/dialog/dialog.js +72 -4
- package/dist/dialog/dialog.js.map +1 -1
- package/dist/dialog/index.d.ts +1 -1
- package/dist/dialog/index.d.ts.map +1 -1
- package/dist/dialog/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/side-panel-layout/index.d.ts +2 -0
- package/dist/side-panel-layout/index.d.ts.map +1 -0
- package/dist/side-panel-layout/index.js +2 -0
- package/dist/side-panel-layout/index.js.map +1 -0
- package/dist/side-panel-layout/side-panel-context.d.ts +20 -0
- package/dist/side-panel-layout/side-panel-context.d.ts.map +1 -0
- package/dist/side-panel-layout/side-panel-context.js +7 -0
- package/dist/side-panel-layout/side-panel-context.js.map +1 -0
- package/dist/side-panel-layout/side-panel-layout.css +54 -0
- package/dist/side-panel-layout/side-panel-layout.css.d.ts +2 -0
- package/dist/side-panel-layout/side-panel-layout.d.ts +30 -0
- package/dist/side-panel-layout/side-panel-layout.d.ts.map +1 -0
- package/dist/side-panel-layout/side-panel-layout.js +42 -0
- package/dist/side-panel-layout/side-panel-layout.js.map +1 -0
- package/dist/tooltip/tooltip.d.ts.map +1 -1
- package/dist/tooltip/tooltip.js +19 -2
- package/dist/tooltip/tooltip.js.map +1 -1
- package/package.json +10 -2
package/README.md
CHANGED
|
@@ -97,6 +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 column a `Dialog` with `presentation="side"` opens in |
|
|
100
101
|
| `@manakind/ui-core/form-layout` | `FormLayout`, `FormActions` |
|
|
101
102
|
| `@manakind/ui-core/wizard-layout` | `WizardLayout`, `WizardHeader`, `WizardContent`, `WizardFooter` |
|
|
102
103
|
| `@manakind/ui-core/centered-layout` | `CenteredLayout` |
|
|
@@ -137,6 +138,7 @@ separately, so an app can load only what it renders.
|
|
|
137
138
|
| `@manakind/ui-core/css/page-layout` | PageLayout structural CSS; its title and description also need `css/text` |
|
|
138
139
|
| `@manakind/ui-core/css/section` | Section structural CSS; its title and description also need `css/text` |
|
|
139
140
|
| `@manakind/ui-core/css/split-layout` | SplitLayout structural CSS |
|
|
141
|
+
| `@manakind/ui-core/css/side-panel-layout` | SidePanelLayout structural CSS |
|
|
140
142
|
| `@manakind/ui-core/css/form-layout` | FormLayout structural CSS |
|
|
141
143
|
| `@manakind/ui-core/css/wizard-layout` | WizardLayout structural CSS; its header also needs `css/progress` and `css/text` |
|
|
142
144
|
| `@manakind/ui-core/css/centered-layout` | CenteredLayout structural CSS |
|
package/dist/dialog/dialog.css
CHANGED
|
@@ -53,6 +53,20 @@
|
|
|
53
53
|
max-inline-size: var(--ds-dialog-max-inline-size-lg);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/*
|
|
57
|
+
* In a SidePanelLayout's column: as wide as the column, as tall as its
|
|
58
|
+
* content up to the column's height, past which the body scrolls. It sits
|
|
59
|
+
* in the page rather than over it, so it draws no shadow, and its scroll
|
|
60
|
+
* margin keeps it clear of the app's sticky header when it is scrolled
|
|
61
|
+
* into view.
|
|
62
|
+
*/
|
|
63
|
+
&.ds-dialog--side {
|
|
64
|
+
max-inline-size: none;
|
|
65
|
+
min-block-size: 0;
|
|
66
|
+
box-shadow: none;
|
|
67
|
+
scroll-margin-block-start: var(--ds-sticky-offset-top);
|
|
68
|
+
}
|
|
69
|
+
|
|
56
70
|
padding: var(--ds-dialog-padding);
|
|
57
71
|
border: 1px solid var(--ds-dialog-border);
|
|
58
72
|
border-radius: var(--ds-dialog-radius);
|
package/dist/dialog/dialog.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ 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 column beside it. */
|
|
8
|
+
export type DialogPresentation = 'modal' | 'side';
|
|
7
9
|
export interface DialogProps {
|
|
8
10
|
/**
|
|
9
11
|
* The dialog's name: rendered as its `<h2>` heading and announced when it
|
|
@@ -82,6 +84,23 @@ export interface DialogProps {
|
|
|
82
84
|
* form, `lg` for a form with fields side by side.
|
|
83
85
|
*/
|
|
84
86
|
size?: DialogSize;
|
|
87
|
+
/**
|
|
88
|
+
* `modal` (the default) floats the panel over a dimmed page. `side` opens
|
|
89
|
+
* it in the column of the nearest `SidePanelLayout`, beside the content,
|
|
90
|
+
* which stays in view and usable: a form for one item of a list the user
|
|
91
|
+
* may want to browse while filling it in. A side panel traps no focus,
|
|
92
|
+
* locks no scroll and stays open on a click outside. Escape closes it
|
|
93
|
+
* while focus is in it or on no control, and leaves an Escape pressed on a
|
|
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 takes the column's width, so `size`
|
|
96
|
+
* does not apply. Opening another side dialog in the layout closes this
|
|
97
|
+
* one through `onOpenChange`; a controlled dialog should honour it.
|
|
98
|
+
*
|
|
99
|
+
* Outside a `SidePanelLayout`, for `role="alertdialog"`, which must hold
|
|
100
|
+
* the user until they answer, and inside another dialog, the dialog opens
|
|
101
|
+
* as a modal.
|
|
102
|
+
*/
|
|
103
|
+
presentation?: DialogPresentation;
|
|
85
104
|
/** Extra class names appended to the panel's `ds-dialog`. */
|
|
86
105
|
className?: string;
|
|
87
106
|
}
|
|
@@ -120,5 +139,5 @@ export interface DialogProps {
|
|
|
120
139
|
* dialog portals into its panel (see `PortalContainerContext`) and opens at
|
|
121
140
|
* 60, above it. Nothing is mounted while the dialog is closed.
|
|
122
141
|
*/
|
|
123
|
-
export declare function Dialog({ title, description, children, actions, trigger, open, defaultOpen, onOpenChange, role, initialFocusRef, finalFocusRef, closeLabel, closeIcon, size, className, }: DialogProps): import("react/jsx-runtime").JSX.Element;
|
|
142
|
+
export declare function Dialog({ title, description, children, actions, trigger, open, defaultOpen, onOpenChange, role, initialFocusRef, finalFocusRef, closeLabel, closeIcon, size, presentation, className, }: DialogProps): import("react/jsx-runtime").JSX.Element;
|
|
124
143
|
//# sourceMappingURL=dialog.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog.d.ts","sourceRoot":"","sources":["../../src/dialog/dialog.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"dialog.d.ts","sourceRoot":"","sources":["../../src/dialog/dialog.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,SAAS,EAMf,MAAM,OAAO,CAAC;AAGf,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG/C,OAAO,cAAc,CAAC;AAItB,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,aAAa,CAAC;AAElD,gGAAgG;AAChG,MAAM,MAAM,UAAU,GAAG,IAAI,GAAG,IAAI,CAAC;AAErC,4EAA4E;AAC5E,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,MAAM,CAAC;AAElD,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,KAAK,EAAE,SAAS,CAAC;IACjB;;;;OAIG;IACH,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,4EAA4E;IAC5E,QAAQ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} from '@ark-ui/react/dialog';
|
|
2
|
+
import { Dialog as ArkDialog, useDialogContext } from '@ark-ui/react/dialog';
|
|
3
3
|
import { Portal } from '@ark-ui/react/portal';
|
|
4
|
-
import { useCallback, useRef, useState, } from 'react';
|
|
4
|
+
import { useCallback, useContext, useLayoutEffect, useRef, useState, } from 'react';
|
|
5
|
+
import { createPortal } from 'react-dom';
|
|
5
6
|
import { IconButton } from '../button/icon-button';
|
|
6
7
|
import { PortalContainerContext } from '../portal-container';
|
|
8
|
+
import { SidePanelSlotContext } from '../side-panel-layout/side-panel-context';
|
|
7
9
|
import './dialog.css';
|
|
8
10
|
import { cx } from '../cx';
|
|
9
11
|
import { Cross } from '../fallback-glyphs';
|
|
@@ -42,16 +44,82 @@ import { Cross } from '../fallback-glyphs';
|
|
|
42
44
|
* dialog portals into its panel (see `PortalContainerContext`) and opens at
|
|
43
45
|
* 60, above it. Nothing is mounted while the dialog is closed.
|
|
44
46
|
*/
|
|
45
|
-
export function Dialog({ title, description, children, actions, trigger, open, defaultOpen, onOpenChange, role = 'dialog', initialFocusRef, finalFocusRef, closeLabel = 'Close', closeIcon = Cross, size = 'md', className, }) {
|
|
47
|
+
export function Dialog({ title, description, children, actions, trigger, open, defaultOpen, onOpenChange, role = 'dialog', initialFocusRef, finalFocusRef, closeLabel = 'Close', closeIcon = Cross, size = 'md', presentation = 'modal', className, }) {
|
|
46
48
|
const dismissible = role === 'dialog';
|
|
49
|
+
const slot = useContext(SidePanelSlotContext);
|
|
50
|
+
const side = presentation === 'side' && dismissible && slot ? slot : undefined;
|
|
47
51
|
const panelRef = useRef(null);
|
|
52
|
+
const triggerRef = useRef(null);
|
|
53
|
+
const [sidePanel, setSidePanel] = useState(null);
|
|
54
|
+
const sidePanelRef = useCallback((element) => {
|
|
55
|
+
panelRef.current = element;
|
|
56
|
+
setSidePanel(element);
|
|
57
|
+
}, []);
|
|
48
58
|
const handleOpenChange = (details) => onOpenChange?.(details.open);
|
|
49
59
|
// Zag types this as returning `HTMLElement | null`, but its focus trap
|
|
50
60
|
// reads undefined as "the first focusable element" and, given null, fails
|
|
51
61
|
// to start at all, leaving the page reachable by Tab.
|
|
52
62
|
const initialFocusEl = (() => initialFocusRef?.current ?? undefined);
|
|
53
63
|
const finalFocusEl = () => finalFocusRef?.current ?? null;
|
|
54
|
-
|
|
64
|
+
// Zag's dismiss layer takes Escape anywhere in the document. A side panel
|
|
65
|
+
// leaves the page usable, so an Escape meant for a control on the page,
|
|
66
|
+
// such as a ReorderControl dropping its draft, must not close it too.
|
|
67
|
+
const keepEscapeOnThePage = (event) => {
|
|
68
|
+
const target = event.target;
|
|
69
|
+
const onThePage = target instanceof Node &&
|
|
70
|
+
target !== target.ownerDocument?.body &&
|
|
71
|
+
!panelRef.current?.contains(target);
|
|
72
|
+
if (onThePage)
|
|
73
|
+
event.preventDefault();
|
|
74
|
+
};
|
|
75
|
+
const panel = (_jsxs(PortalContainerContext.Provider, { value: panelRef, children: [_jsxs("div", { className: "ds-dialog__header", children: [_jsxs("div", { className: "ds-dialog__heading", children: [_jsx(ArkDialog.Title, { className: "ds-dialog__title", children: title }), description && (_jsx(ArkDialog.Description, { className: "ds-dialog__description", children: description }))] }), dismissible && (_jsx(ArkDialog.CloseTrigger, { asChild: true, children: _jsx(IconButton, { icon: closeIcon, "aria-label": closeLabel, variant: "tertiary", size: "sm", className: "ds-dialog__close" }) }))] }), children && _jsx(DialogBody, { children: children }), actions && _jsx("div", { className: "ds-dialog__actions", children: actions })] }));
|
|
76
|
+
const content = (_jsx(SidePanelSlotContext.Provider, { value: undefined, children: panel }));
|
|
77
|
+
return (_jsxs(ArkDialog.Root, { open: open, defaultOpen: defaultOpen, onOpenChange: handleOpenChange, role: role, modal: !side, closeOnInteractOutside: dismissible && !side, onEscapeKeyDown: side ? keepEscapeOnThePage : undefined, initialFocusEl: initialFocusEl, finalFocusEl: finalFocusEl, lazyMount: true, unmountOnExit: true, children: [trigger && (_jsx(ArkDialog.Trigger, { ref: triggerRef, asChild: true, children: trigger })), side ? (side.container &&
|
|
78
|
+
createPortal(_jsxs(ArkDialog.Content, { ref: sidePanelRef, className: cx('ds-dialog', 'ds-dialog--side', className), children: [_jsx(SidePanelSeat, { claim: side.claim, panel: sidePanel, triggerRef: triggerRef, finalFocusRef: finalFocusRef }), content] }), side.container)) : (_jsxs(Portal, { children: [_jsx(ArkDialog.Backdrop, { className: "ds-dialog__backdrop" }), _jsx(ArkDialog.Positioner, { className: "ds-dialog__positioner", children: _jsx(ArkDialog.Content, { ref: panelRef, className: cx('ds-dialog', size === 'lg' && 'ds-dialog--lg', className), children: content }) })] }))] }));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* What a side panel needs that Ark leaves to a modal's focus trap: the slot,
|
|
82
|
+
* taken on open so any other panel closes; the panel scrolled into view,
|
|
83
|
+
* since below the `lg` step it sits above the content in the page's flow;
|
|
84
|
+
* and focus put back on close. Focus moves when it was inside the panel or
|
|
85
|
+
* on nothing, as after a save whose button disabled itself and so dropped
|
|
86
|
+
* focus, so closing the panel never pulls the user out of the list they
|
|
87
|
+
* moved to but never leaves them on the page's body either.
|
|
88
|
+
* It goes where the trap would send it: `finalFocusRef`'s element, else the
|
|
89
|
+
* trigger, else what had focus when the panel opened. The trigger is named
|
|
90
|
+
* outright because Safari does not focus a button on click.
|
|
91
|
+
*
|
|
92
|
+
* The panel arrives as state from its callback ref: a child's layout effect
|
|
93
|
+
* runs before its parent's ref is attached. A layout effect, because its
|
|
94
|
+
* cleanup runs while the panel is still in the document and can still hold
|
|
95
|
+
* focus, and before Ark moves focus into the panel a frame after it opens.
|
|
96
|
+
* It runs once per opening: the callbacks and refs it reads at close are
|
|
97
|
+
* kept current beside it, so a re-render never closes and reopens the seat.
|
|
98
|
+
*/
|
|
99
|
+
function SidePanelSeat({ claim, panel, triggerRef, finalFocusRef, }) {
|
|
100
|
+
const dialog = useDialogContext();
|
|
101
|
+
const latest = useRef({ setOpen: dialog.setOpen, finalFocusRef });
|
|
102
|
+
useLayoutEffect(() => {
|
|
103
|
+
latest.current = { setOpen: dialog.setOpen, finalFocusRef };
|
|
104
|
+
});
|
|
105
|
+
useLayoutEffect(() => {
|
|
106
|
+
if (!panel)
|
|
107
|
+
return;
|
|
108
|
+
const opener = panel.ownerDocument.activeElement;
|
|
109
|
+
const release = claim(() => latest.current.setOpen(false));
|
|
110
|
+
panel.scrollIntoView({ block: 'nearest' });
|
|
111
|
+
return () => {
|
|
112
|
+
release();
|
|
113
|
+
const active = panel.ownerDocument.activeElement;
|
|
114
|
+
const movedToThePage = active && active !== panel.ownerDocument.body && !panel.contains(active);
|
|
115
|
+
if (movedToThePage)
|
|
116
|
+
return;
|
|
117
|
+
const target = [latest.current.finalFocusRef?.current, triggerRef.current, opener].find((element) => element instanceof HTMLElement && element.isConnected);
|
|
118
|
+
if (target instanceof HTMLElement)
|
|
119
|
+
target.focus();
|
|
120
|
+
};
|
|
121
|
+
}, [claim, panel, triggerRef]);
|
|
122
|
+
return null;
|
|
55
123
|
}
|
|
56
124
|
/**
|
|
57
125
|
* The scrolling body. While its content overflows it joins the tab order, so
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog.js","sourceRoot":"","sources":["../../src/dialog/dialog.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAIL,WAAW,EACX,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAyF3C;;;;;;;;;;;;;;;;;;;;;;;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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 } 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 useRef,\n useState,\n} from 'react';\nimport { IconButton } from '../button/icon-button';\nimport type { IconSource } from '../icon/icon';\nimport { PortalContainerContext } from '../portal-container';\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\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 /** 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 className,\n}: DialogProps) {\n const dismissible = role === 'dialog';\n const panelRef = useRef<HTMLDivElement>(null);\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\n return (\n <ArkDialog.Root\n open={open}\n defaultOpen={defaultOpen}\n onOpenChange={handleOpenChange}\n role={role}\n closeOnInteractOutside={dismissible}\n initialFocusEl={initialFocusEl}\n finalFocusEl={finalFocusEl}\n lazyMount\n unmountOnExit\n >\n {trigger && <ArkDialog.Trigger asChild>{trigger}</ArkDialog.Trigger>}\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 <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 </ArkDialog.Content>\n </ArkDialog.Positioner>\n </Portal>\n </ArkDialog.Root>\n );\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,EA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C,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"]}
|
package/dist/dialog/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { DialogProps, DialogRole, DialogSize } from './dialog';
|
|
1
|
+
export type { DialogPresentation, DialogProps, DialogRole, DialogSize } from './dialog';
|
|
2
2
|
export { Dialog } from './dialog';
|
|
3
3
|
export type { DialogCloseProps } from './dialog-close';
|
|
4
4
|
export { DialogClose } from './dialog-close';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dialog/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dialog/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACxF,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/dialog/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dialog/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["export type { DialogProps, DialogRole, DialogSize } from './dialog';\nexport { Dialog } from './dialog';\nexport type { DialogCloseProps } from './dialog-close';\nexport { DialogClose } from './dialog-close';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dialog/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["export type { DialogPresentation, DialogProps, DialogRole, DialogSize } from './dialog';\nexport { Dialog } from './dialog';\nexport type { DialogCloseProps } from './dialog-close';\nexport { DialogClose } from './dialog-close';\n"]}
|
package/dist/index.d.ts
CHANG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;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,OAAO,EACL,KAAK,IAAI,aAAa,EACtB,WAAW,IAAI,mBAAmB,EAClC,YAAY,IAAI,oBAAoB,EACpC,KAAK,IAAI,aAAa,EACtB,GAAG,IAAI,WAAW,GACnB,MAAM,mBAAmB,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AAEvB,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC","sourcesContent":["export * from './alert';\nexport * from './avatar';\nexport * from './badge';\nexport * from './breadcrumb';\nexport * from './button';\nexport * from './calendar';\nexport * from './card';\nexport * from './centered-layout';\nexport * from './checkbox';\nexport * from './combobox';\nexport { cx } from './cx';\nexport * from './date-input';\nexport * from './dialog';\nexport * from './divider';\nexport * from './empty-state';\nexport {\n Check as FallbackCheck,\n ChevronLeft as FallbackChevronLeft,\n ChevronRight as FallbackChevronRight,\n Cross as FallbackCross,\n Pin as FallbackPin,\n} from './fallback-glyphs';\nexport * from './field';\nexport * from './form-layout';\nexport * from './icon';\nexport * from './illustration';\nexport * from './layout';\nexport * from './link';\nexport type { LinkComponentProps } from './link-component';\nexport * from './menu';\nexport * from './page-layout';\nexport * from './popover';\nexport * from './progress';\nexport * from './reorder-control';\nexport * from './scroll-area';\nexport * from './section';\nexport * from './segment-group';\nexport * from './select';\nexport * from './show';\nexport * from './skeleton';\nexport * from './slider';\nexport * from './spinner';\nexport * from './split-layout';\nexport * from './sticky';\nexport * from './switch';\nexport * from './tabs';\nexport * from './text';\nexport * from './tooltip';\nexport * from './visually-hidden';\nexport * from './wizard-layout';\n"]}
|
|
1
|
+
{"version":3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,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC","sourcesContent":["export * from './alert';\nexport * from './avatar';\nexport * from './badge';\nexport * from './breadcrumb';\nexport * from './button';\nexport * from './calendar';\nexport * from './card';\nexport * from './centered-layout';\nexport * from './checkbox';\nexport * from './combobox';\nexport { cx } from './cx';\nexport * from './date-input';\nexport * from './dialog';\nexport * from './divider';\nexport * from './empty-state';\nexport {\n Check as FallbackCheck,\n ChevronLeft as FallbackChevronLeft,\n ChevronRight as FallbackChevronRight,\n Cross as FallbackCross,\n Pin as FallbackPin,\n} from './fallback-glyphs';\nexport * from './field';\nexport * from './form-layout';\nexport * from './icon';\nexport * from './illustration';\nexport * from './layout';\nexport * from './link';\nexport type { LinkComponentProps } from './link-component';\nexport * from './menu';\nexport * from './page-layout';\nexport * from './popover';\nexport * from './progress';\nexport * from './reorder-control';\nexport * from './scroll-area';\nexport * from './section';\nexport * from './segment-group';\nexport * from './select';\nexport * from './show';\nexport * from './side-panel-layout';\nexport * from './skeleton';\nexport * from './slider';\nexport * from './spinner';\nexport * from './split-layout';\nexport * from './sticky';\nexport * from './switch';\nexport * from './tabs';\nexport * from './text';\nexport * from './tooltip';\nexport * from './visually-hidden';\nexport * from './wizard-layout';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/side-panel-layout/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,oBAAoB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/side-panel-layout/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAA6B,MAAM,qBAAqB,CAAC","sourcesContent":["export { SidePanelLayout, type SidePanelLayoutProps } from './side-panel-layout';\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface SidePanelSlot {
|
|
2
|
+
/**
|
|
3
|
+
* The column a `Dialog` with `presentation="side"` portals its panel into.
|
|
4
|
+
* Null until the layout has mounted it: a side dialog open on mount waits
|
|
5
|
+
* for it rather than rendering into `<body>` first.
|
|
6
|
+
*/
|
|
7
|
+
container: HTMLDivElement | null;
|
|
8
|
+
/**
|
|
9
|
+
* Takes the slot for a panel that just opened and asks the panel holding
|
|
10
|
+
* it to close, so one panel shows at a time. Returns the release to call
|
|
11
|
+
* when the panel closes.
|
|
12
|
+
*/
|
|
13
|
+
claim: (close: () => void) => () => void;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The slot a `SidePanelLayout` keeps beside its content. Outside a layout
|
|
17
|
+
* there is none, and a side dialog opens as a modal.
|
|
18
|
+
*/
|
|
19
|
+
export declare const SidePanelSlotContext: import("react").Context<SidePanelSlot | undefined>;
|
|
20
|
+
//# sourceMappingURL=side-panel-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"side-panel-context.d.ts","sourceRoot":"","sources":["../../src/side-panel-layout/side-panel-context.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,SAAS,EAAE,cAAc,GAAG,IAAI,CAAC;IACjC;;;;OAIG;IACH,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;CAC1C;AAED;;;GAGG;AACH,eAAO,MAAM,oBAAoB,oDAAsD,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* The slot a `SidePanelLayout` keeps beside its content. Outside a layout
|
|
4
|
+
* there is none, and a side dialog opens as a modal.
|
|
5
|
+
*/
|
|
6
|
+
export const SidePanelSlotContext = createContext(undefined);
|
|
7
|
+
//# sourceMappingURL=side-panel-context.js.map
|
|
@@ -0,0 +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 column 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"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
@layer components {
|
|
2
|
+
/*
|
|
3
|
+
* The panel column stays empty until a side Dialog portals into it; React
|
|
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. From it the
|
|
6
|
+
* panel takes a column at the dialog's width and sticks under the app's
|
|
7
|
+
* header, its body scrolling inside it. Breakpoints are viewport tokens
|
|
8
|
+
* written as literals (`check:breakpoints`).
|
|
9
|
+
*/
|
|
10
|
+
.ds-side-panel-layout {
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
gap: var(--ds-side-panel-layout-gap);
|
|
14
|
+
min-width: 0;
|
|
15
|
+
|
|
16
|
+
& > .ds-side-panel-layout__main {
|
|
17
|
+
min-width: 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
& > .ds-side-panel-layout__panel {
|
|
21
|
+
order: -1;
|
|
22
|
+
display: flex;
|
|
23
|
+
flex-direction: column;
|
|
24
|
+
min-width: 0;
|
|
25
|
+
|
|
26
|
+
&:empty {
|
|
27
|
+
display: none;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@media (width >= 64rem) {
|
|
33
|
+
.ds-side-panel-layout {
|
|
34
|
+
display: grid;
|
|
35
|
+
grid-template-columns: minmax(0, 1fr);
|
|
36
|
+
align-items: start;
|
|
37
|
+
|
|
38
|
+
&:has(> .ds-side-panel-layout__panel:not(:empty)) {
|
|
39
|
+
grid-template-columns: minmax(0, 1fr) var(--ds-dialog-max-inline-size);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
& > .ds-side-panel-layout__panel {
|
|
43
|
+
order: 0;
|
|
44
|
+
position: sticky;
|
|
45
|
+
top: var(--ds-sticky-offset-top);
|
|
46
|
+
max-block-size: calc(
|
|
47
|
+
100dvh -
|
|
48
|
+
var(--ds-sticky-offset-top) -
|
|
49
|
+
var(--ds-side-panel-layout-gap)
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ark } from '@ark-ui/react/factory';
|
|
2
|
+
import { type ComponentProps } from 'react';
|
|
3
|
+
import './side-panel-layout.css';
|
|
4
|
+
/**
|
|
5
|
+
* No `asChild`: the layout renders its content and panel columns, and Ark's
|
|
6
|
+
* `asChild` clones exactly one.
|
|
7
|
+
*/
|
|
8
|
+
export type SidePanelLayoutProps = Omit<ComponentProps<typeof ark.div>, 'asChild'>;
|
|
9
|
+
/**
|
|
10
|
+
* Content with room for a side panel: a `Dialog` with `presentation="side"`
|
|
11
|
+
* opened anywhere inside it takes a column beside the content and pushes it
|
|
12
|
+
* narrower, so the list it was opened from stays in view and usable.
|
|
13
|
+
*
|
|
14
|
+
* From the `lg` viewport step up the panel sits at the end, held under the
|
|
15
|
+
* app's header while the content scrolls (`--ds-sticky-offset-top`). Below
|
|
16
|
+
* it the panel goes above the content, in the page's flow, and pushes it
|
|
17
|
+
* down. With no panel open the content takes the whole width. One panel
|
|
18
|
+
* shows at a time: opening another closes the one that was open.
|
|
19
|
+
*
|
|
20
|
+
* ```tsx
|
|
21
|
+
* <SidePanelLayout>
|
|
22
|
+
* <ActionList />
|
|
23
|
+
* <Dialog presentation="side" title="Add action" trigger={<Button>Add action</Button>}>
|
|
24
|
+
* <ActionForm />
|
|
25
|
+
* </Dialog>
|
|
26
|
+
* </SidePanelLayout>
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function SidePanelLayout({ className, children, ...props }: SidePanelLayoutProps): import("react/jsx-runtime").JSX.Element;
|
|
30
|
+
//# sourceMappingURL=side-panel-layout.d.ts.map
|
|
@@ -0,0 +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;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,eAAe,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,oBAAoB,2CAqBtF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ark } from '@ark-ui/react/factory';
|
|
3
|
+
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { cx } from '../cx';
|
|
5
|
+
import { SidePanelSlotContext } from './side-panel-context';
|
|
6
|
+
import './side-panel-layout.css';
|
|
7
|
+
/**
|
|
8
|
+
* Content with room for a side panel: a `Dialog` with `presentation="side"`
|
|
9
|
+
* opened anywhere inside it takes a column beside the content and pushes it
|
|
10
|
+
* narrower, so the list it was opened from stays in view and usable.
|
|
11
|
+
*
|
|
12
|
+
* From the `lg` viewport step up the panel sits at the end, held under the
|
|
13
|
+
* app's header while the content scrolls (`--ds-sticky-offset-top`). Below
|
|
14
|
+
* it the panel goes above the content, in the page's flow, and pushes it
|
|
15
|
+
* down. With no panel open the content takes the whole width. One panel
|
|
16
|
+
* shows at a time: opening another closes the one that was open.
|
|
17
|
+
*
|
|
18
|
+
* ```tsx
|
|
19
|
+
* <SidePanelLayout>
|
|
20
|
+
* <ActionList />
|
|
21
|
+
* <Dialog presentation="side" title="Add action" trigger={<Button>Add action</Button>}>
|
|
22
|
+
* <ActionForm />
|
|
23
|
+
* </Dialog>
|
|
24
|
+
* </SidePanelLayout>
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function SidePanelLayout({ className, children, ...props }) {
|
|
28
|
+
const [container, setContainer] = useState(null);
|
|
29
|
+
const closeHolder = useRef(null);
|
|
30
|
+
const claim = useCallback((close) => {
|
|
31
|
+
const previous = closeHolder.current;
|
|
32
|
+
closeHolder.current = close;
|
|
33
|
+
previous?.();
|
|
34
|
+
return () => {
|
|
35
|
+
if (closeHolder.current === close)
|
|
36
|
+
closeHolder.current = null;
|
|
37
|
+
};
|
|
38
|
+
}, []);
|
|
39
|
+
const slot = useMemo(() => ({ container, claim }), [container, claim]);
|
|
40
|
+
return (_jsx(SidePanelSlotContext.Provider, { value: slot, children: _jsxs(ark.div, { className: cx('ds-side-panel-layout', className), ...props, children: [_jsx("div", { className: "ds-side-panel-layout__main", children: children }), _jsx("div", { ref: setContainer, className: "ds-side-panel-layout__panel" })] }) }));
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=side-panel-layout.js.map
|
|
@@ -0,0 +1 @@
|
|
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C,sBAAsB,EAAE,SAAS,CAAC,KAAM,KAAK,aAClE,cAAK,SAAS,EAAC,4BAA4B,YAAE,QAAQ,GAAO,EAC5D,cAAK,GAAG,EAAE,YAAY,EAAE,SAAS,EAAC,6BAA6B,GAAG,IAC1D,GACoB,CACjC,CAAC;AACJ,CAAC","sourcesContent":["import { ark } from '@ark-ui/react/factory';\nimport { type ComponentProps, useCallback, useMemo, useRef, useState } from 'react';\nimport { 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 panel columns, 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 takes a column beside the content and pushes it\n * narrower, so the list it was opened from stays in view and usable.\n *\n * From the `lg` viewport step up the panel sits at the end, held under the\n * app's header while the content scrolls (`--ds-sticky-offset-top`). Below\n * it the panel goes above the content, in the page's flow, and pushes it\n * down. With no panel open the content takes the whole width. One panel\n * shows at a time: opening another closes the one that was open.\n *\n * ```tsx\n * <SidePanelLayout>\n * <ActionList />\n * <Dialog presentation=\"side\" title=\"Add action\" trigger={<Button>Add action</Button>}>\n * <ActionForm />\n * </Dialog>\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../src/tooltip/tooltip.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../src/tooltip/tooltip.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,SAAS,EAAmC,MAAM,OAAO,CAAC;AAE3F,OAAO,eAAe,CAAC;AAEvB,MAAM,MAAM,gBAAgB,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AAEnE,MAAM,WAAW,YAAY;IAC3B,iDAAiD;IACjD,OAAO,EAAE,SAAS,CAAC;IACnB,iEAAiE;IACjE,QAAQ,EAAE,YAAY,CAAC;QAAE,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACxC;;;;;OAKG;IACH,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC;IAC/B,uEAAuE;IACvE,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,OAAO,CAAC,EACtB,OAAO,EACP,QAAQ,EACR,IAAoB,EACpB,SAAiB,GAClB,EAAE,YAAY,2CA0Dd"}
|
package/dist/tooltip/tooltip.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Portal } from '@ark-ui/react/portal';
|
|
3
3
|
import { Tooltip as ArkTooltip } from '@ark-ui/react/tooltip';
|
|
4
|
-
import { useContext } from 'react';
|
|
4
|
+
import { useContext, useEffect, useState } from 'react';
|
|
5
5
|
import { PortalContainerContext } from '../portal-container';
|
|
6
6
|
import './tooltip.css';
|
|
7
7
|
/**
|
|
@@ -36,6 +36,23 @@ export function Tooltip({ content, children, kind = 'description', placement = '
|
|
|
36
36
|
* with keeps the lookup on the real element.
|
|
37
37
|
*/
|
|
38
38
|
const triggerId = children.props.id;
|
|
39
|
-
|
|
39
|
+
const [open, setOpen] = useState(false);
|
|
40
|
+
/*
|
|
41
|
+
* Escape hides the caption and goes on to whatever else it means: Zag's
|
|
42
|
+
* own Escape handling stops the key at the document, so a keyboard drag
|
|
43
|
+
* could not be cancelled and a dialog would not close while a caption
|
|
44
|
+
* showed.
|
|
45
|
+
*/
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (!open)
|
|
48
|
+
return;
|
|
49
|
+
const hide = (event) => {
|
|
50
|
+
if (event.key === 'Escape')
|
|
51
|
+
setOpen(false);
|
|
52
|
+
};
|
|
53
|
+
document.addEventListener('keydown', hide);
|
|
54
|
+
return () => document.removeEventListener('keydown', hide);
|
|
55
|
+
}, [open]);
|
|
56
|
+
return (_jsxs(ArkTooltip.Root, { lazyMount: true, unmountOnExit: true, positioning: { placement, gutter: 6 }, ids: triggerId ? { trigger: triggerId } : undefined, open: open, onOpenChange: (details) => setOpen(details.open), closeOnEscape: false, children: [_jsx(ArkTooltip.Trigger, { asChild: true, "aria-describedby": triggerDescription, children: children }), _jsx(Portal, { container: portalContainer, children: _jsx(ArkTooltip.Positioner, { children: _jsx(ArkTooltip.Content, { className: "ds-tooltip__content", "aria-hidden": kind === 'label' ? true : undefined, children: content }) }) })] }));
|
|
40
57
|
}
|
|
41
58
|
//# sourceMappingURL=tooltip.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip.js","sourceRoot":"","sources":["../../src/tooltip/tooltip.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OA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AAC,CAAC;IAC7D,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAEX,OAAO,CACL,MAAC,UAAU,CAAC,IAAI,IACd,SAAS,QACT,aAAa,QACb,WAAW,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,EACrC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,SAAS,EACnD,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAChD,aAAa,EAAE,KAAK,aAEpB,KAAC,UAAU,CAAC,OAAO,IAAC,OAAO,4BAAmB,kBAAkB,YAC7D,QAAQ,GACU,EACrB,KAAC,MAAM,IAAC,SAAS,EAAE,eAAe,YAChC,KAAC,UAAU,CAAC,UAAU,cACpB,KAAC,UAAU,CAAC,OAAO,IACjB,SAAS,EAAC,qBAAqB,iBAClB,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,YAE/C,OAAO,GACW,GACC,GACjB,IACO,CACnB,CAAC;AACJ,CAAC","sourcesContent":["import { Portal } from '@ark-ui/react/portal';\nimport { Tooltip as ArkTooltip } from '@ark-ui/react/tooltip';\nimport { type ReactElement, type ReactNode, useContext, useEffect, useState } from 'react';\nimport { PortalContainerContext } from '../portal-container';\nimport './tooltip.css';\n\nexport type TooltipPlacement = 'top' | 'bottom' | 'left' | 'right';\n\nexport interface TooltipProps {\n /** The caption: a few words, never a control. */\n content: ReactNode;\n /** The element it captions. It keeps its own accessible name. */\n children: ReactElement<{ id?: string }>;\n /**\n * What the caption is to assistive tech. `description` (default) adds it\n * to the trigger's description while it shows. `label` says it repeats the\n * trigger's accessible name, as an icon-only button's caption does, so it\n * is left out and the name is announced once.\n */\n kind?: 'description' | 'label';\n /** Side of the trigger it opens on, flipping when there is no room. */\n placement?: TooltipPlacement;\n}\n\n/**\n * A caption that shows while the pointer rests on its trigger or the\n * keyboard focuses it, built on Ark UI's Tooltip. Esc and moving away hide\n * it; it never takes focus and holds nothing to click.\n *\n * ```tsx\n * <Tooltip content=\"Archive\">\n * <button type=\"button\" aria-label=\"Archive Run 10k\">…</button>\n * </Tooltip>\n * ```\n *\n * `IconButton` shows one with its label by default. Reach for it directly\n * for another control whose meaning its glyph alone does not say. Anything\n * a user must read to act belongs on the page, not in a tooltip: touch\n * screens never show one.\n */\nexport function Tooltip({\n content,\n children,\n kind = 'description',\n placement = 'top',\n}: TooltipProps) {\n const portalContainer = useContext(PortalContainerContext);\n /*\n * Zag points the trigger's description at the caption while it shows, and\n * only a defined value overrides it, so a label caption passes an empty\n * one. A description the trigger sets itself still wins.\n */\n const triggerDescription = kind === 'label' ? '' : undefined;\n /*\n * A trigger that is itself another part's asChild trigger (a Menu's, a\n * Dialog's close button, a Calendar arrow) takes that part's id, and the\n * child's props win the merge, so Zag would look for its own id and find\n * nothing to place the caption against. Naming the id the trigger ends up\n * with keeps the lookup on the real element.\n */\n const triggerId = children.props.id;\n const [open, setOpen] = useState(false);\n\n /*\n * Escape hides the caption and goes on to whatever else it means: Zag's\n * own Escape handling stops the key at the document, so a keyboard drag\n * could not be cancelled and a dialog would not close while a caption\n * showed.\n */\n useEffect(() => {\n if (!open) return;\n const hide = (event: KeyboardEvent) => {\n if (event.key === 'Escape') setOpen(false);\n };\n document.addEventListener('keydown', hide);\n return () => document.removeEventListener('keydown', hide);\n }, [open]);\n\n return (\n <ArkTooltip.Root\n lazyMount\n unmountOnExit\n positioning={{ placement, gutter: 6 }}\n ids={triggerId ? { trigger: triggerId } : undefined}\n open={open}\n onOpenChange={(details) => setOpen(details.open)}\n closeOnEscape={false}\n >\n <ArkTooltip.Trigger asChild aria-describedby={triggerDescription}>\n {children}\n </ArkTooltip.Trigger>\n <Portal container={portalContainer}>\n <ArkTooltip.Positioner>\n <ArkTooltip.Content\n className=\"ds-tooltip__content\"\n aria-hidden={kind === 'label' ? true : undefined}\n >\n {content}\n </ArkTooltip.Content>\n </ArkTooltip.Positioner>\n </Portal>\n </ArkTooltip.Root>\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.27.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -144,6 +144,10 @@
|
|
|
144
144
|
"types": "./dist/show/index.d.ts",
|
|
145
145
|
"import": "./dist/show/index.js"
|
|
146
146
|
},
|
|
147
|
+
"./side-panel-layout": {
|
|
148
|
+
"types": "./dist/side-panel-layout/index.d.ts",
|
|
149
|
+
"import": "./dist/side-panel-layout/index.js"
|
|
150
|
+
},
|
|
147
151
|
"./skeleton": {
|
|
148
152
|
"types": "./dist/skeleton/index.d.ts",
|
|
149
153
|
"import": "./dist/skeleton/index.js"
|
|
@@ -304,6 +308,10 @@
|
|
|
304
308
|
"types": "./dist/show/show.css.d.ts",
|
|
305
309
|
"default": "./dist/show/show.css"
|
|
306
310
|
},
|
|
311
|
+
"./css/side-panel-layout": {
|
|
312
|
+
"types": "./dist/side-panel-layout/side-panel-layout.css.d.ts",
|
|
313
|
+
"default": "./dist/side-panel-layout/side-panel-layout.css"
|
|
314
|
+
},
|
|
307
315
|
"./css/skeleton": {
|
|
308
316
|
"types": "./dist/skeleton/skeleton.css.d.ts",
|
|
309
317
|
"default": "./dist/skeleton/skeleton.css"
|
|
@@ -372,7 +380,7 @@
|
|
|
372
380
|
},
|
|
373
381
|
"devDependencies": {
|
|
374
382
|
"@manakind/ds-config": "*",
|
|
375
|
-
"@manakind/manuia-tokens": "0.
|
|
383
|
+
"@manakind/manuia-tokens": "0.26.0",
|
|
376
384
|
"@testing-library/jest-dom": "^6.9.1",
|
|
377
385
|
"@testing-library/react": "^16.3.2",
|
|
378
386
|
"@testing-library/user-event": "^14.6.1",
|