@mohirlab/react 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/dialog/dialog.css.d.ts +30 -0
- package/dist/components/dialog/dialog.css.d.ts.map +1 -0
- package/dist/components/dialog/dialog.d.ts +34 -0
- package/dist/components/dialog/dialog.d.ts.map +1 -0
- package/dist/components/dialog/dialog.js +159 -0
- package/dist/components/dialog/dialog.js.map +1 -0
- package/dist/components/dialog/dialog.styles.js +33 -0
- package/dist/components/dialog/dialog.styles.js.map +1 -0
- package/dist/components/dialog/index.d.ts +2 -0
- package/dist/components/popover/index.d.ts +3 -0
- package/dist/components/popover/popover.css.d.ts +18 -0
- package/dist/components/popover/popover.css.d.ts.map +1 -0
- package/dist/components/popover/popover.d.ts +45 -0
- package/dist/components/popover/popover.d.ts.map +1 -0
- package/dist/components/popover/popover.js +123 -0
- package/dist/components/popover/popover.js.map +1 -0
- package/dist/components/popover/popover.styles.js +36 -0
- package/dist/components/popover/popover.styles.js.map +1 -0
- package/dist/components/toast/index.d.ts +2 -0
- package/dist/components/toast/toast.d.ts +37 -0
- package/dist/components/toast/toast.d.ts.map +1 -0
- package/dist/components/toast/toast.js +142 -0
- package/dist/components/toast/toast.js.map +1 -0
- package/dist/components/toast/toast.styles.js +24 -0
- package/dist/components/toast/toast.styles.js.map +1 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/use-disclosure.d.ts +9 -0
- package/dist/hooks/use-disclosure.d.ts.map +1 -0
- package/dist/hooks/use-disclosure.js +16 -0
- package/dist/hooks/use-disclosure.js.map +1 -0
- package/dist/hooks/use-presence.d.ts +18 -0
- package/dist/hooks/use-presence.d.ts.map +1 -0
- package/dist/hooks/use-presence.js +55 -0
- package/dist/hooks/use-presence.js.map +1 -0
- package/dist/index.d.ts +11 -1
- package/dist/index.js +7 -2
- package/dist/styles.css +604 -92
- package/package.json +6 -5
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { RecipeVariants } from "@vanilla-extract/recipes";
|
|
2
|
+
declare const dialogWidth: `var(--${string})`;
|
|
3
|
+
export declare const dialog: import("@vanilla-extract/recipes").RuntimeFn<{
|
|
4
|
+
placement: {
|
|
5
|
+
center: import("@vanilla-extract/css").StyleRule;
|
|
6
|
+
sheet: import("@vanilla-extract/css").StyleRule;
|
|
7
|
+
/** A bottom sheet on phones, a centered dialog from tablet up. */
|
|
8
|
+
auto: import("@vanilla-extract/css").StyleRule;
|
|
9
|
+
};
|
|
10
|
+
size: {
|
|
11
|
+
sm: {
|
|
12
|
+
vars: {
|
|
13
|
+
[dialogWidth]: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
md: {
|
|
17
|
+
vars: {
|
|
18
|
+
[dialogWidth]: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
lg: {
|
|
22
|
+
vars: {
|
|
23
|
+
[dialogWidth]: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}>;
|
|
28
|
+
export type DialogVariants = NonNullable<RecipeVariants<typeof dialog>>;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=dialog.css.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialog.css.d.ts","names":[],"sources":["../../../src/components/dialog/dialog.css.ts"],"mappings":";cAWM;qBAmBO,2CAAM;;;;;;;;;;SA4BE;;;;;SACA;;;;;SACA;;;;;YAMT,iBAAiB,YAAY,sBAAsB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ComponentPropsWithRef, ReactNode } from "react";
|
|
2
|
+
import { DialogVariants } from "./dialog.css.js";
|
|
3
|
+
export interface DialogProps extends Omit<ComponentPropsWithRef<'dialog'>, 'open' | 'title' | 'role'> {
|
|
4
|
+
open: boolean;
|
|
5
|
+
onOpenChange: (open: boolean) => void;
|
|
6
|
+
/** Required: names the dialog for assistive technology. */
|
|
7
|
+
title: ReactNode;
|
|
8
|
+
description?: ReactNode;
|
|
9
|
+
/** `auto` (default): bottom sheet on phones, centered from tablet up. */
|
|
10
|
+
placement?: DialogVariants['placement'];
|
|
11
|
+
size?: DialogVariants['size'];
|
|
12
|
+
/**
|
|
13
|
+
* Whether Escape, the backdrop and the close button may dismiss it. Turn off for
|
|
14
|
+
* decisions the user must make; pair with `role="alertdialog"`.
|
|
15
|
+
*/
|
|
16
|
+
dismissible?: boolean;
|
|
17
|
+
role?: 'dialog' | 'alertdialog';
|
|
18
|
+
/** Label of the close button, for localisation. */
|
|
19
|
+
closeLabel?: string;
|
|
20
|
+
children?: ReactNode;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A modal dialog on the native `<dialog>` element: the browser traps focus, makes the
|
|
24
|
+
* rest of the page inert, handles Escape and returns focus when it closes.
|
|
25
|
+
*/
|
|
26
|
+
export declare function Dialog({ open, onOpenChange, title, description, placement, size, dismissible, role, closeLabel, className, children, ...rest }: DialogProps): import("react").JSX.Element | null;
|
|
27
|
+
/** Scrollable content area of a dialog. */
|
|
28
|
+
export declare function DialogBody({ className, ...rest }: ComponentPropsWithRef<'div'>): import("react").JSX.Element;
|
|
29
|
+
/**
|
|
30
|
+
* The dialog's buttons. Put the primary action last: it lands on the right of a
|
|
31
|
+
* centered dialog and on top of the full-width stack in a sheet.
|
|
32
|
+
*/
|
|
33
|
+
export declare function DialogActions({ className, ...rest }: ComponentPropsWithRef<'div'>): import("react").JSX.Element;
|
|
34
|
+
//# sourceMappingURL=dialog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialog.d.ts","names":["styles.DialogVariants"],"sources":["../../../src/components/dialog/dialog.tsx"],"mappings":";;iBAiBiB,oBAAoB,KAAK;EACxC;EACA,eAAe;;EAEf,OAAO;EACP,cAAc;;EAEd,YAAYA;EACZ,OAAOA;;;;;EAKP;EACA;;EAEA;EACA,WAAW;;;;;;wBAUG,SACd,MACA,cACA,OACA,aACA,WACA,MACA,aACA,MACA,YACA,WACA,aACG,QACF,8BAAW,IAAA;;wBAgJE,aAAa,cAAc,QAAQ,+CAA4B,IAAA;;;;;wBAQ/D,gBAAgB,cAAc,QAAQ,+CAA4B,IAAA"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { useEffect, useId, useLayoutEffect, useRef } from "react";
|
|
2
|
+
import { iconClose } from "@mohirlab/icons";
|
|
3
|
+
import { mq } from "@mohirlab/sprinkles";
|
|
4
|
+
import { usePresence } from "../../hooks/use-presence.js";
|
|
5
|
+
import { cx } from "../../utils/cx.js";
|
|
6
|
+
import { Button } from "../button/button.js";
|
|
7
|
+
import { Icon } from "../icon/icon.js";
|
|
8
|
+
import { actions, body, dialog, dragArea, handle, header, title } from "./dialog.styles.js";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
// src/components/dialog/dialog.tsx
|
|
11
|
+
const DISMISS_DISTANCE = .3;
|
|
12
|
+
const DISMISS_VELOCITY = .6;
|
|
13
|
+
/**
|
|
14
|
+
* A modal dialog on the native `<dialog>` element: the browser traps focus, makes the
|
|
15
|
+
* rest of the page inert, handles Escape and returns focus when it closes.
|
|
16
|
+
*/
|
|
17
|
+
function Dialog({ open, onOpenChange, title: title$1, description: description$1, placement = "auto", size, dismissible = true, role = "dialog", closeLabel = "Close", className, children, ...rest }) {
|
|
18
|
+
const ref = useRef(null);
|
|
19
|
+
const titleId = useId();
|
|
20
|
+
const descriptionId = useId();
|
|
21
|
+
const { mounted, state } = usePresence(open, ref, { onExitComplete: () => ref.current?.open && ref.current.close() });
|
|
22
|
+
useLayoutEffect(() => {
|
|
23
|
+
const el = ref.current;
|
|
24
|
+
if (mounted && open && el && !el.open) el.showModal();
|
|
25
|
+
}, [mounted, open]);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!mounted) return;
|
|
28
|
+
const root = document.documentElement;
|
|
29
|
+
const previous = root.style.overflow;
|
|
30
|
+
root.style.overflow = "hidden";
|
|
31
|
+
return () => {
|
|
32
|
+
root.style.overflow = previous;
|
|
33
|
+
};
|
|
34
|
+
}, [mounted]);
|
|
35
|
+
const requestClose = () => {
|
|
36
|
+
if (dismissible) onOpenChange(false);
|
|
37
|
+
};
|
|
38
|
+
const drag = useRef(null);
|
|
39
|
+
const isSheetNow = () => placement === "sheet" || placement === "auto" && !window.matchMedia(mq("tablet")).matches;
|
|
40
|
+
const onPointerDown = (event) => {
|
|
41
|
+
if (!dismissible || !isSheetNow() || event.target.closest("button, a, input")) return;
|
|
42
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
43
|
+
drag.current = {
|
|
44
|
+
startY: event.clientY,
|
|
45
|
+
startTime: performance.now(),
|
|
46
|
+
dy: 0
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
const onPointerMove = (event) => {
|
|
50
|
+
const el = ref.current;
|
|
51
|
+
if (!drag.current || !el) return;
|
|
52
|
+
drag.current.dy = Math.max(0, event.clientY - drag.current.startY);
|
|
53
|
+
el.style.transition = "none";
|
|
54
|
+
el.style.transform = `translateY(${drag.current.dy}px)`;
|
|
55
|
+
};
|
|
56
|
+
const onPointerUp = () => {
|
|
57
|
+
const el = ref.current;
|
|
58
|
+
const current = drag.current;
|
|
59
|
+
drag.current = null;
|
|
60
|
+
if (!current || !el) return;
|
|
61
|
+
const velocity = current.dy / Math.max(1, performance.now() - current.startTime);
|
|
62
|
+
if (current.dy > el.offsetHeight * DISMISS_DISTANCE || velocity > DISMISS_VELOCITY) {
|
|
63
|
+
onOpenChange(false);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
el.style.transition = "";
|
|
67
|
+
el.style.transform = "";
|
|
68
|
+
};
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (!mounted && ref.current) {
|
|
71
|
+
ref.current.style.transform = "";
|
|
72
|
+
ref.current.style.transition = "";
|
|
73
|
+
}
|
|
74
|
+
}, [mounted]);
|
|
75
|
+
if (!mounted) return null;
|
|
76
|
+
return /* @__PURE__ */ jsxs("dialog", {
|
|
77
|
+
...rest,
|
|
78
|
+
ref,
|
|
79
|
+
role: role === "alertdialog" ? "alertdialog" : void 0,
|
|
80
|
+
"aria-modal": "true",
|
|
81
|
+
"aria-labelledby": titleId,
|
|
82
|
+
"aria-describedby": description$1 ? descriptionId : void 0,
|
|
83
|
+
"data-state": state,
|
|
84
|
+
"data-placement": placement,
|
|
85
|
+
className: cx(dialog({
|
|
86
|
+
placement,
|
|
87
|
+
size
|
|
88
|
+
}), className),
|
|
89
|
+
onCancel: (event) => {
|
|
90
|
+
event.preventDefault();
|
|
91
|
+
requestClose();
|
|
92
|
+
},
|
|
93
|
+
onClose: () => {
|
|
94
|
+
if (open) onOpenChange(false);
|
|
95
|
+
},
|
|
96
|
+
onClick: (event) => {
|
|
97
|
+
if (event.target !== ref.current) return;
|
|
98
|
+
const box = ref.current.getBoundingClientRect();
|
|
99
|
+
if (!(event.clientX >= box.left && event.clientX <= box.right && event.clientY >= box.top && event.clientY <= box.bottom)) requestClose();
|
|
100
|
+
},
|
|
101
|
+
children: [
|
|
102
|
+
/* @__PURE__ */ jsxs("div", {
|
|
103
|
+
className: dragArea,
|
|
104
|
+
onPointerDown,
|
|
105
|
+
onPointerMove,
|
|
106
|
+
onPointerUp,
|
|
107
|
+
onPointerCancel: onPointerUp,
|
|
108
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
109
|
+
className: handle,
|
|
110
|
+
"aria-hidden": "true"
|
|
111
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
112
|
+
className: header,
|
|
113
|
+
children: [/* @__PURE__ */ jsx("h2", {
|
|
114
|
+
id: titleId,
|
|
115
|
+
className: title,
|
|
116
|
+
children: title$1
|
|
117
|
+
}), description$1 && /* @__PURE__ */ jsx("p", {
|
|
118
|
+
id: descriptionId,
|
|
119
|
+
className: "ml_iy25f5c",
|
|
120
|
+
children: description$1
|
|
121
|
+
})]
|
|
122
|
+
})]
|
|
123
|
+
}),
|
|
124
|
+
children,
|
|
125
|
+
dismissible && /* @__PURE__ */ jsx("span", {
|
|
126
|
+
className: "ml_iy25f5d",
|
|
127
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
128
|
+
appearance: "ghost",
|
|
129
|
+
tone: "neutral",
|
|
130
|
+
size: "sm",
|
|
131
|
+
iconOnly: true,
|
|
132
|
+
"aria-label": closeLabel,
|
|
133
|
+
onClick: requestClose,
|
|
134
|
+
children: /* @__PURE__ */ jsx(Icon, { icon: iconClose })
|
|
135
|
+
})
|
|
136
|
+
})
|
|
137
|
+
]
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/** Scrollable content area of a dialog. */
|
|
141
|
+
function DialogBody({ className, ...rest }) {
|
|
142
|
+
return /* @__PURE__ */ jsx("div", {
|
|
143
|
+
...rest,
|
|
144
|
+
className: cx(body, className)
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The dialog's buttons. Put the primary action last: it lands on the right of a
|
|
149
|
+
* centered dialog and on top of the full-width stack in a sheet.
|
|
150
|
+
*/
|
|
151
|
+
function DialogActions({ className, ...rest }) {
|
|
152
|
+
return /* @__PURE__ */ jsx("div", {
|
|
153
|
+
...rest,
|
|
154
|
+
className: cx(actions, className)
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
export { Dialog, DialogActions, DialogBody };
|
|
158
|
+
|
|
159
|
+
//# sourceMappingURL=dialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialog.js","names":["title","description","styles.dialog","styles.dragArea","styles.handle","styles.header","styles.title","styles.body","styles.actions"],"sources":["../../../src/components/dialog/dialog.tsx"],"sourcesContent":["import {\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n type ComponentPropsWithRef,\n type PointerEvent as ReactPointerEvent,\n type ReactNode,\n} from 'react';\nimport { iconClose } from '@mohirlab/icons';\nimport { mq } from '@mohirlab/sprinkles';\nimport { usePresence } from '../../hooks/use-presence';\nimport { cx } from '../../utils/cx';\nimport { Button } from '../button';\nimport { Icon } from '../icon';\nimport * as styles from './dialog.css';\n\nexport interface DialogProps extends Omit<ComponentPropsWithRef<'dialog'>, 'open' | 'title' | 'role'> {\n open: boolean;\n onOpenChange: (open: boolean) => void;\n /** Required: names the dialog for assistive technology. */\n title: ReactNode;\n description?: ReactNode;\n /** `auto` (default): bottom sheet on phones, centered from tablet up. */\n placement?: styles.DialogVariants['placement'];\n size?: styles.DialogVariants['size'];\n /**\n * Whether Escape, the backdrop and the close button may dismiss it. Turn off for\n * decisions the user must make; pair with `role=\"alertdialog\"`.\n */\n dismissible?: boolean;\n role?: 'dialog' | 'alertdialog';\n /** Label of the close button, for localisation. */\n closeLabel?: string;\n children?: ReactNode;\n}\n\nconst DISMISS_DISTANCE = 0.3; // fraction of the sheet's height\nconst DISMISS_VELOCITY = 0.6; // px per ms\n\n/**\n * A modal dialog on the native `<dialog>` element: the browser traps focus, makes the\n * rest of the page inert, handles Escape and returns focus when it closes.\n */\nexport function Dialog({\n open,\n onOpenChange,\n title,\n description,\n placement = 'auto',\n size,\n dismissible = true,\n role = 'dialog',\n closeLabel = 'Close',\n className,\n children,\n ...rest\n}: DialogProps) {\n const ref = useRef<HTMLDialogElement>(null);\n const titleId = useId();\n const descriptionId = useId();\n const { mounted, state } = usePresence(open, ref, {\n onExitComplete: () => ref.current?.open && ref.current.close(),\n });\n\n // Open as a modal as soon as the element exists.\n useLayoutEffect(() => {\n const el = ref.current;\n if (mounted && open && el && !el.open) el.showModal();\n }, [mounted, open]);\n\n // The page behind must not scroll while a modal is open.\n useEffect(() => {\n if (!mounted) return;\n const root = document.documentElement;\n const previous = root.style.overflow;\n root.style.overflow = 'hidden';\n return () => {\n root.style.overflow = previous;\n };\n }, [mounted]);\n\n const requestClose = () => {\n if (dismissible) onOpenChange(false);\n };\n\n // --- Drag a sheet down to dismiss it --------------------------------------------\n const drag = useRef<{ startY: number; startTime: number; dy: number } | null>(null);\n const isSheetNow = () =>\n placement === 'sheet' || (placement === 'auto' && !window.matchMedia(mq('tablet')).matches);\n\n const onPointerDown = (event: ReactPointerEvent<HTMLDivElement>) => {\n if (!dismissible || !isSheetNow() || (event.target as Element).closest('button, a, input')) return;\n event.currentTarget.setPointerCapture(event.pointerId);\n drag.current = { startY: event.clientY, startTime: performance.now(), dy: 0 };\n };\n const onPointerMove = (event: ReactPointerEvent<HTMLDivElement>) => {\n const el = ref.current;\n if (!drag.current || !el) return;\n drag.current.dy = Math.max(0, event.clientY - drag.current.startY);\n el.style.transition = 'none';\n el.style.transform = `translateY(${drag.current.dy}px)`;\n };\n const onPointerUp = () => {\n const el = ref.current;\n const current = drag.current;\n drag.current = null;\n if (!current || !el) return;\n const velocity = current.dy / Math.max(1, performance.now() - current.startTime);\n if (current.dy > el.offsetHeight * DISMISS_DISTANCE || velocity > DISMISS_VELOCITY) {\n // The exit animation continues from where the finger let go.\n onOpenChange(false);\n return;\n }\n el.style.transition = '';\n el.style.transform = '';\n };\n\n // Reset any drag offset once the sheet has gone.\n useEffect(() => {\n if (!mounted && ref.current) {\n ref.current.style.transform = '';\n ref.current.style.transition = '';\n }\n }, [mounted]);\n\n if (!mounted) return null;\n\n return (\n // oxlint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions -- backdrop click; Escape is the keyboard equivalent\n <dialog\n {...rest}\n ref={ref}\n role={role === 'alertdialog' ? 'alertdialog' : undefined}\n aria-modal=\"true\"\n aria-labelledby={titleId}\n aria-describedby={description ? descriptionId : undefined}\n data-state={state}\n data-placement={placement}\n className={cx(styles.dialog({ placement, size }), className)}\n onCancel={(event) => {\n // Escape: we close through state so the exit animation can run.\n event.preventDefault();\n requestClose();\n }}\n onClose={() => {\n // Closed by the browser or a <form method=\"dialog\">: keep state in sync.\n if (open) onOpenChange(false);\n }}\n onClick={(event) => {\n // A click on the backdrop lands on the <dialog> itself, outside its box.\n if (event.target !== ref.current) return;\n const box = ref.current.getBoundingClientRect();\n const inside =\n event.clientX >= box.left &&\n event.clientX <= box.right &&\n event.clientY >= box.top &&\n event.clientY <= box.bottom;\n if (!inside) requestClose();\n }}\n >\n <div\n className={styles.dragArea}\n onPointerDown={onPointerDown}\n onPointerMove={onPointerMove}\n onPointerUp={onPointerUp}\n onPointerCancel={onPointerUp}\n >\n <span className={styles.handle} aria-hidden=\"true\" />\n <div className={styles.header}>\n <h2 id={titleId} className={styles.title}>\n {title}\n </h2>\n {description && (\n <p id={descriptionId} className={styles.description}>\n {description}\n </p>\n )}\n </div>\n </div>\n {children}\n {/* Last in tab order, so focus starts in the content; shown top-right. */}\n {dismissible && (\n <span className={styles.close}>\n <Button\n appearance=\"ghost\"\n tone=\"neutral\"\n size=\"sm\"\n iconOnly\n aria-label={closeLabel}\n onClick={requestClose}\n >\n <Icon icon={iconClose} />\n </Button>\n </span>\n )}\n </dialog>\n );\n}\n\n/** Scrollable content area of a dialog. */\nexport function DialogBody({ className, ...rest }: ComponentPropsWithRef<'div'>) {\n return <div {...rest} className={cx(styles.body, className)} />;\n}\n\n/**\n * The dialog's buttons. Put the primary action last: it lands on the right of a\n * centered dialog and on top of the full-width stack in a sheet.\n */\nexport function DialogActions({ className, ...rest }: ComponentPropsWithRef<'div'>) {\n return <div {...rest} className={cx(styles.actions, className)} />;\n}\n"],"mappings":";;;;;;;;;;AAqCA,MAAM,mBAAmB;AACzB,MAAM,mBAAmB;;;;;AAMzB,SAAgB,OAAO,EACrB,MACA,cACAA,OAAAA,SACAC,aAAAA,eACA,YAAY,QACZ,MACA,cAAc,MACd,OAAO,UACP,aAAa,SACb,WACA,UACA,GAAG,QACW;CACd,MAAM,MAAM,OAA0B,IAAI;CAC1C,MAAM,UAAU,MAAM;CACtB,MAAM,gBAAgB,MAAM;CAC5B,MAAM,EAAE,SAAS,UAAU,YAAY,MAAM,KAAK,EAChD,sBAAsB,IAAI,SAAS,QAAQ,IAAI,QAAQ,MAAM,EAC/D,CAAC;CAGD,sBAAsB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QAAD;KACE,YAAW;KACX,MAAK;KACL,MAAK;KACL,UAAA;KACA,cAAY;KACZ,SAAS;KAET,UAAA,oBAAC,MAAD,EAAM,MAAM,UAAY,CAAA;IAClB,CAAA;GACJ,CAAA;EAEF;;AAEZ;;AAGA,SAAgB,WAAW,EAAE,WAAW,GAAG,QAAsC;CAC/E,OAAO,oBAAC,OAAD;EAAK,GAAI;EAAM,WAAW,GAAGM,MAAa,SAAS;CAAI,CAAA;AAChE;;;;;AAMA,SAAgB,cAAc,EAAE,WAAW,GAAG,QAAsC;CAClF,OAAO,oBAAC,OAAD;EAAK,GAAI;EAAM,WAAW,GAAGC,SAAgB,SAAS;CAAI,CAAA;AACnE"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createRuntimeFn } from "@vanilla-extract/recipes/createRuntimeFn";
|
|
2
|
+
// src/components/dialog/dialog.css.ts
|
|
3
|
+
var actions = "ml_iy25f5f";
|
|
4
|
+
var body = "ml_iy25f5e";
|
|
5
|
+
var close = "ml_iy25f5d";
|
|
6
|
+
var description = "ml_iy25f5c";
|
|
7
|
+
var dialog = createRuntimeFn({
|
|
8
|
+
defaultClassName: "ml_iy25f51",
|
|
9
|
+
variantClassNames: {
|
|
10
|
+
placement: {
|
|
11
|
+
center: "ml_placement_center_iy25f52",
|
|
12
|
+
sheet: "ml_placement_sheet_iy25f53",
|
|
13
|
+
auto: "ml_placement_auto_iy25f54"
|
|
14
|
+
},
|
|
15
|
+
size: {
|
|
16
|
+
sm: "ml_size_sm_iy25f55",
|
|
17
|
+
md: "ml_size_md_iy25f56",
|
|
18
|
+
lg: "ml_size_lg_iy25f57"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
defaultVariants: {
|
|
22
|
+
placement: "auto",
|
|
23
|
+
size: "md"
|
|
24
|
+
},
|
|
25
|
+
compoundVariants: []
|
|
26
|
+
});
|
|
27
|
+
var dragArea = "ml_iy25f59";
|
|
28
|
+
var handle = "ml_iy25f58";
|
|
29
|
+
var header = "ml_iy25f5a";
|
|
30
|
+
var title = "ml_iy25f5b";
|
|
31
|
+
export { actions, body, close, description, dialog, dragArea, handle, header, title };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=dialog.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialog.styles.js","names":[],"sources":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import "@vanilla-extract/recipes";
|
|
2
|
+
/**
|
|
3
|
+
* Where the panel sits relative to its trigger, as CSS `position-area` values.
|
|
4
|
+
* `start`/`end` are logical, so they follow right-to-left text.
|
|
5
|
+
*/
|
|
6
|
+
declare const areas: {
|
|
7
|
+
readonly top: 'block-start';
|
|
8
|
+
readonly 'top-start': 'block-start span-inline-end';
|
|
9
|
+
readonly 'top-end': 'block-start span-inline-start';
|
|
10
|
+
readonly bottom: 'block-end';
|
|
11
|
+
readonly 'bottom-start': 'block-end span-inline-end';
|
|
12
|
+
readonly 'bottom-end': 'block-end span-inline-start';
|
|
13
|
+
readonly start: 'inline-start';
|
|
14
|
+
readonly end: 'inline-end';
|
|
15
|
+
};
|
|
16
|
+
export type Placement = keyof typeof areas;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=popover.css.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"popover.css.d.ts","names":[],"sources":["../../../src/components/popover/popover.css.ts"],"mappings":";;;;;cAcM;WACJ;WACA;WACA;WACA;WACA;WACA;WACA;WACA;;YAGU,yBAAyB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { CSSProperties, ComponentPropsWithRef, ReactElement, ReactNode } from "react";
|
|
2
|
+
import { Placement } from "./popover.css.js";
|
|
3
|
+
type TriggerProps = {
|
|
4
|
+
style?: CSSProperties;
|
|
5
|
+
popoverTarget?: string;
|
|
6
|
+
'aria-describedby'?: string;
|
|
7
|
+
onPointerEnter?: (event: never) => void;
|
|
8
|
+
onPointerLeave?: (event: never) => void;
|
|
9
|
+
onFocus?: (event: never) => void;
|
|
10
|
+
onBlur?: (event: never) => void;
|
|
11
|
+
onKeyDown?: (event: never) => void;
|
|
12
|
+
};
|
|
13
|
+
export interface PopoverProps extends Omit<ComponentPropsWithRef<'div'>, 'title' | 'popover'> {
|
|
14
|
+
/** The element that toggles it: usually a `Button`. It must be a `<button>`. */
|
|
15
|
+
trigger: ReactElement<TriggerProps>;
|
|
16
|
+
/** Optional heading; it also names the popover. */
|
|
17
|
+
title?: ReactNode;
|
|
18
|
+
placement?: Placement;
|
|
19
|
+
/** Called when it opens or closes, including light dismiss and Escape. */
|
|
20
|
+
onOpenChange?: (open: boolean) => void;
|
|
21
|
+
children?: ReactNode;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Non-modal content next to its trigger: filters, details, small forms.
|
|
25
|
+
* Built on the Popover API: the browser handles light dismiss, Escape and top layer,
|
|
26
|
+
* and `popovertarget` exposes the expanded state. CSS anchor positioning places it.
|
|
27
|
+
*/
|
|
28
|
+
export declare function Popover({ trigger, title, placement, onOpenChange, className, style, children, ...rest }: PopoverProps): import("react").JSX.Element;
|
|
29
|
+
export interface TooltipProps {
|
|
30
|
+
/** Short, plain text. Tooltips must never hold links, buttons or other controls. */
|
|
31
|
+
content: ReactNode;
|
|
32
|
+
/** The described element. It must be focusable, so keyboard users get the tooltip too. */
|
|
33
|
+
children: ReactElement<TriggerProps>;
|
|
34
|
+
placement?: Placement;
|
|
35
|
+
/** Hover delay before showing, in ms. Focus shows it straight away. Default 400. */
|
|
36
|
+
delay?: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A short description of a control, shown on hover (after a delay) and on focus,
|
|
40
|
+
* hidden on leave, blur and Escape. Linked with `aria-describedby`.
|
|
41
|
+
* Touch screens have no hover, so never put essential information only in a tooltip.
|
|
42
|
+
*/
|
|
43
|
+
export declare function Tooltip({ content, children, placement, delay }: TooltipProps): import("react").JSX.Element;
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=popover.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"popover.d.ts","names":["styles.Placement"],"sources":["../../../src/components/popover/popover.tsx"],"mappings":";;KAcK;EACH,QAAQ;EACR;EACA;EACA,kBAAkB;EAClB,kBAAkB;EAClB,WAAW;EACX,UAAU;EACV,aAAa;;iBAQE,qBAAqB,KAAK;;EAEzC,SAAS,aAAa;;EAEtB,QAAQ;EACR,YAAYA;;EAEZ,gBAAgB;EAChB,WAAW;;;;;;;wBAQG,UACd,SACA,OACA,WACA,cACA,WACA,OACA,aACG,QACF,+BAAY,IAAA;iBAoDE;;EAEf,SAAS;;EAET,UAAU,aAAa;EACvB,YAAYA;;EAEZ;;;;;;;wBAQc,UAAU,SAAS,UAAU,WAAW,SAAe,+BAAY,IAAA"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { cloneElement, isValidElement, useEffect, useId, useRef } from "react";
|
|
2
|
+
import { cx } from "../../utils/cx.js";
|
|
3
|
+
import { popover, tooltip } from "./popover.styles.js";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
// src/components/popover/popover.tsx
|
|
6
|
+
/** A unique, CSS-safe anchor name per instance. */
|
|
7
|
+
function useAnchorName() {
|
|
8
|
+
return `--ml-anchor-${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Non-modal content next to its trigger: filters, details, small forms.
|
|
12
|
+
* Built on the Popover API: the browser handles light dismiss, Escape and top layer,
|
|
13
|
+
* and `popovertarget` exposes the expanded state. CSS anchor positioning places it.
|
|
14
|
+
*/
|
|
15
|
+
function Popover({ trigger, title, placement, onOpenChange, className, style, children, ...rest }) {
|
|
16
|
+
const id = useId();
|
|
17
|
+
const titleId = useId();
|
|
18
|
+
const anchor = useAnchorName();
|
|
19
|
+
const ref = useRef(null);
|
|
20
|
+
const onOpenChangeRef = useRef(onOpenChange);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
onOpenChangeRef.current = onOpenChange;
|
|
23
|
+
});
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
const el = ref.current;
|
|
26
|
+
if (!el) return;
|
|
27
|
+
const onToggle = (event) => onOpenChangeRef.current?.(event.newState === "open");
|
|
28
|
+
el.addEventListener("toggle", onToggle);
|
|
29
|
+
return () => el.removeEventListener("toggle", onToggle);
|
|
30
|
+
}, []);
|
|
31
|
+
const wiredTrigger = isValidElement(trigger) ? cloneElement(trigger, {
|
|
32
|
+
popoverTarget: id,
|
|
33
|
+
style: {
|
|
34
|
+
...trigger.props.style,
|
|
35
|
+
anchorName: anchor
|
|
36
|
+
}
|
|
37
|
+
}) : trigger;
|
|
38
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [wiredTrigger, /* @__PURE__ */ jsxs("div", {
|
|
39
|
+
...rest,
|
|
40
|
+
ref,
|
|
41
|
+
id,
|
|
42
|
+
popover: "auto",
|
|
43
|
+
role: "dialog",
|
|
44
|
+
"aria-labelledby": title ? titleId : void 0,
|
|
45
|
+
className: cx(popover({ placement }), className),
|
|
46
|
+
style: {
|
|
47
|
+
...style,
|
|
48
|
+
positionAnchor: anchor
|
|
49
|
+
},
|
|
50
|
+
children: [title && /* @__PURE__ */ jsx("p", {
|
|
51
|
+
id: titleId,
|
|
52
|
+
className: "ml_12557yp9",
|
|
53
|
+
children: title
|
|
54
|
+
}), children]
|
|
55
|
+
})] });
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A short description of a control, shown on hover (after a delay) and on focus,
|
|
59
|
+
* hidden on leave, blur and Escape. Linked with `aria-describedby`.
|
|
60
|
+
* Touch screens have no hover, so never put essential information only in a tooltip.
|
|
61
|
+
*/
|
|
62
|
+
function Tooltip({ content, children, placement, delay = 400 }) {
|
|
63
|
+
const id = useId();
|
|
64
|
+
const anchor = useAnchorName();
|
|
65
|
+
const ref = useRef(null);
|
|
66
|
+
const timer = useRef(void 0);
|
|
67
|
+
const show = (after = 0) => {
|
|
68
|
+
clearTimeout(timer.current);
|
|
69
|
+
timer.current = setTimeout(() => {
|
|
70
|
+
const el = ref.current;
|
|
71
|
+
if (el && !el.matches(":popover-open")) el.showPopover();
|
|
72
|
+
}, after);
|
|
73
|
+
};
|
|
74
|
+
const hide = () => {
|
|
75
|
+
clearTimeout(timer.current);
|
|
76
|
+
const el = ref.current;
|
|
77
|
+
if (el?.matches(":popover-open")) el.hidePopover();
|
|
78
|
+
};
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
const pending = timer;
|
|
81
|
+
return () => clearTimeout(pending.current);
|
|
82
|
+
}, [timer]);
|
|
83
|
+
const props = children.props;
|
|
84
|
+
const trigger = cloneElement(children, {
|
|
85
|
+
"aria-describedby": [props["aria-describedby"], id].filter(Boolean).join(" "),
|
|
86
|
+
style: {
|
|
87
|
+
...props.style,
|
|
88
|
+
anchorName: anchor
|
|
89
|
+
},
|
|
90
|
+
onPointerEnter: (event) => {
|
|
91
|
+
props.onPointerEnter?.(event);
|
|
92
|
+
show(delay);
|
|
93
|
+
},
|
|
94
|
+
onPointerLeave: (event) => {
|
|
95
|
+
props.onPointerLeave?.(event);
|
|
96
|
+
hide();
|
|
97
|
+
},
|
|
98
|
+
onFocus: (event) => {
|
|
99
|
+
props.onFocus?.(event);
|
|
100
|
+
show(0);
|
|
101
|
+
},
|
|
102
|
+
onBlur: (event) => {
|
|
103
|
+
props.onBlur?.(event);
|
|
104
|
+
hide();
|
|
105
|
+
},
|
|
106
|
+
onKeyDown: (event) => {
|
|
107
|
+
props.onKeyDown?.(event);
|
|
108
|
+
if (event.key === "Escape") hide();
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [trigger, /* @__PURE__ */ jsx("div", {
|
|
112
|
+
ref,
|
|
113
|
+
id,
|
|
114
|
+
popover: "manual",
|
|
115
|
+
role: "tooltip",
|
|
116
|
+
className: tooltip({ placement }),
|
|
117
|
+
style: { positionAnchor: anchor },
|
|
118
|
+
children: content
|
|
119
|
+
})] });
|
|
120
|
+
}
|
|
121
|
+
export { Popover, Tooltip };
|
|
122
|
+
|
|
123
|
+
//# sourceMappingURL=popover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"popover.js","names":["styles.popover","styles.tooltip"],"sources":["../../../src/components/popover/popover.tsx"],"sourcesContent":["import {\n cloneElement,\n isValidElement,\n useEffect,\n useId,\n useRef,\n type ComponentPropsWithRef,\n type CSSProperties,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport { cx } from '../../utils/cx';\nimport * as styles from './popover.css';\n\ntype TriggerProps = {\n style?: CSSProperties;\n popoverTarget?: string;\n 'aria-describedby'?: string;\n onPointerEnter?: (event: never) => void;\n onPointerLeave?: (event: never) => void;\n onFocus?: (event: never) => void;\n onBlur?: (event: never) => void;\n onKeyDown?: (event: never) => void;\n};\n\n/** A unique, CSS-safe anchor name per instance. */\nfunction useAnchorName() {\n return `--ml-anchor-${useId().replace(/[^a-zA-Z0-9_-]/g, '')}`;\n}\n\nexport interface PopoverProps extends Omit<ComponentPropsWithRef<'div'>, 'title' | 'popover'> {\n /** The element that toggles it: usually a `Button`. It must be a `<button>`. */\n trigger: ReactElement<TriggerProps>;\n /** Optional heading; it also names the popover. */\n title?: ReactNode;\n placement?: styles.Placement;\n /** Called when it opens or closes, including light dismiss and Escape. */\n onOpenChange?: (open: boolean) => void;\n children?: ReactNode;\n}\n\n/**\n * Non-modal content next to its trigger: filters, details, small forms.\n * Built on the Popover API: the browser handles light dismiss, Escape and top layer,\n * and `popovertarget` exposes the expanded state. CSS anchor positioning places it.\n */\nexport function Popover({\n trigger,\n title,\n placement,\n onOpenChange,\n className,\n style,\n children,\n ...rest\n}: PopoverProps) {\n const id = useId();\n const titleId = useId();\n const anchor = useAnchorName();\n const ref = useRef<HTMLDivElement>(null);\n const onOpenChangeRef = useRef(onOpenChange);\n useEffect(() => {\n onOpenChangeRef.current = onOpenChange;\n });\n\n useEffect(() => {\n const el = ref.current;\n if (!el) return;\n const onToggle = (event: Event) => onOpenChangeRef.current?.((event as ToggleEvent).newState === 'open');\n el.addEventListener('toggle', onToggle);\n return () => el.removeEventListener('toggle', onToggle);\n }, []);\n\n const wiredTrigger = isValidElement(trigger)\n ? cloneElement(trigger, {\n popoverTarget: id,\n style: { ...trigger.props.style, anchorName: anchor } as CSSProperties,\n })\n : trigger;\n\n return (\n <>\n {wiredTrigger}\n <div\n {...rest}\n ref={ref}\n id={id}\n popover=\"auto\"\n // A <dialog> shown through the Popover API is unreliable across browsers, so the\n // panel stays a <div> and the role names it.\n // oxlint-disable-next-line jsx-a11y/prefer-tag-over-role\n role=\"dialog\"\n aria-labelledby={title ? titleId : undefined}\n className={cx(styles.popover({ placement }), className)}\n style={{ ...style, positionAnchor: anchor } as CSSProperties}\n >\n {title && (\n <p id={titleId} className={styles.popoverTitle}>\n {title}\n </p>\n )}\n {children}\n </div>\n </>\n );\n}\n\nexport interface TooltipProps {\n /** Short, plain text. Tooltips must never hold links, buttons or other controls. */\n content: ReactNode;\n /** The described element. It must be focusable, so keyboard users get the tooltip too. */\n children: ReactElement<TriggerProps>;\n placement?: styles.Placement;\n /** Hover delay before showing, in ms. Focus shows it straight away. Default 400. */\n delay?: number;\n}\n\n/**\n * A short description of a control, shown on hover (after a delay) and on focus,\n * hidden on leave, blur and Escape. Linked with `aria-describedby`.\n * Touch screens have no hover, so never put essential information only in a tooltip.\n */\nexport function Tooltip({ content, children, placement, delay = 400 }: TooltipProps) {\n const id = useId();\n const anchor = useAnchorName();\n const ref = useRef<HTMLDivElement>(null);\n const timer = useRef<ReturnType<typeof setTimeout>>(undefined);\n\n const show = (after = 0) => {\n clearTimeout(timer.current);\n timer.current = setTimeout(() => {\n const el = ref.current;\n if (el && !el.matches(':popover-open')) el.showPopover();\n }, after);\n };\n const hide = () => {\n clearTimeout(timer.current);\n const el = ref.current;\n if (el?.matches(':popover-open')) el.hidePopover();\n };\n useEffect(() => {\n const pending = timer;\n return () => clearTimeout(pending.current);\n }, [timer]);\n\n const props = children.props;\n // The handlers below read refs only when the events fire; the rule cannot see that\n // through cloneElement.\n // oxlint-disable-next-line react/refs\n const trigger = cloneElement(children, {\n 'aria-describedby': [props['aria-describedby'], id].filter(Boolean).join(' '),\n style: { ...props.style, anchorName: anchor } as CSSProperties,\n onPointerEnter: (event: never) => {\n props.onPointerEnter?.(event);\n show(delay);\n },\n onPointerLeave: (event: never) => {\n props.onPointerLeave?.(event);\n hide();\n },\n onFocus: (event: never) => {\n props.onFocus?.(event);\n show(0);\n },\n onBlur: (event: never) => {\n props.onBlur?.(event);\n hide();\n },\n onKeyDown: (event: never) => {\n props.onKeyDown?.(event);\n if ((event as KeyboardEvent).key === 'Escape') hide();\n },\n });\n\n return (\n <>\n {trigger}\n <div\n ref={ref}\n id={id}\n popover=\"manual\"\n role=\"tooltip\"\n className={styles.tooltip({ placement })}\n style={{ positionAnchor: anchor } as CSSProperties}\n >\n {content}\n </div>\n </>\n );\n}\n"],"mappings":";;;;;;AA0BA,SAAS,gBAAgB;CACvB,OAAO,eAAe,MAAM,CAAC,CAAC,QAAQ,mBAAmB,EAAE;AAC7D;;;;;;AAkBA,SAAgB,QAAQ,EACtB,SACA,OACA,WACA,cACA,WACA,OACA,UACA,GAAG,QACY;CACf,MAAM,KAAK,MAAM;CACjB,MAAM,UAAU,MAAM;CACtB,MAAM,SAAS,cAAc;CAC7B,MAAM,MAAM,OAAuB,IAAI;CACvC,MAAM,kBAAkB,OAAO,YAAY;CAC3C,gBAAgB;EACd,gBAAgB,UAAU;CAC5B,CAAC;CAED,gBAAgB;EACd,MAAM,KAAK,IAAI;EACf,IAAI,CAAC,IAAI;EACT,MAAM,YAAY,UAAiB,gBAAgB,UAAW,MAAsB,aAAa,MAAM;EACvG,GAAG,iBAAiB,UAAU,QAAQ;EACtC,aAAa,GAAG,oBAAoB,UAAU,Q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,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;EAC5E,OAAO;GAAE,GAAG,MAAM;GAAO,YAAY;EAAO;EAC5C,iBAAiB,UAAiB;GAChC,MAAM,iBAAiB,KAAK;GAC5B,KAAK,KAAK;EACZ;EACA,iBAAiB,UAAiB;GAChC,MAAM,iBAAiB,KAAK;GAC5B,KAAK;EACP;EACA,UAAU,UAAiB;GACzB,MAAM,UAAU,KAAK;GACrB,KAAK,CAAC;EACR;EACA,SAAS,UAAiB;GACxB,MAAM,SAAS,KAAK;GACpB,KAAK;EACP;EACA,YAAY,UAAiB;GAC3B,MAAM,YAAY,KAAK;GACvB,IAAK,MAAwB,QAAQ,UAAU,KAAK;EACtD;CACF,CAAC;CAED,OACE,qBAAA,UAAA,EAAA,UAAA,CACG,SACD,oBAAC,OAAD;EACO;EACD;EACJ,SAAQ;EACR,MAAK;EACL,WAAWC,QAAe,EAAE,UAAU,CAAC;EACvC,OAAO,EAAE,gBAAgB,OAAO;EAE/B,UAAA;CACE,CAAA,CACL,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createRuntimeFn } from "@vanilla-extract/recipes/createRuntimeFn";
|
|
2
|
+
// src/components/popover/popover.css.ts
|
|
3
|
+
var popover = createRuntimeFn({
|
|
4
|
+
defaultClassName: "ml_12557yp0",
|
|
5
|
+
variantClassNames: { placement: {
|
|
6
|
+
top: "ml_placement_top_12557yp1",
|
|
7
|
+
"top-start": "ml_placement_top-start_12557yp2",
|
|
8
|
+
"top-end": "ml_placement_top-end_12557yp3",
|
|
9
|
+
bottom: "ml_placement_bottom_12557yp4",
|
|
10
|
+
"bottom-start": "ml_placement_bottom-start_12557yp5",
|
|
11
|
+
"bottom-end": "ml_placement_bottom-end_12557yp6",
|
|
12
|
+
start: "ml_placement_start_12557yp7",
|
|
13
|
+
end: "ml_placement_end_12557yp8"
|
|
14
|
+
} },
|
|
15
|
+
defaultVariants: { placement: "bottom-start" },
|
|
16
|
+
compoundVariants: []
|
|
17
|
+
});
|
|
18
|
+
var popoverTitle = "ml_12557yp9";
|
|
19
|
+
var tooltip = createRuntimeFn({
|
|
20
|
+
defaultClassName: "ml_12557ypa",
|
|
21
|
+
variantClassNames: { placement: {
|
|
22
|
+
top: "ml_placement_top_12557ypb",
|
|
23
|
+
"top-start": "ml_placement_top-start_12557ypc",
|
|
24
|
+
"top-end": "ml_placement_top-end_12557ypd",
|
|
25
|
+
bottom: "ml_placement_bottom_12557ype",
|
|
26
|
+
"bottom-start": "ml_placement_bottom-start_12557ypf",
|
|
27
|
+
"bottom-end": "ml_placement_bottom-end_12557ypg",
|
|
28
|
+
start: "ml_placement_start_12557yph",
|
|
29
|
+
end: "ml_placement_end_12557ypi"
|
|
30
|
+
} },
|
|
31
|
+
defaultVariants: { placement: "top" },
|
|
32
|
+
compoundVariants: []
|
|
33
|
+
});
|
|
34
|
+
export { popover, popoverTitle, tooltip };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=popover.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"popover.styles.js","names":[],"sources":[],"mappings":""}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
export type ToastTone = 'neutral' | 'accent' | 'success' | 'warning' | 'danger';
|
|
3
|
+
export interface ToastOptions {
|
|
4
|
+
title: ReactNode;
|
|
5
|
+
description?: ReactNode;
|
|
6
|
+
tone?: ToastTone;
|
|
7
|
+
/** One follow-up action, e.g. Undo. Toasts must never be the only way to do something. */
|
|
8
|
+
action?: {
|
|
9
|
+
label: string;
|
|
10
|
+
onClick: () => void;
|
|
11
|
+
};
|
|
12
|
+
/** Milliseconds before it dismisses itself. Default 5000 (8000 for danger). `Infinity` keeps it. */
|
|
13
|
+
duration?: number;
|
|
14
|
+
/** Reuse an id to replace a toast instead of stacking a new one. */
|
|
15
|
+
id?: string;
|
|
16
|
+
}
|
|
17
|
+
interface ToastApi {
|
|
18
|
+
toast: (options: ToastOptions) => string;
|
|
19
|
+
dismiss: (id: string) => void;
|
|
20
|
+
}
|
|
21
|
+
/** Show and dismiss toasts. Needs a `<ToastProvider>` above. */
|
|
22
|
+
export declare function useToast(): ToastApi;
|
|
23
|
+
export interface ToastProviderProps {
|
|
24
|
+
children: ReactNode;
|
|
25
|
+
/** Most toasts on screen at once; older ones are dismissed. Default 3. */
|
|
26
|
+
max?: number;
|
|
27
|
+
/** Accessible name of the notifications region, for localisation. */
|
|
28
|
+
label?: string;
|
|
29
|
+
dismissLabel?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Renders the notification region in place (so it inherits the surrounding theme) and
|
|
33
|
+
* provides `useToast()`. Put it once near the root, inside your `ThemeScope`.
|
|
34
|
+
*/
|
|
35
|
+
export declare function ToastProvider({ children, max, label, dismissLabel }: ToastProviderProps): import("react").JSX.Element;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=toast.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toast.d.ts","names":[],"sources":["../../../src/components/toast/toast.tsx"],"mappings":";YAcY;iBAEK;EACf,OAAO;EACP,cAAc;EACd,OAAO;;EAEP;IAAW;IAAe;;;EAE1B;;EAEA;;UAQQ;EACR,QAAQ,SAAS;EACjB,UAAU;;;wBAMI,YAAY;iBAMX;EACf,UAAU;;EAEV;;EAEA;EACA;;;;;;wBAUc,gBACd,UACA,KACA,OACA,gBACC,qCAAkB,IAAA"}
|