@g4rcez/components 0.0.32 → 0.0.34
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/core/button.d.ts +1 -1
- package/dist/components/core/button.d.ts.map +1 -1
- package/dist/components/core/button.js +1 -1
- package/dist/components/display/list.d.ts.map +1 -1
- package/dist/components/display/list.js +15 -17
- package/dist/components/display/notifications.d.ts +25 -0
- package/dist/components/display/notifications.d.ts.map +1 -0
- package/dist/components/display/notifications.js +70 -0
- package/dist/components/floating/menu.d.ts +31 -5
- package/dist/components/floating/menu.d.ts.map +1 -1
- package/dist/components/floating/menu.js +18 -11
- package/dist/components/floating/modal.js +2 -2
- package/dist/components/floating/tooltip.d.ts +4 -4
- package/dist/components/floating/tooltip.d.ts.map +1 -1
- package/dist/components/floating/tooltip.js +7 -6
- package/dist/constants.d.ts +2 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +1 -0
- package/dist/hooks/use-hover.d.ts +3 -0
- package/dist/hooks/use-hover.d.ts.map +1 -0
- package/dist/hooks/use-hover.js +18 -0
- package/dist/hooks/use-on-event.d.ts +4 -0
- package/dist/hooks/use-on-event.d.ts.map +1 -0
- package/dist/hooks/use-on-event.js +7 -0
- package/dist/index.css +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3300 -3271
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +38 -38
- package/dist/index.umd.js.map +1 -1
- package/dist/preset/src/styles/theme.d.ts.map +1 -1
- package/dist/preset/src/styles/theme.js +8 -0
- package/dist/preset/src/styles/theme.types.d.ts +4 -0
- package/dist/preset/src/styles/theme.types.d.ts.map +1 -1
- package/dist/styles/theme.d.ts.map +1 -1
- package/dist/styles/theme.js +8 -0
- package/dist/styles/theme.types.d.ts +4 -0
- package/dist/styles/theme.types.d.ts.map +1 -1
- package/dist/types.d.ts +3 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type VariantProps } from "class-variance-authority";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import { Label } from "../../types";
|
|
3
|
+
import { type Label } from "../../types";
|
|
4
4
|
import { PolymorphicProps } from "./polymorph";
|
|
5
5
|
declare const buttonVariants: (props?: ({
|
|
6
6
|
size?: "big" | "small" | "default" | "icon" | null | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../../../src/components/core/button.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAqB,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../../../src/components/core/button.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAqB,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAa,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE1D,QAAA,MAAM,cAAc;;;;mFA6BnB,CAAC;AAEF,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,KAAK,CAAC,WAAW,GAAG,QAAQ,IAAI,gBAAgB,CAC9E,YAAY,CAAC,OAAO,cAAc,CAAC,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,EAChF,CAAC,CACJ,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,CAAC,CAAC,SAAS,KAAK,CAAC,WAAW,GAAG,QAAQ,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,GAsB7E,CAAC;AAEZ,KAAK,KAAK,GAAG;IACT,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,WAAW,EAAE,CAAC;CAC1B,CAAC;AAEF,eAAO,MAAM,WAAW,UAAW,KAAK,4CAkBvC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../src/components/display/list.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../src/components/display/list.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,EAAY,iBAAiB,EAAgC,MAAM,OAAO,CAAC;AACzF,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,KAAK,iBAAiB,GAAG;IACrB,KAAK,EAAE,KAAK,CAAC;IACb,WAAW,EAAE,KAAK,CAAC;IACnB,QAAQ,EAAE,KAAK,CAAC;IAChB,MAAM,CAAC,EAAE,KAAK,CAAC;IACf,OAAO,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC;QAAE,IAAI,EAAE,MAAM,IAAI,CAAA;KAAE,CAAC,CAAC;CAC5C,CAAC;AAIF,KAAK,iBAAiB,GAAG,EAAE,CAAC;AA6D5B,eAAO,MAAM,YAAY,UAAW,iBAAiB,CAAC,iBAAiB,CAAC,4CAoEvE,CAAC;AAEF,eAAO,MAAM,gBAAgB,UAAW,iBAAiB,CAAC,iBAAiB,CAAC,4CAA0C,CAAC"}
|
|
@@ -1,31 +1,29 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { FloatingFocusManager, FloatingOverlay, FloatingPortal, useClick, useDismiss, useFloating, useInteractions, useRole, } from "@floating-ui/react";
|
|
3
|
+
import { AnimatePresence, motion, MotionConfig } from "framer-motion";
|
|
3
4
|
import { XIcon } from "lucide-react";
|
|
4
|
-
import React, { Fragment, useCallback,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const ref = useRef(null);
|
|
8
|
-
useOnClickOutside(ref, setter);
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
function onKeyDown(event) {
|
|
11
|
-
if (event.key === "Escape")
|
|
12
|
-
setter();
|
|
13
|
-
}
|
|
14
|
-
window.addEventListener("keydown", onKeyDown);
|
|
15
|
-
return () => window.removeEventListener("keydown", onKeyDown);
|
|
16
|
-
}, []);
|
|
17
|
-
return (_jsxs(Fragment, { children: [_jsx(AnimatePresence, { children: item ? (_jsx(motion.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, className: "pointer-events-none absolute inset-0 z-floating h-screen w-screen bg-floating-overlay/70" })) : null }), _jsx(AnimatePresence, { children: item ? (_jsx("div", { className: "absolute inset-0 z-tooltip flex items-center justify-center", children: _jsxs(motion.div, { layout: true, ref: ref, layoutId: `item-${item.id}`, className: "relative flex h-min w-min min-w-xs flex-col gap-4 rounded-card border border-card-border bg-card-background p-6 py-4 pb-8 shadow", children: [_jsx("nav", { className: "absolute right-4 top-1 lg:right-2", children: _jsx("button", { type: "button", onClick: setter, className: "p-1 opacity-70 transition-colors hover:text-danger hover:opacity-100 focus:text-danger", children: _jsx(XIcon, {}) }) }), _jsxs("header", { className: "flex w-full flex-wrap items-center justify-between gap-2", children: [_jsx("h3", { className: "min-w-full text-balance text-2xl font-medium", children: item.title }), _jsx("p", { className: "text-sm leading-snug text-secondary", children: item.description })] }), item.children] }) })) : null })] }));
|
|
5
|
+
import React, { Fragment, useCallback, useId, useState } from "react";
|
|
6
|
+
const FloatItem = ({ item, context, setter, get, refs }) => {
|
|
7
|
+
return (_jsx(FloatingPortal, { children: _jsx(MotionConfig, { reducedMotion: "user", transition: { type: "tween", stiffness: 25, duration: 0.2 }, children: _jsxs(AnimatePresence, { presenceAffectsLayout: true, children: [_jsx(AnimatePresence, { children: item ? (_jsx(motion.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, className: "pointer-events-none fixed inset-0 top-0 z-floating h-screen w-screen bg-floating-overlay/70" })) : null }), _jsx(AnimatePresence, { children: item ? (_jsx(FloatingOverlay, { lockScroll: true, className: "absolute inset-0 z-tooltip flex items-center justify-center", children: _jsx(FloatingFocusManager, { visuallyHiddenDismiss: true, modal: true, closeOnFocusOut: true, context: context, children: _jsxs(motion.div, Object.assign({ layout: true, layoutId: `item-${item.id}`, className: "relative flex h-min w-min min-w-xs flex-col gap-4 rounded-card border border-card-border bg-card-background p-6 py-4 pb-8 shadow", ref: refs.setFloating }, get(), { children: [_jsx("nav", { className: "absolute right-4 top-1 lg:right-2", children: _jsx("button", { type: "button", onClick: setter, className: "p-1 opacity-70 transition-colors hover:text-danger hover:opacity-100 focus:text-danger", children: _jsx(XIcon, {}) }) }), _jsxs("header", { className: "flex w-full flex-wrap items-center justify-between gap-2", children: [_jsx("h3", { className: "min-w-full text-balance text-2xl font-medium", children: item.title }), _jsx("p", { className: "text-sm leading-snug text-secondary", children: item.description })] }), item.children] })) }) })) : null })] }) }) }));
|
|
18
8
|
};
|
|
19
9
|
export const AnimatedList = (props) => {
|
|
20
10
|
const [selected, setSelected] = useState(null);
|
|
21
11
|
const id = useId();
|
|
12
|
+
const { context, refs } = useFloating({
|
|
13
|
+
open: selected !== null,
|
|
14
|
+
transform: true,
|
|
15
|
+
onOpenChange: (open) => (open ? undefined : setSelected(null)),
|
|
16
|
+
});
|
|
17
|
+
const click = useClick(context);
|
|
18
|
+
const role = useRole(context);
|
|
19
|
+
const dismiss = useDismiss(context, { escapeKey: true, referencePress: true, outsidePress: true });
|
|
20
|
+
const { getFloatingProps } = useInteractions([click, role, dismiss]);
|
|
22
21
|
const clear = useCallback(() => {
|
|
23
22
|
setSelected(null);
|
|
24
23
|
}, []);
|
|
25
24
|
const items = React.Children.toArray(props.children);
|
|
26
|
-
return (_jsxs(Fragment, { children: [_jsx(FloatItem, { item: selected, setter: clear }), _jsx("ul", { role: "list", children: items.map((x, index) => {
|
|
25
|
+
return (_jsxs(Fragment, { children: [_jsx(FloatItem, { refs: refs, context: context, get: getFloatingProps, item: selected, setter: clear }), _jsx("ul", { role: "list", children: items.map((x, index) => {
|
|
27
26
|
const item = x.props;
|
|
28
|
-
const isLast = index === items.length - 1;
|
|
29
27
|
const innerId = `${id}-${index}`;
|
|
30
28
|
const setter = () => setSelected(Object.assign(Object.assign({}, item), { id: innerId }));
|
|
31
29
|
const Leading = item.leading;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type VariantProps } from "class-variance-authority";
|
|
2
|
+
import { type PropsWithChildren } from "react";
|
|
3
|
+
import { Label } from "../../types";
|
|
4
|
+
declare const variants: (props?: ({
|
|
5
|
+
theme?: "default" | "warn" | "danger" | "success" | "info" | null | undefined;
|
|
6
|
+
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
7
|
+
type NotificationOptions = Partial<{
|
|
8
|
+
title: Label;
|
|
9
|
+
duration: number;
|
|
10
|
+
closable: boolean;
|
|
11
|
+
theme: VariantProps<typeof variants>["theme"];
|
|
12
|
+
}>;
|
|
13
|
+
type NotificationSubscriber = {
|
|
14
|
+
close: () => void;
|
|
15
|
+
clear: () => void;
|
|
16
|
+
};
|
|
17
|
+
type ContextFunction = (text: Label, args?: NotificationOptions) => NotificationSubscriber;
|
|
18
|
+
export declare const useNotification: () => ContextFunction;
|
|
19
|
+
export type NotificationProps = Partial<{
|
|
20
|
+
max: number;
|
|
21
|
+
duration: number;
|
|
22
|
+
}>;
|
|
23
|
+
export declare function Notifications({ children, max, duration }: PropsWithChildren<NotificationProps>): import("react/jsx-runtime").JSX.Element;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=notifications.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notifications.d.ts","sourceRoot":"","sources":["../../../src/components/display/notifications.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAGlE,OAAO,EAA8C,KAAK,iBAAiB,EAAwD,MAAM,OAAO,CAAC;AAEjJ,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,QAAA,MAAM,QAAQ;;mFAcb,CAAC;AAEF,KAAK,mBAAmB,GAAG,OAAO,CAAC;IAC/B,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,YAAY,CAAC,OAAO,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC;CACjD,CAAC,CAAC;AAEH,KAAK,sBAAsB,GAAG;IAAE,KAAK,EAAE,MAAM,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,IAAI,CAAA;CAAE,CAAC;AAEvE,KAAK,eAAe,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,mBAAmB,KAAK,sBAAsB,CAAC;AAM3F,eAAO,MAAM,eAAe,uBAAwC,CAAC;AAkErE,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAE3E,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,GAAO,EAAE,QAAe,EAAE,EAAE,iBAAiB,CAAC,iBAAiB,CAAC,2CAuDzG"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createElement as _createElement } from "react";
|
|
3
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
|
+
import * as RadixToast from "@radix-ui/react-toast";
|
|
5
|
+
import { cva } from "class-variance-authority";
|
|
6
|
+
import { AnimatePresence, motion } from "framer-motion";
|
|
7
|
+
import { XIcon } from "lucide-react";
|
|
8
|
+
import { createContext, forwardRef, useCallback, useContext, useEffect, useRef, useState } from "react";
|
|
9
|
+
import { useHover } from "../../hooks/use-hover";
|
|
10
|
+
const variants = cva("relative isolate z-tooltip flex justify-between overflow-hidden whitespace-nowrap rounded-lg border text-sm shadow-sm supports-[backdrop-filter]:backdrop-blur-xl", {
|
|
11
|
+
variants: {
|
|
12
|
+
theme: {
|
|
13
|
+
warn: "bg-warn-notification/90 text-warn-hover border-warn/50",
|
|
14
|
+
info: "bg-info-notification supports-[backdrop-filter]:bg-info-notification/50 supports-[backdrop-filter]:bg-info/20 text-info border-info/50",
|
|
15
|
+
danger: "bg-danger-notification supports-[backdrop-filter]:bg-danger-notification/60 text-danger border-danger/50",
|
|
16
|
+
success: "bg-success-notification supports-[backdrop-filter]:bg-success-notification/50 text-success border-success/50",
|
|
17
|
+
default: "border-card-border bg-card-background text-foreground",
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
defaultVariants: { theme: "default" },
|
|
21
|
+
});
|
|
22
|
+
const NotificationContext = createContext(() => {
|
|
23
|
+
throw new Error("Not implemented");
|
|
24
|
+
});
|
|
25
|
+
export const useNotification = () => useContext(NotificationContext);
|
|
26
|
+
const animatedIndex = {
|
|
27
|
+
0: { opacity: 1, y: [10, 15], scale: [1, 0.98] },
|
|
28
|
+
1: { opacity: 1, y: [15, 20], scale: [1, 0.97] },
|
|
29
|
+
2: { opacity: 1, y: [20, 25], scale: [1, 0.96] },
|
|
30
|
+
default: { opacity: 1, y: [25, 30], scale: [1, 0.95] },
|
|
31
|
+
};
|
|
32
|
+
const Notification = forwardRef(function Toast(props, forwardedRef) {
|
|
33
|
+
var _a;
|
|
34
|
+
const closable = (_a = props.closable) !== null && _a !== void 0 ? _a : true;
|
|
35
|
+
const duration = props.duration;
|
|
36
|
+
const variant = props.hover ? "hover" : props.isLast ? "isLast" : "other";
|
|
37
|
+
const className = variants({ theme: props.theme || "default" });
|
|
38
|
+
return (_jsx(RadixToast.Root, { ref: forwardedRef, asChild: true, forceMount: true, onOpenChange: props.onClose, duration: duration, children: _jsx(motion.li, { layout: true, layoutScroll: true, animate: variant, "data-index": props.index, initial: { y: -100, zIndex: -1 }, className: "text-select pointer-events-auto absolute right-0 top-0 w-80", variants: {
|
|
39
|
+
isLast: { y: 10, scale: 1, animationDuration: "300ms", opacity: 1 },
|
|
40
|
+
hover: { y: 0, position: "static", scale: 1, opacity: 1 },
|
|
41
|
+
other: animatedIndex[props.reversedIndex] || animatedIndex.default,
|
|
42
|
+
}, transition: { type: "spring", mass: 1.2, damping: 30, stiffness: 200 }, exit: { opacity: [0.9, 0], transition: { opacity: { bounce: 0.25, duration: 0.3 } } }, children: _jsxs("div", { className: className, children: [_jsxs("div", { className: "flex flex-col p-4", children: [props.title ? (_jsx(RadixToast.Title, { className: "select-text truncate text-lg font-medium leading-relaxed", children: "Title" })) : null, _jsxs(RadixToast.Description, { className: "select-text truncate", children: [props.text, props.index] })] }), closable ? (_jsx(RadixToast.Close, { className: "absolute right-2 top-2 rounded-full p-1 text-foreground transition hover:bg-danger/10 hover:text-danger-hover", children: _jsx(XIcon, { className: "h-5 w-5" }) })) : null] }) }) }));
|
|
43
|
+
});
|
|
44
|
+
export function Notifications({ children, max = 5, duration = 5000 }) {
|
|
45
|
+
const ref = useRef(null);
|
|
46
|
+
const hover = useHover(ref);
|
|
47
|
+
const [messages, setMessages] = useState([]);
|
|
48
|
+
const clear = useCallback(() => setMessages([]), []);
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
return () => clear();
|
|
51
|
+
}, [clear]);
|
|
52
|
+
const notify = useCallback((text, args) => {
|
|
53
|
+
const id = window.crypto.randomUUID();
|
|
54
|
+
setMessages((prev) => {
|
|
55
|
+
const newItems = [...prev, Object.assign(Object.assign({}, args), { id, text })];
|
|
56
|
+
if (newItems.length > max)
|
|
57
|
+
return newItems.slice(newItems.length - max, newItems.length + 1);
|
|
58
|
+
return newItems;
|
|
59
|
+
});
|
|
60
|
+
const close = () => setMessages((prev) => prev.filter((x) => x.id !== id));
|
|
61
|
+
return { clear, close };
|
|
62
|
+
}, [max]);
|
|
63
|
+
return (_jsxs(RadixToast.Provider, { duration: duration, swipeThreshold: 150, children: [_jsx(NotificationContext.Provider, { value: notify, children: children }), _jsx(AnimatePresence, { presenceAffectsLayout: true, mode: "popLayout", children: messages.map((toast, index, list) => {
|
|
64
|
+
const close = () => setMessages((prev) => prev.filter((t) => t.id !== toast.id));
|
|
65
|
+
return (_createElement(Notification, Object.assign({}, toast, { key: toast.id, hover: hover, index: index, onClose: close, isLast: list.length - 1 === index, reversedIndex: list.length - (index + 1) })));
|
|
66
|
+
}) }), _jsx(RadixToast.Viewport, { ref: ref, "data-items": messages.length, style: {
|
|
67
|
+
justifyContent: "start",
|
|
68
|
+
height: `${(hover ? messages.length : Math.min(1, messages.length)) * 7}rem`,
|
|
69
|
+
}, className: "fixed right-4 top-10 flex w-80 list-none flex-col-reverse items-end gap-4 overflow-y-clip overflow-x-visible data-[items=true]:pb-8 max-sm:top-20" })] }));
|
|
70
|
+
}
|
|
@@ -1,17 +1,43 @@
|
|
|
1
1
|
import { LucideProps } from "lucide-react";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { Override } from "../../types";
|
|
4
|
+
export type MenuProps = Partial<{
|
|
5
|
+
nested: boolean;
|
|
6
|
+
isParent: boolean;
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
asChild: boolean;
|
|
9
|
+
} & ({
|
|
10
|
+
label: string;
|
|
11
|
+
} | {
|
|
12
|
+
label: React.ReactElement;
|
|
13
|
+
title: string;
|
|
14
|
+
})>;
|
|
4
15
|
type MenuItemProps = {
|
|
5
16
|
label: string;
|
|
6
17
|
disabled?: boolean;
|
|
7
18
|
Right?: React.FC<LucideProps>;
|
|
19
|
+
} | {
|
|
20
|
+
label: React.ReactElement;
|
|
21
|
+
title: string;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
Right?: React.FC<LucideProps>;
|
|
8
24
|
};
|
|
9
|
-
export declare const MenuItem: React.ForwardRefExoticComponent<
|
|
10
|
-
export declare const Menu: React.ForwardRefExoticComponent<Omit<Partial<{
|
|
25
|
+
export declare const MenuItem: React.ForwardRefExoticComponent<Override<React.ButtonHTMLAttributes<HTMLButtonElement>, MenuItemProps> & React.RefAttributes<HTMLButtonElement>>;
|
|
26
|
+
export declare const Menu: React.ForwardRefExoticComponent<(Omit<Omit<React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "label" | "children" | "asChild" | "nested" | "isParent"> & Partial<{
|
|
27
|
+
nested: boolean;
|
|
11
28
|
isParent: boolean;
|
|
12
|
-
|
|
29
|
+
children: React.ReactNode;
|
|
30
|
+
asChild: boolean;
|
|
31
|
+
} & {
|
|
32
|
+
label: string;
|
|
33
|
+
}>, "ref"> | Omit<Omit<React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "label" | "children" | "asChild" | "nested" | "isParent"> & Partial<{
|
|
13
34
|
nested: boolean;
|
|
35
|
+
isParent: boolean;
|
|
14
36
|
children: React.ReactNode;
|
|
15
|
-
|
|
37
|
+
asChild: boolean;
|
|
38
|
+
} & {
|
|
39
|
+
label: React.ReactElement;
|
|
40
|
+
title: string;
|
|
41
|
+
}>, "ref">) & React.RefAttributes<HTMLButtonElement>>;
|
|
16
42
|
export {};
|
|
17
43
|
//# sourceMappingURL=menu.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu.d.ts","sourceRoot":"","sources":["../../../src/components/floating/menu.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"menu.d.ts","sourceRoot":"","sources":["../../../src/components/floating/menu.tsx"],"names":[],"mappings":"AA0BA,OAAO,EAAoB,WAAW,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,KAA2E,MAAM,OAAO,CAAC;AAGhG,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAyBvC,MAAM,MAAM,SAAS,GAAG,OAAO,CAC3B;IACI,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,OAAO,EAAE,OAAO,CAAC;CACpB,GAAG,CAAC;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,KAAK,CAAC,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CACzE,CAAC;AA6JF,KAAK,aAAa,GACZ;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAAC,CAAA;CAAE,GACpE;IAAE,KAAK,EAAE,KAAK,CAAC,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAAC,CAAA;CAAE,CAAC;AAEtG,eAAO,MAAM,QAAQ,kJAiCpB,CAAC;AAEF,eAAO,MAAM,IAAI;YAzMD,OAAO;cACL,OAAO;cACP,KAAK,CAAC,SAAS;aAChB,OAAO;;WACN,MAAM;;YAJR,OAAO;cACL,OAAO;cACP,KAAK,CAAC,SAAS;aAChB,OAAO;;WACc,KAAK,CAAC,YAAY;WAAS,MAAM;qDA8MrE,CAAC"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { autoUpdate, flip, FloatingFocusManager, FloatingList, FloatingNode, FloatingPortal, FloatingTree, offset, safePolygon, shift, useClick, useDismiss, useFloating, useFloatingNodeId, useFloatingParentNodeId, useFloatingTree, useHover, useInteractions, useListItem, useListNavigation, useMergeRefs, useRole, useTypeahead, } from "@floating-ui/react";
|
|
4
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
4
5
|
import { ChevronRightIcon } from "lucide-react";
|
|
5
|
-
import React, { createContext, useContext, useEffect, useRef, useState } from "react";
|
|
6
|
+
import React, { createContext, Fragment, useContext, useEffect, useRef, useState } from "react";
|
|
7
|
+
import { FLOATING_DELAY } from "../../constants";
|
|
6
8
|
import { css } from "../../lib/dom";
|
|
7
|
-
const menuItemClassName = (highlight = "") => css("w-full min-w-36 outline-none px-2 py-1 items-center flex justify-between text-left", "
|
|
9
|
+
const menuItemClassName = (highlight = "") => css("w-full min-w-36 outline-none px-2 py-1 items-center flex justify-between text-left", "hover:bg-primary data-[open]:bg-primary focus:bg-primary aria-expanded:opacity-80", "first-of-type:rounded-t-lg last-of-type:rounded-b-lg", "disabled:opacity-40 disabled:cursor-not-allowed", highlight);
|
|
8
10
|
const MenuContext = createContext({
|
|
9
11
|
isOpen: false,
|
|
10
12
|
activeIndex: null,
|
|
@@ -38,7 +40,7 @@ const MenuComponent = React.forwardRef((_a, forwardedRef) => {
|
|
|
38
40
|
const dismiss = useDismiss(context, { bubbles: true });
|
|
39
41
|
const hover = useHover(context, {
|
|
40
42
|
enabled: true,
|
|
41
|
-
delay: { open:
|
|
43
|
+
delay: { open: FLOATING_DELAY },
|
|
42
44
|
handleClose: safePolygon({ blockPointerEvents: true }),
|
|
43
45
|
});
|
|
44
46
|
const click = useClick(context, {
|
|
@@ -84,17 +86,22 @@ const MenuComponent = React.forwardRef((_a, forwardedRef) => {
|
|
|
84
86
|
tree.events.emit("menuopen", { parentId, nodeId });
|
|
85
87
|
}, [tree, isOpen, nodeId, parentId]);
|
|
86
88
|
const className = isParent ? props.className : menuItemClassName(props.className);
|
|
87
|
-
return (_jsxs(FloatingNode, { id: nodeId, children: [
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
return (_jsxs(FloatingNode, { id: nodeId, children: [_jsx(Fragment, { children: props.asChild ? (_jsx(Slot, Object.assign({ children: label, ref: useMergeRefs([refs.setReference, item.ref, forwardedRef]), tabIndex: !isNested ? undefined : parent.activeIndex === item.index ? 0 : -1, "data-open": isOpen ? "" : undefined, "data-nested": isNested ? "" : undefined, role: isNested ? "menuitem" : undefined, "data-focus-inside": hasFocusInside ? "" : undefined, className: className }, getReferenceProps(parent.getItemProps(Object.assign(Object.assign({}, props), { onFocus(event) {
|
|
90
|
+
var _a;
|
|
91
|
+
(_a = props.onFocus) === null || _a === void 0 ? void 0 : _a.call(props, event);
|
|
92
|
+
setHasFocusInside(false);
|
|
93
|
+
parent.setHasFocusInside(true);
|
|
94
|
+
} })))))) : (_jsxs("button", Object.assign({ ref: useMergeRefs([refs.setReference, item.ref, forwardedRef]), tabIndex: !isNested ? undefined : parent.activeIndex === item.index ? 0 : -1, "data-open": isOpen ? "" : undefined, "data-nested": isNested ? "" : undefined, role: isNested ? "menuitem" : undefined, "data-focus-inside": hasFocusInside ? "" : undefined, className: className }, getReferenceProps(parent.getItemProps(Object.assign(Object.assign({}, props), { onFocus(event) {
|
|
95
|
+
var _a;
|
|
96
|
+
(_a = props.onFocus) === null || _a === void 0 ? void 0 : _a.call(props, event);
|
|
97
|
+
setHasFocusInside(false);
|
|
98
|
+
parent.setHasFocusInside(true);
|
|
99
|
+
} }))), { children: [label, isNested && (_jsxs("span", { style: { marginLeft: 10, fontSize: 10 }, children: [_jsx("span", { className: "sr-only", children: "Next menu" }), _jsx(ChevronRightIcon, { size: 14 })] }))] }))) }), _jsx(MenuContext.Provider, { value: { activeIndex, setActiveIndex, getItemProps, setHasFocusInside, isOpen }, children: _jsx(FloatingList, { elementsRef: elementsRef, labelsRef: labelsRef, children: isOpen && (_jsx(FloatingPortal, { preserveTabOrder: true, children: _jsx(FloatingFocusManager, { context: context, modal: false, initialFocus: isNested ? -1 : 0, returnFocus: !isNested, children: _jsx("div", Object.assign({ ref: refs.setFloating, style: floatingStyles, className: "isolate z-tooltip flex flex-col items-start rounded-lg border border-floating-border bg-floating-background text-left shadow-xl outline-none" }, getFloatingProps(), { children: children })) }) })) }) })] }));
|
|
93
100
|
});
|
|
94
101
|
export const MenuItem = React.forwardRef((_a, forwardedRef) => {
|
|
95
|
-
var { label, Right, disabled } = _a, props = __rest(_a, ["label", "Right", "disabled"]);
|
|
102
|
+
var { label, title, Right, disabled } = _a, props = __rest(_a, ["label", "title", "Right", "disabled"]);
|
|
96
103
|
const menu = useContext(MenuContext);
|
|
97
|
-
const item = useListItem({ label: disabled ? null : label });
|
|
104
|
+
const item = useListItem({ label: disabled ? null : typeof label === "string" ? label : title });
|
|
98
105
|
const tree = useFloatingTree();
|
|
99
106
|
const isActive = item.index === menu.activeIndex;
|
|
100
107
|
return (_jsxs("button", Object.assign({}, props, { ref: useMergeRefs([item.ref, forwardedRef]), "data-active": isActive, type: "button", role: "menuitem", disabled: disabled, tabIndex: isActive ? 0 : -1, className: menuItemClassName(props.className) }, menu.getItemProps({
|
|
@@ -37,7 +37,7 @@ const variants = cva("isolate z-floating border border-card-border ring-0 outlin
|
|
|
37
37
|
variants: {
|
|
38
38
|
type: {
|
|
39
39
|
drawer: "max-h-screen max-w-[90%] absolute w-fit h-screen min-h-0",
|
|
40
|
-
dialog: "max-h-[calc(100lvh-10%)] relative container h-min rounded-lg py-
|
|
40
|
+
dialog: "max-h-[calc(100lvh-10%)] relative container h-min rounded-lg py-4",
|
|
41
41
|
sheet: "w-screen absolute bottom-0 h-[85vh] max-h-[85vh] max-h-[85svh] pt-6 pb-4 rounded-t-lg",
|
|
42
42
|
},
|
|
43
43
|
position: {
|
|
@@ -96,5 +96,5 @@ export const Modal = (_a) => {
|
|
|
96
96
|
const Trigger = props.trigger;
|
|
97
97
|
const value = useMotionValue(undefined);
|
|
98
98
|
const onClose = () => props.onChange(false);
|
|
99
|
-
return (_jsxs(Fragment, { children: [props.trigger ? (_jsx(Fragment, { children: props.asChild ? (_jsx(Slot, Object.assign({ ref: refs.setReference }, getReferenceProps(), { children: Trigger }))) : (_jsx("button", Object.assign({ ref: refs.setReference }, getReferenceProps(), { type: "button", children: Trigger }))) })) : null, _jsx(FloatingPortal, { children: _jsx(AnimatePresence, { presenceAffectsLayout: true, children: props.open ? (_jsx(FloatingOverlay, { lockScroll: true, className: `z-overlay inset-0 isolate h-[100dvh] !overflow-clip bg-floating-overlay/70 ${type === "drawer" ? "" : "grid items-end justify-center lg:items-center"}`, children: _jsx(FloatingFocusManager, { visuallyHiddenDismiss: true, modal: true, closeOnFocusOut: true, context: context, children: _jsxs(motion.div, Object.assign({ animate: "enter", "aria-describedby": descriptionId, "aria-labelledby": headingId, className: variants({ position, type }), exit: "exit", initial: "initial", ref: refs.setFloating, style: type === "drawer" ? { width: value } : { height: value }, variants: animation }, getFloatingProps(), { children: [props.title ? (_jsx("header", { className: "relative w-full", children: props.title ? (_jsx("h2", { className: "border-b border-floating-border px-8 pb-
|
|
99
|
+
return (_jsxs(Fragment, { children: [props.trigger ? (_jsx(Fragment, { children: props.asChild ? (_jsx(Slot, Object.assign({ ref: refs.setReference }, getReferenceProps(), { children: Trigger }))) : (_jsx("button", Object.assign({ ref: refs.setReference }, getReferenceProps(), { type: "button", children: Trigger }))) })) : null, _jsx(FloatingPortal, { children: _jsx(AnimatePresence, { presenceAffectsLayout: true, children: props.open ? (_jsx(FloatingOverlay, { lockScroll: true, className: `z-overlay inset-0 isolate h-[100dvh] !overflow-clip bg-floating-overlay/70 ${type === "drawer" ? "" : "grid items-end justify-center lg:items-center"}`, children: _jsx(FloatingFocusManager, { visuallyHiddenDismiss: true, modal: true, closeOnFocusOut: true, context: context, children: _jsxs(motion.div, Object.assign({ animate: "enter", "aria-describedby": descriptionId, "aria-labelledby": headingId, className: variants({ position, type }), exit: "exit", initial: "initial", ref: refs.setFloating, style: type === "drawer" ? { width: value } : { height: value }, variants: animation }, getFloatingProps(), { children: [props.title ? (_jsx("header", { className: "relative w-full", children: props.title ? (_jsx("h2", { className: "border-b border-floating-border px-8 pb-2 text-3xl font-medium leading-relaxed", children: props.title })) : null })) : null, _jsx("section", { className: "py-1 flex-1 overflow-y-auto px-8", children: props.children }), props.footer ? (_jsx("footer", { className: "w-full border-t border-floating-border px-8 pt-4", children: props.footer })) : null, closable ? (_jsx("nav", { className: "absolute right-4 top-1", children: _jsx("button", { type: "button", onClick: onClose, className: "p-1 opacity-70 transition-colors hover:text-danger hover:opacity-100 focus:text-danger", children: _jsx(XIcon, {}) }) })) : null, useResizer && resizer ? (_jsx(Draggable, { onChange: props.onChange, parent: refs.floating, position: position, sheet: type === "sheet", value: value })) : null] })) }) })) : null }) })] }));
|
|
100
100
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { PolymorphicProps } from "../../components/core/polymorph";
|
|
3
|
-
import { Label, Override } from "../../types";
|
|
4
|
-
type TooltipProps = Override<PolymorphicProps<React.ComponentProps<
|
|
3
|
+
import { ComponentLike, Label, Override } from "../../types";
|
|
4
|
+
export type TooltipProps<T extends ComponentLike = "span"> = Override<PolymorphicProps<React.ComponentProps<T>, T>, {
|
|
5
5
|
title: Label;
|
|
6
|
+
enabled?: boolean;
|
|
6
7
|
}>;
|
|
7
|
-
export declare const Tooltip: ({ children, as, title, ...props }: TooltipProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
-
export {};
|
|
8
|
+
export declare const Tooltip: <T extends ComponentLike = "span">({ children, enabled, as, title, ...props }: TooltipProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
9
9
|
//# sourceMappingURL=tooltip.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../../src/components/floating/tooltip.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAqC,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAa,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../../src/components/floating/tooltip.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAqC,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAa,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAE9E,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE7D,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,aAAa,GAAG,MAAM,IAAI,QAAQ,CACjE,gBAAgB,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAC5C;IACI,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB,CACJ,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,aAAa,uDAAuD,YAAY,CAAC,CAAC,CAAC,4CA6CpH,CAAC"}
|
|
@@ -4,8 +4,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
4
4
|
import { arrow, autoUpdate, flip, FloatingArrow, FloatingPortal, offset, shift, useDismiss, useFloating, useFocus, useHover, useInteractions, useRole, } from "@floating-ui/react";
|
|
5
5
|
import { Fragment, useRef, useState } from "react";
|
|
6
6
|
import { Polymorph } from "../../components/core/polymorph";
|
|
7
|
+
import { FLOATING_DELAY } from "../../constants";
|
|
7
8
|
export const Tooltip = (_a) => {
|
|
8
|
-
var { children, as, title } = _a, props = __rest(_a, ["children", "as", "title"]);
|
|
9
|
+
var { children, enabled, as, title } = _a, props = __rest(_a, ["children", "enabled", "as", "title"]);
|
|
9
10
|
const [isOpen, setIsOpen] = useState(false);
|
|
10
11
|
const arrowRef = useRef(null);
|
|
11
12
|
const Component = as || "span";
|
|
@@ -24,10 +25,10 @@ export const Tooltip = (_a) => {
|
|
|
24
25
|
}),
|
|
25
26
|
],
|
|
26
27
|
});
|
|
27
|
-
const hover = useHover(context, { move: true });
|
|
28
|
-
const focus = useFocus(context);
|
|
29
|
-
const dismiss = useDismiss(context);
|
|
30
|
-
const role = useRole(context, { role: "tooltip" });
|
|
28
|
+
const hover = useHover(context, { move: true, delay: { open: FLOATING_DELAY } });
|
|
29
|
+
const focus = useFocus(context, { enabled });
|
|
30
|
+
const dismiss = useDismiss(context, { enabled });
|
|
31
|
+
const role = useRole(context, { role: "tooltip", enabled });
|
|
31
32
|
const { getReferenceProps, getFloatingProps } = useInteractions([hover, focus, dismiss, role]);
|
|
32
|
-
return (_jsxs(Fragment, { children: [_jsx(Component, Object.assign({ ref: refs.setReference }, getReferenceProps(props), { children: title })), _jsx(FloatingPortal, { children: isOpen && (_jsxs(Polymorph, Object.assign({}, getFloatingProps(), { ref: refs.setFloating, style: floatingStyles, className: "
|
|
33
|
+
return (_jsxs(Fragment, { children: [_jsx(Component, Object.assign({ ref: refs.setReference }, getReferenceProps(props), { children: title })), _jsx(FloatingPortal, { children: isOpen && (_jsxs(Polymorph, Object.assign({}, getFloatingProps(), { ref: refs.setFloating, style: floatingStyles, className: "z-tooltip rounded-lg border border-tooltip-border bg-tooltip-background p-3 text-tooltip-foreground", children: [_jsx(FloatingArrow, { ref: arrowRef, context: context, strokeWidth: 0.1, className: "fill-tooltip-background stroke-tooltip-border" }), children] }))) })] }));
|
|
33
34
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,MAAM,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const FLOATING_DELAY = 300;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-hover.d.ts","sourceRoot":"","sources":["../../src/hooks/use-hover.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAuB,MAAM,OAAO,CAAC;AAEvD,eAAO,MAAM,QAAQ,QAAS,SAAS,CAAC,WAAW,CAAC,YAiBnD,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
export const useHover = (ref) => {
|
|
3
|
+
const [hovered, setHovered] = useState(false);
|
|
4
|
+
const enter = () => setHovered(true);
|
|
5
|
+
const leave = () => setHovered(false);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const el = ref.current; // cache external ref value for use in cleanup
|
|
8
|
+
if (el) {
|
|
9
|
+
el.addEventListener("mouseenter", enter);
|
|
10
|
+
el.addEventListener("mouseleave", leave);
|
|
11
|
+
return () => {
|
|
12
|
+
el.removeEventListener("mouseenter", enter);
|
|
13
|
+
el.removeEventListener("mouseleave", leave);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
}, []);
|
|
17
|
+
return hovered;
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-on-event.d.ts","sourceRoot":"","sources":["../../src/hooks/use-on-event.ts"],"names":[],"mappings":"AAEA,KAAK,QAAQ,CAAC,CAAC,SAAS,MAAM,cAAc,IAAI,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;AAEnF,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,MAAM,cAAc,SAAS,CAAC,QAAQ,QAAQ,CAAC,CAAC,CAAC,SAKrF,CAAC"}
|