@mohirlab/react 0.1.1 → 0.3.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/badge/badge.css.d.ts +1 -5
- package/dist/components/badge/badge.css.d.ts.map +1 -1
- package/dist/components/button/button.css.d.ts +3 -4
- package/dist/components/button/button.css.d.ts.map +1 -1
- 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/input/input.css.d.ts +2 -3
- package/dist/components/input/input.css.d.ts.map +1 -1
- 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/text/text.css.d.ts +1 -2
- package/dist/components/text/text.css.d.ts.map +1 -1
- 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 +537 -42
- package/package.json +6 -5
|
@@ -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"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { iconClose } from "@mohirlab/icons";
|
|
3
|
+
import { Icon } from "../icon/icon.js";
|
|
4
|
+
import { content, dismiss, region, sealMark, title, toast } from "./toast.styles.js";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
// src/components/toast/toast.tsx
|
|
7
|
+
const ToastContext = createContext(null);
|
|
8
|
+
/** Show and dismiss toasts. Needs a `<ToastProvider>` above. */
|
|
9
|
+
function useToast() {
|
|
10
|
+
const api = useContext(ToastContext);
|
|
11
|
+
if (!api) throw new Error("useToast() must be used inside <ToastProvider>.");
|
|
12
|
+
return api;
|
|
13
|
+
}
|
|
14
|
+
let counter = 0;
|
|
15
|
+
const EXIT_MS = 400;
|
|
16
|
+
/**
|
|
17
|
+
* Renders the notification region in place (so it inherits the surrounding theme) and
|
|
18
|
+
* provides `useToast()`. Put it once near the root, inside your `ThemeScope`.
|
|
19
|
+
*/
|
|
20
|
+
function ToastProvider({ children, max = 3, label = "Notifications", dismissLabel = "Dismiss" }) {
|
|
21
|
+
const [items, setItems] = useState([]);
|
|
22
|
+
const [paused, setPaused] = useState(false);
|
|
23
|
+
const sweep = useCallback(() => {
|
|
24
|
+
setTimeout(() => setItems((list) => list.filter((t) => !t.closing)), EXIT_MS);
|
|
25
|
+
}, []);
|
|
26
|
+
const dismiss = useCallback((id) => {
|
|
27
|
+
setItems((list) => list.map((t) => t.id === id ? {
|
|
28
|
+
...t,
|
|
29
|
+
closing: true
|
|
30
|
+
} : t));
|
|
31
|
+
sweep();
|
|
32
|
+
}, [sweep]);
|
|
33
|
+
const toast = useCallback((options) => {
|
|
34
|
+
const id = options.id ?? `ml-toast-${++counter}`;
|
|
35
|
+
setItems((list) => {
|
|
36
|
+
const next = [...list.filter((t) => t.id !== id), {
|
|
37
|
+
...options,
|
|
38
|
+
id,
|
|
39
|
+
closing: false
|
|
40
|
+
}];
|
|
41
|
+
const overflow = new Set(next.filter((t) => !t.closing).slice(0, -max).map((t) => t.id));
|
|
42
|
+
return overflow.size ? next.map((t) => overflow.has(t.id) ? {
|
|
43
|
+
...t,
|
|
44
|
+
closing: true
|
|
45
|
+
} : t) : next;
|
|
46
|
+
});
|
|
47
|
+
sweep();
|
|
48
|
+
return id;
|
|
49
|
+
}, [max, sweep]);
|
|
50
|
+
const api = useMemo(() => ({
|
|
51
|
+
toast,
|
|
52
|
+
dismiss
|
|
53
|
+
}), [toast, dismiss]);
|
|
54
|
+
return /* @__PURE__ */ jsxs(ToastContext.Provider, {
|
|
55
|
+
value: api,
|
|
56
|
+
children: [children, /* @__PURE__ */ jsx("section", {
|
|
57
|
+
"aria-label": label,
|
|
58
|
+
children: /* @__PURE__ */ jsx("ol", {
|
|
59
|
+
className: region,
|
|
60
|
+
"aria-live": "polite",
|
|
61
|
+
"aria-relevant": "additions",
|
|
62
|
+
onPointerEnter: () => setPaused(true),
|
|
63
|
+
onPointerLeave: () => setPaused(false),
|
|
64
|
+
onFocus: () => setPaused(true),
|
|
65
|
+
onBlur: (event) => {
|
|
66
|
+
if (!event.currentTarget.contains(event.relatedTarget)) setPaused(false);
|
|
67
|
+
},
|
|
68
|
+
children: items.map((item) => /* @__PURE__ */ jsx(ToastSlip, {
|
|
69
|
+
item,
|
|
70
|
+
paused,
|
|
71
|
+
dismissLabel,
|
|
72
|
+
onDismiss: () => dismiss(item.id)
|
|
73
|
+
}, item.id))
|
|
74
|
+
})
|
|
75
|
+
})]
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function ToastSlip({ item, paused, dismissLabel, onDismiss }) {
|
|
79
|
+
const tone = item.tone ?? "neutral";
|
|
80
|
+
const duration = item.duration ?? (tone === "danger" ? 8e3 : 5e3);
|
|
81
|
+
const remaining = useRef(duration);
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (item.closing || paused || !Number.isFinite(remaining.current)) return;
|
|
84
|
+
const started = Date.now();
|
|
85
|
+
const timer = setTimeout(onDismiss, remaining.current);
|
|
86
|
+
return () => {
|
|
87
|
+
clearTimeout(timer);
|
|
88
|
+
remaining.current -= Date.now() - started;
|
|
89
|
+
};
|
|
90
|
+
}, [
|
|
91
|
+
item.closing,
|
|
92
|
+
paused,
|
|
93
|
+
onDismiss
|
|
94
|
+
]);
|
|
95
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
96
|
+
className: toast({ tone }),
|
|
97
|
+
"data-state": item.closing ? "closed" : "open",
|
|
98
|
+
role: tone === "danger" ? "alert" : void 0,
|
|
99
|
+
"aria-atomic": "true",
|
|
100
|
+
children: [
|
|
101
|
+
/* @__PURE__ */ jsx("span", {
|
|
102
|
+
className: sealMark,
|
|
103
|
+
"aria-hidden": "true"
|
|
104
|
+
}),
|
|
105
|
+
/* @__PURE__ */ jsxs("div", {
|
|
106
|
+
className: content,
|
|
107
|
+
children: [
|
|
108
|
+
/* @__PURE__ */ jsx("span", {
|
|
109
|
+
className: title,
|
|
110
|
+
children: item.title
|
|
111
|
+
}),
|
|
112
|
+
item.description && /* @__PURE__ */ jsx("span", {
|
|
113
|
+
className: "ml_jxsxlqb",
|
|
114
|
+
children: item.description
|
|
115
|
+
}),
|
|
116
|
+
item.action && /* @__PURE__ */ jsx("button", {
|
|
117
|
+
type: "button",
|
|
118
|
+
className: "ml_jxsxlqc",
|
|
119
|
+
onClick: () => {
|
|
120
|
+
item.action.onClick();
|
|
121
|
+
onDismiss();
|
|
122
|
+
},
|
|
123
|
+
children: item.action.label
|
|
124
|
+
})
|
|
125
|
+
]
|
|
126
|
+
}),
|
|
127
|
+
/* @__PURE__ */ jsx("button", {
|
|
128
|
+
type: "button",
|
|
129
|
+
className: dismiss,
|
|
130
|
+
"aria-label": dismissLabel,
|
|
131
|
+
onClick: onDismiss,
|
|
132
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
133
|
+
icon: iconClose,
|
|
134
|
+
size: 16
|
|
135
|
+
})
|
|
136
|
+
})
|
|
137
|
+
]
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
export { ToastProvider, useToast };
|
|
141
|
+
|
|
142
|
+
//# sourceMappingURL=toast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toast.js","names":["styles.region","styles.toast","styles.sealMark","styles.content","styles.title","styles.dismiss"],"sources":["../../../src/components/toast/toast.tsx"],"sourcesContent":["import {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n type ReactNode,\n} from 'react';\nimport { iconClose } from '@mohirlab/icons';\nimport { Icon } from '../icon';\nimport * as styles from './toast.css';\n\nexport type ToastTone = 'neutral' | 'accent' | 'success' | 'warning' | 'danger';\n\nexport interface ToastOptions {\n title: ReactNode;\n description?: ReactNode;\n tone?: ToastTone;\n /** One follow-up action, e.g. Undo. Toasts must never be the only way to do something. */\n action?: { label: string; onClick: () => void };\n /** Milliseconds before it dismisses itself. Default 5000 (8000 for danger). `Infinity` keeps it. */\n duration?: number;\n /** Reuse an id to replace a toast instead of stacking a new one. */\n id?: string;\n}\n\ninterface ToastItem extends ToastOptions {\n id: string;\n closing: boolean;\n}\n\ninterface ToastApi {\n toast: (options: ToastOptions) => string;\n dismiss: (id: string) => void;\n}\n\nconst ToastContext = createContext<ToastApi | null>(null);\n\n/** Show and dismiss toasts. Needs a `<ToastProvider>` above. */\nexport function useToast(): ToastApi {\n const api = useContext(ToastContext);\n if (!api) throw new Error('useToast() must be used inside <ToastProvider>.');\n return api;\n}\n\nexport interface ToastProviderProps {\n children: ReactNode;\n /** Most toasts on screen at once; older ones are dismissed. Default 3. */\n max?: number;\n /** Accessible name of the notifications region, for localisation. */\n label?: string;\n dismissLabel?: string;\n}\n\nlet counter = 0;\nconst EXIT_MS = 400;\n\n/**\n * Renders the notification region in place (so it inherits the surrounding theme) and\n * provides `useToast()`. Put it once near the root, inside your `ThemeScope`.\n */\nexport function ToastProvider({\n children,\n max = 3,\n label = 'Notifications',\n dismissLabel = 'Dismiss',\n}: ToastProviderProps) {\n const [items, setItems] = useState<ToastItem[]>([]);\n const [paused, setPaused] = useState(false);\n\n // Closing toasts stay for their exit animation, then this sweep removes them.\n const sweep = useCallback(() => {\n setTimeout(() => setItems((list) => list.filter((t) => !t.closing)), EXIT_MS);\n }, []);\n\n const dismiss = useCallback(\n (id: string) => {\n setItems((list) => list.map((t) => (t.id === id ? { ...t, closing: true } : t)));\n sweep();\n },\n [sweep],\n );\n\n const toast = useCallback(\n (options: ToastOptions) => {\n const id = options.id ?? `ml-toast-${++counter}`;\n setItems((list) => {\n const next = [...list.filter((t) => t.id !== id), { ...options, id, closing: false }];\n // Over the limit: the oldest open toasts start leaving.\n const overflow = new Set(\n next\n .filter((t) => !t.closing)\n .slice(0, -max)\n .map((t) => t.id),\n );\n return overflow.size ? next.map((t) => (overflow.has(t.id) ? { ...t, closing: true } : t)) : next;\n });\n sweep();\n return id;\n },\n [max, sweep],\n );\n\n const api = useMemo(() => ({ toast, dismiss }), [toast, dismiss]);\n\n return (\n <ToastContext.Provider value={api}>\n {children}\n <section aria-label={label}>\n {/* oxlint-disable-next-line jsx-a11y/no-noninteractive-element-interactions -- hover and focus only pause the timers; nothing is activated */}\n <ol\n className={styles.region}\n aria-live=\"polite\"\n aria-relevant=\"additions\"\n onPointerEnter={() => setPaused(true)}\n onPointerLeave={() => setPaused(false)}\n onFocus={() => setPaused(true)}\n onBlur={(event) => {\n if (!event.currentTarget.contains(event.relatedTarget as Node | null)) setPaused(false);\n }}\n >\n {items.map((item) => (\n <ToastSlip\n key={item.id}\n item={item}\n paused={paused}\n dismissLabel={dismissLabel}\n onDismiss={() => dismiss(item.id)}\n />\n ))}\n </ol>\n </section>\n </ToastContext.Provider>\n );\n}\n\nfunction ToastSlip({\n item,\n paused,\n dismissLabel,\n onDismiss,\n}: {\n item: ToastItem;\n paused: boolean;\n dismissLabel: string;\n onDismiss: () => void;\n}) {\n const tone = item.tone ?? 'neutral';\n const duration = item.duration ?? (tone === 'danger' ? 8000 : 5000);\n const remaining = useRef(duration);\n\n // Count down only while nothing is hovered or focused; resume where it stopped.\n useEffect(() => {\n if (item.closing || paused || !Number.isFinite(remaining.current)) return;\n const started = Date.now();\n const timer = setTimeout(onDismiss, remaining.current);\n return () => {\n clearTimeout(timer);\n remaining.current -= Date.now() - started;\n };\n }, [item.closing, paused, onDismiss]);\n\n return (\n <li\n className={styles.toast({ tone })}\n data-state={item.closing ? 'closed' : 'open'}\n // Danger interrupts; everything else waits its turn in the polite region.\n role={tone === 'danger' ? 'alert' : undefined}\n aria-atomic=\"true\"\n >\n <span className={styles.sealMark} aria-hidden=\"true\" />\n <div className={styles.content}>\n <span className={styles.title}>{item.title}</span>\n {item.description && <span className={styles.description}>{item.description}</span>}\n {item.action && (\n <button\n type=\"button\"\n className={styles.action}\n onClick={() => {\n item.action!.onClick();\n onDismiss();\n }}\n >\n {item.action.label}\n </button>\n )}\n </div>\n <button type=\"button\" className={styles.dismiss} aria-label={dismissLabel} onClick={onDismiss}>\n <Icon icon={iconClose} size={16} />\n </button>\n </li>\n );\n}\n"],"mappings":";;;;;;AAsCA,MAAM,eAAe,cAA+B,IAAI;;AAGxD,SAAgB,WAAqB;CACnC,MAAM,MAAM,WAA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AAqB,UAAA,KAAK;KAAkB,CAAA;KACjF,KAAK,UACJ,oBAAC,UAAD;MACE,MAAK;MACL,WAAW;MACX,eAAe;OACb,KAAK,OAAQ,QAAQ;OACrB,UAAU;MACZ;MAEC,UAAA,KAAK,OAAO;KACP,CAAA;IAEP;;GACL,oBAAC,UAAD;IAAQ,MAAK;IAAS,WAAWC;IAAgB,cAAY;IAAc,SAAS;IAClF,UAAA,oBAAC,MAAD;KAAM,MAAM;KAAW,MAAM;IAAK,CAAA;GAC5B,CAAA;EACN;;AAER"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createRuntimeFn } from "@vanilla-extract/recipes/createRuntimeFn";
|
|
2
|
+
// src/components/toast/toast.css.ts
|
|
3
|
+
var action = "ml_jxsxlqc";
|
|
4
|
+
var content = "ml_jxsxlq9";
|
|
5
|
+
var description = "ml_jxsxlqb";
|
|
6
|
+
var dismiss = "ml_jxsxlqd";
|
|
7
|
+
var region = "ml_jxsxlq0";
|
|
8
|
+
var sealMark = "ml_jxsxlq8";
|
|
9
|
+
var title = "ml_jxsxlqa";
|
|
10
|
+
var toast = createRuntimeFn({
|
|
11
|
+
defaultClassName: "ml_jxsxlq2",
|
|
12
|
+
variantClassNames: { tone: {
|
|
13
|
+
neutral: "ml_tone_neutral_jxsxlq3",
|
|
14
|
+
accent: "ml_tone_accent_jxsxlq4",
|
|
15
|
+
success: "ml_tone_success_jxsxlq5",
|
|
16
|
+
warning: "ml_tone_warning_jxsxlq6",
|
|
17
|
+
danger: "ml_tone_danger_jxsxlq7"
|
|
18
|
+
} },
|
|
19
|
+
defaultVariants: { tone: "neutral" },
|
|
20
|
+
compoundVariants: []
|
|
21
|
+
});
|
|
22
|
+
export { action, content, description, dismiss, region, sealMark, title, toast };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=toast.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toast.styles.js","names":[],"sources":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Open/closed state for dialogs, sheets and other disclosures. */
|
|
2
|
+
export declare function useDisclosure(initial?: boolean): {
|
|
3
|
+
open: boolean;
|
|
4
|
+
setOpen: import("react").Dispatch<import("react").SetStateAction<boolean>>;
|
|
5
|
+
onOpen: () => void;
|
|
6
|
+
onClose: () => void;
|
|
7
|
+
onToggle: () => void;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=use-disclosure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-disclosure.d.ts","names":[],"sources":["../../src/hooks/use-disclosure.ts"],"mappings":";wBAGgB,cAAc"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useCallback, useState } from "react";
|
|
2
|
+
// src/hooks/use-disclosure.ts
|
|
3
|
+
/** Open/closed state for dialogs, sheets and other disclosures. */
|
|
4
|
+
function useDisclosure(initial = false) {
|
|
5
|
+
const [open, setOpen] = useState(initial);
|
|
6
|
+
return {
|
|
7
|
+
open,
|
|
8
|
+
setOpen,
|
|
9
|
+
onOpen: useCallback(() => setOpen(true), []),
|
|
10
|
+
onClose: useCallback(() => setOpen(false), []),
|
|
11
|
+
onToggle: useCallback(() => setOpen((v) => !v), [])
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export { useDisclosure };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=use-disclosure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-disclosure.js","names":[],"sources":["../../src/hooks/use-disclosure.ts"],"sourcesContent":["import { useCallback, useState } from 'react';\n\n/** Open/closed state for dialogs, sheets and other disclosures. */\nexport function useDisclosure(initial = false) {\n const [open, setOpen] = useState(initial);\n const onOpen = useCallback(() => setOpen(true), []);\n const onClose = useCallback(() => setOpen(false), []);\n const onToggle = useCallback(() => setOpen((v) => !v), []);\n return { open, setOpen, onOpen, onClose, onToggle };\n}\n"],"mappings":";;;AAGA,SAAgB,cAAc,UAAU,OAAO;CAC7C,MAAM,CAAC,MAAM,WAAW,SAAS,OAAO;CAIxC,OAAO;EAAE;EAAM;EAAS,QAHT,kBAAkB,QAAQ,IAAI,GAAG,CAAC,CAGpB;EAAG,SAFhB,kBAAkB,QAAQ,KAAK,GAAG,CAAC,CAEb;EAAG,UADxB,kBAAkB,SAAS,MAAM,CAAC,CAAC,GAAG,CAAC,CACR;CAAE;AACpD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RefObject } from "react";
|
|
2
|
+
export type PresenceState = 'open' | 'closed';
|
|
3
|
+
/**
|
|
4
|
+
* Keeps an element mounted until its exit animation has finished.
|
|
5
|
+
*
|
|
6
|
+
* Set `data-state={state}` on the element and give it a `motion()` style: when `open`
|
|
7
|
+
* turns false, `state` becomes `closed`, the exit animation runs, and only then does
|
|
8
|
+
* `mounted` turn false. If no animation runs (no CSS, reduced motion, tests), a timeout
|
|
9
|
+
* finishes the exit anyway.
|
|
10
|
+
*/
|
|
11
|
+
export declare function usePresence(open: boolean, ref: RefObject<HTMLElement | null>, { onExitComplete, maxExitMs }?: {
|
|
12
|
+
onExitComplete?: () => void;
|
|
13
|
+
maxExitMs?: number;
|
|
14
|
+
}): {
|
|
15
|
+
mounted: boolean;
|
|
16
|
+
state: PresenceState;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=use-presence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-presence.d.ts","names":[],"sources":["../../src/hooks/use-presence.ts"],"mappings":";YAEY;;;;;;;;;wBAUI,YACd,eACA,KAAK,UAAU,uBACb,gBAAgB;EAAqB;EAA6B"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
2
|
+
// src/hooks/use-presence.ts
|
|
3
|
+
/**
|
|
4
|
+
* Keeps an element mounted until its exit animation has finished.
|
|
5
|
+
*
|
|
6
|
+
* Set `data-state={state}` on the element and give it a `motion()` style: when `open`
|
|
7
|
+
* turns false, `state` becomes `closed`, the exit animation runs, and only then does
|
|
8
|
+
* `mounted` turn false. If no animation runs (no CSS, reduced motion, tests), a timeout
|
|
9
|
+
* finishes the exit anyway.
|
|
10
|
+
*/
|
|
11
|
+
function usePresence(open, ref, { onExitComplete, maxExitMs = 600 } = {}) {
|
|
12
|
+
const [mounted, setMounted] = useState(open);
|
|
13
|
+
const [prevOpen, setPrevOpen] = useState(open);
|
|
14
|
+
if (open !== prevOpen) {
|
|
15
|
+
setPrevOpen(open);
|
|
16
|
+
if (open) setMounted(true);
|
|
17
|
+
}
|
|
18
|
+
const state = open ? "open" : "closed";
|
|
19
|
+
const exitRef = useRef(onExitComplete);
|
|
20
|
+
useLayoutEffect(() => {
|
|
21
|
+
exitRef.current = onExitComplete;
|
|
22
|
+
});
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (open || !mounted) return;
|
|
25
|
+
const el = ref.current;
|
|
26
|
+
let done = false;
|
|
27
|
+
const finish = () => {
|
|
28
|
+
if (done) return;
|
|
29
|
+
done = true;
|
|
30
|
+
exitRef.current?.();
|
|
31
|
+
setMounted(false);
|
|
32
|
+
};
|
|
33
|
+
const onEnd = (event) => {
|
|
34
|
+
if (event.target === el && !event.pseudoElement) finish();
|
|
35
|
+
};
|
|
36
|
+
el?.addEventListener("animationend", onEnd);
|
|
37
|
+
const timer = setTimeout(finish, maxExitMs);
|
|
38
|
+
return () => {
|
|
39
|
+
el?.removeEventListener("animationend", onEnd);
|
|
40
|
+
clearTimeout(timer);
|
|
41
|
+
};
|
|
42
|
+
}, [
|
|
43
|
+
open,
|
|
44
|
+
mounted,
|
|
45
|
+
ref,
|
|
46
|
+
maxExitMs
|
|
47
|
+
]);
|
|
48
|
+
return {
|
|
49
|
+
mounted,
|
|
50
|
+
state
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export { usePresence };
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=use-presence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-presence.js","names":[],"sources":["../../src/hooks/use-presence.ts"],"sourcesContent":["import { useEffect, useLayoutEffect, useRef, useState, type RefObject } from 'react';\n\nexport type PresenceState = 'open' | 'closed';\n\n/**\n * Keeps an element mounted until its exit animation has finished.\n *\n * Set `data-state={state}` on the element and give it a `motion()` style: when `open`\n * turns false, `state` becomes `closed`, the exit animation runs, and only then does\n * `mounted` turn false. If no animation runs (no CSS, reduced motion, tests), a timeout\n * finishes the exit anyway.\n */\nexport function usePresence(\n open: boolean,\n ref: RefObject<HTMLElement | null>,\n { onExitComplete, maxExitMs = 600 }: { onExitComplete?: () => void; maxExitMs?: number } = {},\n) {\n const [mounted, setMounted] = useState(open);\n // Mount during render when `open` turns on, so the element exists in the same commit.\n const [prevOpen, setPrevOpen] = useState(open);\n if (open !== prevOpen) {\n setPrevOpen(open);\n if (open) setMounted(true);\n }\n const state: PresenceState = open ? 'open' : 'closed';\n\n const exitRef = useRef(onExitComplete);\n useLayoutEffect(() => {\n exitRef.current = onExitComplete;\n });\n\n useEffect(() => {\n if (open || !mounted) return;\n const el = ref.current;\n let done = false;\n const finish = () => {\n if (done) return;\n done = true;\n exitRef.current?.();\n setMounted(false);\n };\n // Ignore animations of children and of pseudo-elements such as ::backdrop.\n const onEnd = (event: AnimationEvent) => {\n if (event.target === el && !event.pseudoElement) finish();\n };\n el?.addEventListener('animationend', onEnd);\n const timer = setTimeout(finish, maxExitMs);\n return () => {\n el?.removeEventListener('animationend', onEnd);\n clearTimeout(timer);\n };\n }, [open, mounted, ref, maxExitMs]);\n\n return { mounted, state };\n}\n"],"mappings":";;;;;;;;;;AAYA,SAAgB,YACd,MACA,KACA,EAAE,gBAAgB,YAAY,QAA6D,CAAC,GAC5F;CACA,MAAM,CAAC,SAAS,cAAc,SAAS,IAAI;CAE3C,MAAM,CAAC,UAAU,eAAe,SAAS,IAAI;CAC7C,IAAI,SAAS,UAAU;EACrB,YAAY,IAAI;EAChB,IAAI,MAAM,WAAW,IAAI;CAC3B;CACA,MAAM,QAAuB,OAAO,SAAS;CAE7C,MAAM,UAAU,OAAO,cAAc;CACrC,sBAAsB;EACpB,QAAQ,UAAU;CACpB,CAAC;CAED,gBAAgB;EACd,IAAI,QAAQ,CAAC,SAAS;EACtB,MAAM,KAAK,IAAI;EACf,IAAI,OAAO;EACX,MAAM,eAAe;GACnB,IAAI,MAAM;GACV,OAAO;GACP,QAAQ,UAAU;GAClB,WAAW,KAAK;EAClB;EAEA,MAAM,SAAS,UAA0B;GACvC,IAAI,MAAM,WAAW,MAAM,CAAC,MAAM,eAAe,OAAO;EAC1D;EACA,IAAI,iBAAiB,gBAAgB,KAAK;EAC1C,MAAM,QAAQ,WAAW,QAAQ,SAAS;EAC1C,aAAa;GACX,IAAI,oBAAoB,gBAAgB,KAAK;GAC7C,aAAa,KAAK;EACpB;CACF,GAAG;EAAC;EAAM;EAAS;EAAK;CAAS,CAAC;CAElC,OAAO;EAAE;EAAS;CAAM;AAC1B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ import "./components/button/index.js";
|
|
|
10
10
|
import { Card, CardHeader, CardProps } from "./components/card/card.js";
|
|
11
11
|
import { CardMedia, CardMediaProps } from "./components/card/card-media.js";
|
|
12
12
|
import "./components/card/index.js";
|
|
13
|
+
import { Dialog, DialogActions, DialogBody, DialogProps } from "./components/dialog/dialog.js";
|
|
14
|
+
import "./components/dialog/index.js";
|
|
13
15
|
import { Field, FieldProps } from "./components/field/field.js";
|
|
14
16
|
import { FieldContextValue, useField } from "./components/field/field-context.js";
|
|
15
17
|
import "./components/field/index.js";
|
|
@@ -17,8 +19,16 @@ import { Icon, IconProps } from "./components/icon/icon.js";
|
|
|
17
19
|
import "./components/icon/index.js";
|
|
18
20
|
import { Input, InputProps } from "./components/input/input.js";
|
|
19
21
|
import "./components/input/index.js";
|
|
22
|
+
import { Placement } from "./components/popover/popover.css.js";
|
|
23
|
+
import { Popover, PopoverProps, Tooltip, TooltipProps } from "./components/popover/popover.js";
|
|
24
|
+
import "./components/popover/index.js";
|
|
20
25
|
import { Heading, HeadingProps, MarginProps, Text, TextProps } from "./components/text/text.js";
|
|
21
26
|
import "./components/text/index.js";
|
|
27
|
+
import { ToastOptions, ToastProvider, ToastProviderProps, ToastTone, useToast } from "./components/toast/toast.js";
|
|
28
|
+
import "./components/toast/index.js";
|
|
22
29
|
import { ThemeScope, ThemeScopeProps } from "./components/theme-scope/theme-scope.js";
|
|
30
|
+
import { PresenceState, usePresence } from "./hooks/use-presence.js";
|
|
31
|
+
import { useDisclosure } from "./hooks/use-disclosure.js";
|
|
32
|
+
import "./hooks/index.js";
|
|
23
33
|
import { cx } from "./utils/cx.js";
|
|
24
|
-
export { Avatar, AvatarGroup, type AvatarGroupProps, type AvatarProps, Badge, type BadgeProps, Box, type BoxProps, Button, type ButtonProps, Card, CardHeader, CardMedia, type CardMediaProps, type CardProps, Field, type FieldContextValue, type FieldProps, Heading, type HeadingProps, Icon, type IconProps, Input, type InputProps, type MarginProps, Stack, type StackProps, Text, type TextProps, ThemeScope, type ThemeScopeProps, cx, splitSprinkles, useField };
|
|
34
|
+
export { Avatar, AvatarGroup, type AvatarGroupProps, type AvatarProps, Badge, type BadgeProps, Box, type BoxProps, Button, type ButtonProps, Card, CardHeader, CardMedia, type CardMediaProps, type CardProps, Dialog, DialogActions, DialogBody, type DialogProps, Field, type FieldContextValue, type FieldProps, Heading, type HeadingProps, Icon, type IconProps, Input, type InputProps, type MarginProps, type Placement, Popover, type PopoverProps, type PresenceState, Stack, type StackProps, Text, type TextProps, ThemeScope, type ThemeScopeProps, type ToastOptions, ToastProvider, type ToastProviderProps, type ToastTone, Tooltip, type TooltipProps, cx, splitSprinkles, useDisclosure, useField, usePresence, useToast };
|
package/dist/index.js
CHANGED
|
@@ -6,10 +6,15 @@ import { Stack } from "./components/box/stack.js";
|
|
|
6
6
|
import { Button } from "./components/button/button.js";
|
|
7
7
|
import { Card, CardHeader } from "./components/card/card.js";
|
|
8
8
|
import { CardMedia } from "./components/card/card-media.js";
|
|
9
|
+
import { usePresence } from "./hooks/use-presence.js";
|
|
10
|
+
import { Icon } from "./components/icon/icon.js";
|
|
11
|
+
import { Dialog, DialogActions, DialogBody } from "./components/dialog/dialog.js";
|
|
9
12
|
import { useField } from "./components/field/field-context.js";
|
|
10
13
|
import { Field } from "./components/field/field.js";
|
|
11
|
-
import { Icon } from "./components/icon/icon.js";
|
|
12
14
|
import { Input } from "./components/input/input.js";
|
|
15
|
+
import { Popover, Tooltip } from "./components/popover/popover.js";
|
|
13
16
|
import { Heading, Text } from "./components/text/text.js";
|
|
17
|
+
import { ToastProvider, useToast } from "./components/toast/toast.js";
|
|
14
18
|
import { cx } from "./utils/cx.js";
|
|
15
|
-
|
|
19
|
+
import { useDisclosure } from "./hooks/use-disclosure.js";
|
|
20
|
+
export { Avatar, AvatarGroup, Badge, Box, Button, Card, CardHeader, CardMedia, Dialog, DialogActions, DialogBody, Field, Heading, Icon, Input, Popover, Stack, Text, ThemeScope, ToastProvider, Tooltip, cx, splitSprinkles, useDisclosure, useField, usePresence, useToast };
|