@babylonlabs-io/core-ui 1.29.0 → 1.30.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/Avatar/ValidatorAvatar.d.ts +5 -0
- package/dist/components/Avatar/ValidatorAvatar.js +6 -0
- package/dist/components/Avatar/ValidatorAvatar.stories.d.ts +7 -0
- package/dist/components/Avatar/ValidatorAvatar.stories.js +21 -0
- package/dist/components/Avatar/index.d.ts +1 -0
- package/dist/components/Avatar/index.js +1 -0
- package/dist/components/Card/Card.stories.d.ts +2 -0
- package/dist/components/Card/Card.stories.js +21 -2
- package/dist/components/Icons/common/BugReportIcon.d.ts +2 -0
- package/dist/components/Icons/common/BugReportIcon.js +7 -0
- package/dist/components/Icons/common/ChevronLeftIcon.d.ts +2 -0
- package/dist/components/Icons/common/ChevronLeftIcon.js +7 -0
- package/dist/components/Icons/index.d.ts +2 -0
- package/dist/components/Icons/index.js +2 -0
- package/dist/components/List/List.stories.d.ts +1 -0
- package/dist/components/List/List.stories.js +12 -0
- package/dist/components/List/StatItem.d.ts +10 -0
- package/dist/components/List/StatItem.js +24 -0
- package/dist/components/List/index.d.ts +1 -0
- package/dist/components/List/index.js +1 -0
- package/dist/components/Menu/Menu.js +1 -1
- package/dist/components/Menu/MenuDrawer.js +3 -1
- package/dist/components/Popover/Popover.js +1 -1
- package/dist/components/Portal/Portal.d.ts +5 -1
- package/dist/components/Portal/Portal.js +27 -28
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +2 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/useCopy.js +22 -27
- package/dist/hooks/useDrawerAnimation.d.ts +18 -0
- package/dist/hooks/useDrawerAnimation.js +42 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +1756 -1593
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/providers/CoreUIProvider.d.ts +11 -0
- package/dist/providers/CoreUIProvider.js +9 -0
- package/dist/style.css +1 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/widgets/sections/SettingMenu/SettingMenu.js +2 -1
- package/dist/widgets/sections/WalletMenu/WalletMenu.d.ts +7 -0
- package/dist/widgets/sections/WalletMenu/WalletMenu.js +6 -3
- package/dist/widgets/sections/WalletMenu/components/WalletInfoCard.js +1 -1
- package/dist/widgets/sections/WalletMenu/components/WalletInfoSection.js +1 -1
- package/dist/widgets/sections/WalletMenu/components/WalletSettingItem.js +1 -1
- package/package.json +1 -1
- package/tailwind.config.js +86 -3
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AvatarProps } from "./Avatar";
|
|
2
|
+
export interface ValidatorAvatarProps extends Omit<AvatarProps, "children"> {
|
|
3
|
+
name: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function ValidatorAvatar({ url, name, variant, size, ...props }: ValidatorAvatarProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Avatar } from "./Avatar";
|
|
3
|
+
import { Text } from "../Text";
|
|
4
|
+
export function ValidatorAvatar({ url, name, variant = "rounded", size = "large", ...props }) {
|
|
5
|
+
return (_jsx(Avatar, { ...props, url: url, alt: name, variant: variant, size: size, children: _jsx(Text, { as: "span", className: "inline-flex h-full w-full items-center justify-center bg-secondary-main text-xs text-accent-contrast", children: name?.charAt(0).toUpperCase() || "?" }) }));
|
|
6
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import { ValidatorAvatar } from "./ValidatorAvatar";
|
|
3
|
+
declare const meta: Meta<typeof ValidatorAvatar>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof meta>;
|
|
6
|
+
export declare const Image: Story;
|
|
7
|
+
export declare const Initials: Story;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ValidatorAvatar } from "./ValidatorAvatar";
|
|
2
|
+
const meta = {
|
|
3
|
+
component: ValidatorAvatar,
|
|
4
|
+
tags: ["autodocs"],
|
|
5
|
+
};
|
|
6
|
+
export default meta;
|
|
7
|
+
export const Image = {
|
|
8
|
+
args: {
|
|
9
|
+
name: "Satoshi",
|
|
10
|
+
url: "/images/wallets/binance.webp",
|
|
11
|
+
size: "large",
|
|
12
|
+
variant: "rounded",
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
export const Initials = {
|
|
16
|
+
args: {
|
|
17
|
+
name: "Satoshi",
|
|
18
|
+
size: "large",
|
|
19
|
+
variant: "rounded",
|
|
20
|
+
},
|
|
21
|
+
};
|
|
@@ -1,10 +1,29 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Card } from "./Card";
|
|
3
3
|
const meta = {
|
|
4
4
|
component: Card,
|
|
5
5
|
tags: ["autodocs"],
|
|
6
|
+
parameters: {
|
|
7
|
+
docs: {
|
|
8
|
+
description: {
|
|
9
|
+
component: "A card component that automatically adapts to light and dark themes using the theme colors defined in the Tailwind configuration.",
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
},
|
|
6
13
|
};
|
|
7
14
|
export default meta;
|
|
8
15
|
export const Default = {
|
|
9
|
-
args: {
|
|
16
|
+
args: {
|
|
17
|
+
children: (_jsxs("div", { children: [_jsx("h3", { className: "text-primary-main font-semibold mb-2", children: "Card Title" }), _jsx("p", { className: "text-accent-primary", children: "This card automatically changes appearance when switching between light and dark modes using the theme colors." }), _jsx("div", { className: "mt-4 p-3 bg-primary-main text-primary-contrast rounded", children: "Theme-aware content" })] })),
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
export const WithThemeColors = {
|
|
21
|
+
args: {
|
|
22
|
+
children: (_jsxs("div", { className: "space-y-4", children: [_jsxs("div", { children: [_jsx("h4", { className: "text-accent-primary font-medium mb-2", children: "Primary Colors" }), _jsxs("div", { className: "flex gap-2 flex-wrap", children: [_jsx("div", { className: "w-8 h-8 bg-primary-main rounded" }), _jsx("div", { className: "w-8 h-8 bg-primary-light rounded" }), _jsx("div", { className: "w-8 h-8 bg-primary-dark rounded" })] })] }), _jsxs("div", { children: [_jsx("h4", { className: "text-accent-primary font-medium mb-2", children: "Secondary Colors" }), _jsxs("div", { className: "flex gap-2 flex-wrap", children: [_jsx("div", { className: "w-8 h-8 bg-secondary-main rounded" }), _jsx("div", { className: "w-8 h-8 bg-secondary-strokeLight rounded border" }), _jsx("div", { className: "w-8 h-8 bg-secondary-highlight rounded" })] })] }), _jsxs("div", { children: [_jsx("h4", { className: "text-accent-primary font-medium mb-2", children: "Surface Colors" }), _jsx("div", { className: "flex gap-2 flex-wrap", children: _jsx("div", { className: "w-16 h-8 bg-surface rounded border border-secondary-strokeLight" }) })] })] })),
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
export const WithExplicitDarkClasses = {
|
|
26
|
+
args: {
|
|
27
|
+
children: (_jsxs("div", { children: [_jsx("h3", { className: "text-primary-main dark:text-white font-semibold mb-2", children: "Explicit Dark Mode Classes" }), _jsx("p", { className: "text-accent-primary dark:text-accent-secondary", children: "This demonstrates using explicit dark: prefix classes alongside theme colors." }), _jsx("div", { className: "mt-4 p-3 bg-primary-main dark:bg-primary-dark text-primary-contrast rounded", children: "Content with explicit dark mode overrides" })] })),
|
|
28
|
+
},
|
|
10
29
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { iconColorVariants } from "../index";
|
|
3
|
+
import { twJoin } from "tailwind-merge";
|
|
4
|
+
export const BugReportIcon = ({ className = "", size = 16, variant = "default", color }) => {
|
|
5
|
+
const colorClass = color || iconColorVariants[variant];
|
|
6
|
+
return (_jsx("svg", { style: { width: size, height: size }, viewBox: "0 0 16 16.5", fill: "none", xmlns: "http://www.w3.org/2000/svg", className: twJoin("transition-opacity duration-200", colorClass, className), children: _jsx("path", { d: "M11.865 5.5H4.135L0.5 9.135V11.865L4.135 15.5H11.865L15.5 11.865V9.135L11.865 5.5ZM8 13.15C7.28 13.15 6.85 12.72 6.85 12C6.85 11.28 7.28 10.85 8 10.85C8.72 10.85 9.15 11.28 9.15 12C9.15 12.72 8.72 13.15 8 13.15ZM9 10.5H7V7.5H9V10.5Z", fill: "currentColor" }) }));
|
|
7
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { twJoin } from "tailwind-merge";
|
|
3
|
+
import { iconColorVariants } from "../index";
|
|
4
|
+
export const ChevronLeftIcon = ({ className = "", size = 16, variant = "default", color }) => {
|
|
5
|
+
const colorClass = color || iconColorVariants[variant];
|
|
6
|
+
return (_jsx("svg", { style: { width: size, height: size }, viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", className: twJoin("transition-opacity duration-200", colorClass, className), children: _jsx("path", { d: "M10 12L6 8L10 4", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
7
|
+
};
|
|
@@ -24,3 +24,5 @@ export { CloseIcon } from "./common/CloseIcon";
|
|
|
24
24
|
export { WarningIcon } from "./common/WarningIcon";
|
|
25
25
|
export { CollapseIcon } from "./common/CollapseIcon";
|
|
26
26
|
export { OpenIcon } from "./common/OpenIcon";
|
|
27
|
+
export { ChevronLeftIcon } from "./common/ChevronLeftIcon";
|
|
28
|
+
export { BugReportIcon } from "./common/BugReportIcon";
|
|
@@ -19,3 +19,5 @@ export { CloseIcon } from "./common/CloseIcon";
|
|
|
19
19
|
export { WarningIcon } from "./common/WarningIcon";
|
|
20
20
|
export { CollapseIcon } from "./common/CollapseIcon";
|
|
21
21
|
export { OpenIcon } from "./common/OpenIcon";
|
|
22
|
+
export { ChevronLeftIcon } from "./common/ChevronLeftIcon";
|
|
23
|
+
export { BugReportIcon } from "./common/BugReportIcon";
|
|
@@ -2,6 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { MdOutlineInfo, MdAccountBalanceWallet, MdTrendingUp } from "react-icons/md";
|
|
3
3
|
import { List } from "./List";
|
|
4
4
|
import { ListItem } from "./components/ListItem";
|
|
5
|
+
import { StatItem } from "./StatItem";
|
|
5
6
|
const meta = {
|
|
6
7
|
component: List,
|
|
7
8
|
tags: ["autodocs"],
|
|
@@ -67,3 +68,14 @@ export const SingleItem = {
|
|
|
67
68
|
children: [_jsx(ListItem, { title: "Single Entry", value: "Only one item in list", suffix: _jsx(MdOutlineInfo, { size: 20 }) })],
|
|
68
69
|
},
|
|
69
70
|
};
|
|
71
|
+
export const WithStatItems = {
|
|
72
|
+
name: "With StatItem examples",
|
|
73
|
+
args: {
|
|
74
|
+
orientation: "adaptive",
|
|
75
|
+
children: [
|
|
76
|
+
_jsx(StatItem, { title: "Total BTC TVL", value: "2,345 BTC", tooltip: "Total value locked in BTC" }),
|
|
77
|
+
_jsx(StatItem, { title: "BTC Staking APR", value: "3.2%", tooltip: "Estimated APR" }),
|
|
78
|
+
_jsx(StatItem, { title: "Finality Providers", value: "24 Active (30 Total)" }),
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type JSX } from "react";
|
|
2
|
+
import { type ListItemProps } from "@/components/List";
|
|
3
|
+
export interface StatItemProps extends Omit<ListItemProps, "value" | "suffix"> {
|
|
4
|
+
hidden?: boolean;
|
|
5
|
+
loading?: boolean;
|
|
6
|
+
tooltip?: string | JSX.Element;
|
|
7
|
+
loadingStyle?: "spinner" | "spinner-and-value";
|
|
8
|
+
value: string | JSX.Element;
|
|
9
|
+
}
|
|
10
|
+
export declare const StatItem: ({ hidden, loading, title, value, tooltip, loadingStyle, ...props }: StatItemProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useId, useState } from "react";
|
|
3
|
+
import { AiOutlineInfoCircle } from "react-icons/ai";
|
|
4
|
+
import { Button } from "@/components/Button";
|
|
5
|
+
import { ListItem } from "@/components/List";
|
|
6
|
+
import { MobileDialog } from "@/components/Dialog";
|
|
7
|
+
import { useIsMobile } from "@/hooks";
|
|
8
|
+
import { Popover } from "@/components/Popover";
|
|
9
|
+
export const StatItem = ({ hidden = false, loading, title, value, tooltip, loadingStyle = "spinner", ...props }) => {
|
|
10
|
+
const tooltipId = useId();
|
|
11
|
+
const isMobileView = useIsMobile();
|
|
12
|
+
const [dialogOpen, setDialogOpen] = useState(false);
|
|
13
|
+
const [anchorEl, setAnchorEl] = useState(null);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!isMobileView && dialogOpen) {
|
|
16
|
+
setDialogOpen(false);
|
|
17
|
+
}
|
|
18
|
+
}, [isMobileView, dialogOpen]);
|
|
19
|
+
if (hidden)
|
|
20
|
+
return null;
|
|
21
|
+
const spinnerEl = (_jsxs("div", { className: "inline-flex items-center gap-2", children: [_jsx("span", { className: "loader size-5" }), loadingStyle === "spinner-and-value" && _jsx("span", { className: "opacity-50", children: value })] }));
|
|
22
|
+
const suffixEl = tooltip ? (isMobileView ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "block size-5 cursor-pointer text-xs", onClick: () => setDialogOpen(true), children: _jsx(AiOutlineInfoCircle, { size: 20 }) }), _jsxs(MobileDialog, { open: dialogOpen, onClose: () => setDialogOpen(false), children: [_jsx("div", { className: "px-4 py-2 text-accent-primary", children: tooltip }), _jsx("div", { className: "p-4", children: _jsx(Button, { variant: "contained", fluid: true, onClick: () => setDialogOpen(false), children: "Done" }) })] })] })) : (_jsxs(_Fragment, { children: [_jsx("span", { className: "block size-5 cursor-pointer text-xs", onMouseEnter: (e) => setAnchorEl(e.currentTarget), onMouseLeave: () => setAnchorEl(null), "aria-describedby": tooltipId, children: _jsx(AiOutlineInfoCircle, { size: 20 }) }), _jsx(Popover, { open: !!anchorEl, anchorEl: anchorEl, placement: "top", offset: [0, 8], children: _jsx("div", { className: "tooltip-wrap", children: tooltip }) })] }))) : undefined;
|
|
23
|
+
return (_jsx(ListItem, { ...props, title: title, value: loading ? spinnerEl : value, suffix: suffixEl }));
|
|
24
|
+
};
|
|
@@ -25,5 +25,5 @@ export const Menu = ({ children, trigger, open: controlledOpen, onOpenChange, pl
|
|
|
25
25
|
onClick: () => setIsOpen(!isOpen),
|
|
26
26
|
"aria-haspopup": "true",
|
|
27
27
|
"aria-expanded": isOpen,
|
|
28
|
-
}) }), isMobile ? (mobileMode === "dialog" ? (_jsx(MobileDialog, { open: isOpen, onClose: onClose, className: twJoin("
|
|
28
|
+
}) }), isMobile ? (mobileMode === "dialog" ? (_jsx(MobileDialog, { open: isOpen, onClose: onClose, className: twJoin("bg-[#FFFFFF] dark:bg-[#252525] text-primary-main", className), children: menuContent })) : (_jsx(MenuDrawer, { isOpen: isOpen, onClose: onClose, onBackdropClick: onClose, fullHeight: true, fullWidth: true, showBackButton: true, showDivider: false, children: menuContent }))) : (_jsx(Popover, { anchorEl: triggerRef.current, open: isOpen, offset: offset, placement: placement, onClickOutside: onClose, className: twJoin("rounded-lg border border-[#38708533] bg-[#FFFFFF] shadow-lg dark:border-[#404040] dark:bg-[#252525]", "min-w-[294px]", className), children: menuContent }))] }));
|
|
29
29
|
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { twJoin } from "tailwind-merge";
|
|
3
3
|
import { Portal } from "../Portal";
|
|
4
|
+
import { useDrawerAnimation } from "@/hooks/useDrawerAnimation";
|
|
4
5
|
export const MenuDrawer = ({ isOpen, onClose, title, children, className = "", titleAlign = "left", backIcon, fullHeight = false, fullWidth = false, showBackButton = true, showDivider = true, onBackdropClick, }) => {
|
|
6
|
+
const { mounted, shouldShowOpen, handleAnimationEnd } = useDrawerAnimation({ isOpen });
|
|
5
7
|
const titleAlignment = {
|
|
6
8
|
left: "text-left",
|
|
7
9
|
center: "text-center",
|
|
@@ -15,7 +17,7 @@ export const MenuDrawer = ({ isOpen, onClose, title, children, className = "", t
|
|
|
15
17
|
const renderContent = () => (_jsxs(_Fragment, { children: [renderHeader(), _jsx("div", { className: "flex-1 overflow-y-auto", children: children })] }));
|
|
16
18
|
// For fullHeight drawers (mobile), use Portal to ensure proper theme sync
|
|
17
19
|
if (fullHeight) {
|
|
18
|
-
return (_jsxs(Portal, { mounted:
|
|
20
|
+
return (_jsxs(Portal, { mounted: mounted, rootClassName: "menu-drawer-portal", children: [onBackdropClick && (_jsx("div", { className: twJoin("fixed inset-0 z-40 bg-black/50 transition-opacity duration-300", shouldShowOpen ? "opacity-100" : "pointer-events-none opacity-0"), onClick: onBackdropClick })), _jsx("div", { className: twJoin("transform transition-transform duration-300 ease-in-out", "bg-[#FFFFFF] dark:bg-[#252525]", "fixed inset-y-0 right-0 z-50", fullWidth ? "w-full" : "w-full max-w-sm", shouldShowOpen ? "translate-x-0" : "translate-x-full", className), onTransitionEnd: handleAnimationEnd, children: renderContent() })] }));
|
|
19
21
|
}
|
|
20
22
|
// For non-fullHeight drawers (desktop), render normally
|
|
21
23
|
return (_jsx("div", { className: twJoin("transform transition-transform duration-300 ease-in-out", "bg-[#FFFFFF] dark:bg-[#252525]", "absolute inset-0 rounded-lg", isOpen ? "translate-x-0" : "translate-x-full", className), children: renderContent() }));
|
|
@@ -12,5 +12,5 @@ export function Popover({ open = false, className, anchorEl, placement = "bottom
|
|
|
12
12
|
modifiers: [{ name: "offset", options: { offset } }],
|
|
13
13
|
});
|
|
14
14
|
useClickOutside([tooltipRef, anchorEl], onClickOutside, { enabled: open });
|
|
15
|
-
return (_jsx(Portal, { mounted: open, children: _jsx("div", { ref: setTooltipRef, style: { ...styles.popper, ...style }, className: twJoin("bbn-popover", className), children: children }) }));
|
|
15
|
+
return (_jsx(Portal, { mounted: open, rootClassName: "popover-portal", children: _jsx("div", { ref: setTooltipRef, style: { ...styles.popper, ...style, pointerEvents: 'auto' }, className: twJoin("bbn-popover", className), children: children }) }));
|
|
16
16
|
}
|
|
@@ -2,6 +2,10 @@ import { PropsWithChildren } from "react";
|
|
|
2
2
|
interface PortalProps {
|
|
3
3
|
mounted?: boolean;
|
|
4
4
|
rootClassName?: string;
|
|
5
|
+
/** Whether to inherit viewport dimensions and positioning */
|
|
6
|
+
inheritViewport?: boolean;
|
|
7
|
+
/** Pointer events behavior for the portal */
|
|
8
|
+
pointerEvents?: 'auto' | 'none';
|
|
5
9
|
}
|
|
6
|
-
export declare function Portal({ children, mounted, rootClassName }: PropsWithChildren<PortalProps>): import("react").ReactPortal | null;
|
|
10
|
+
export declare function Portal({ children, mounted, rootClassName, inheritViewport, pointerEvents }: PropsWithChildren<PortalProps>): import("react").ReactPortal | null;
|
|
7
11
|
export {};
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { useEffect, useState } from "react";
|
|
2
2
|
import { createPortal } from "react-dom";
|
|
3
|
-
|
|
3
|
+
import { useCoreUI } from "../../providers/CoreUIProvider";
|
|
4
|
+
export function Portal({ children, mounted = false, rootClassName = "portal-root", inheritViewport = true, pointerEvents = 'auto' }) {
|
|
4
5
|
const [rootRef, setRootRef] = useState(null);
|
|
6
|
+
const { portalContainer } = useCoreUI();
|
|
7
|
+
const shouldDisablePointerEvents = pointerEvents === 'none';
|
|
5
8
|
useEffect(() => {
|
|
6
9
|
if (!mounted) {
|
|
7
10
|
setRootRef(null);
|
|
@@ -9,37 +12,33 @@ export function Portal({ children, mounted = false, rootClassName = "portal-root
|
|
|
9
12
|
}
|
|
10
13
|
const root = document.createElement("div");
|
|
11
14
|
root.className = rootClassName;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
if (inheritViewport) {
|
|
16
|
+
if (!rootClassName.includes('popover')) {
|
|
17
|
+
const styles = {
|
|
18
|
+
position: "fixed",
|
|
19
|
+
top: "0",
|
|
20
|
+
left: "0",
|
|
21
|
+
width: "100vw",
|
|
22
|
+
height: "100vh",
|
|
23
|
+
zIndex: "9999",
|
|
24
|
+
pointerEvents: shouldDisablePointerEvents ? "none" : "auto"
|
|
25
|
+
};
|
|
26
|
+
Object.assign(root.style, styles);
|
|
23
27
|
}
|
|
24
28
|
else {
|
|
25
|
-
|
|
26
|
-
root.
|
|
29
|
+
// For popovers, just set z-index and pointer events
|
|
30
|
+
root.style.zIndex = "9999";
|
|
31
|
+
root.style.pointerEvents = shouldDisablePointerEvents ? "none" : "auto";
|
|
27
32
|
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
attributes: true,
|
|
33
|
-
attributeFilter: ["class", "data-mode"],
|
|
34
|
-
});
|
|
35
|
-
observer.observe(document.body, {
|
|
36
|
-
attributes: true,
|
|
37
|
-
attributeFilter: ["class", "data-mode"],
|
|
38
|
-
});
|
|
33
|
+
}
|
|
34
|
+
const container = portalContainer || document.body;
|
|
35
|
+
container.appendChild(root);
|
|
36
|
+
setRootRef(root);
|
|
39
37
|
return () => {
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
if (container.contains(root)) {
|
|
39
|
+
container.removeChild(root);
|
|
40
|
+
}
|
|
42
41
|
};
|
|
43
|
-
}, [mounted]);
|
|
42
|
+
}, [mounted, rootClassName, inheritViewport, shouldDisablePointerEvents, portalContainer]);
|
|
44
43
|
return rootRef ? createPortal(children, rootRef) : null;
|
|
45
44
|
}
|
package/dist/components/index.js
CHANGED
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { useCopy } from './useCopy';
|
|
2
2
|
export type { UseCopyReturn, UseCopyOptions } from './useCopy';
|
|
3
3
|
export { useIsMobile } from './useIsMobile';
|
|
4
|
+
export { useDrawerAnimation } from './useDrawerAnimation';
|
|
4
5
|
export { useClickOutside } from './useClickOutside';
|
|
5
6
|
export { useControlledState } from './useControlledState';
|
|
6
7
|
export { useMemoizedArray } from './useMemoizedArray';
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { useCopy } from './useCopy';
|
|
2
2
|
export { useIsMobile } from './useIsMobile';
|
|
3
|
+
export { useDrawerAnimation } from './useDrawerAnimation';
|
|
3
4
|
export { useClickOutside } from './useClickOutside';
|
|
4
5
|
export { useControlledState } from './useControlledState';
|
|
5
6
|
export { useMemoizedArray } from './useMemoizedArray';
|
package/dist/hooks/useCopy.js
CHANGED
|
@@ -1,45 +1,40 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
2
|
export function useCopy(options = {}) {
|
|
3
|
-
const { copiedText = 'Copied ✓', timeout = 2000 } = options;
|
|
3
|
+
const { copiedText: copiedLabel = 'Copied ✓', timeout = 2000 } = options;
|
|
4
4
|
const [copiedStates, setCopiedStates] = useState({});
|
|
5
|
-
const
|
|
6
|
-
const handleCopy = useCallback((id, value) => {
|
|
7
|
-
if (!id || !value)
|
|
8
|
-
return;
|
|
9
|
-
// Copy to clipboard using the native API
|
|
10
|
-
navigator.clipboard.writeText(value);
|
|
11
|
-
setCopiedStates((prev) => ({ ...prev, [id]: true }));
|
|
12
|
-
setCopiedTexts((prev) => ({ ...prev, [id]: copiedText }));
|
|
13
|
-
}, [copiedText]);
|
|
5
|
+
const timersRef = useRef({});
|
|
14
6
|
const reset = useCallback((id) => {
|
|
15
7
|
if (!id)
|
|
16
8
|
return;
|
|
17
9
|
setCopiedStates((prev) => ({ ...prev, [id]: false }));
|
|
18
|
-
setCopiedTexts((prev) => ({ ...prev, [id]: '' }));
|
|
19
10
|
}, []);
|
|
11
|
+
const handleCopy = useCallback((id, value) => {
|
|
12
|
+
if (!id || !value)
|
|
13
|
+
return;
|
|
14
|
+
void navigator.clipboard.writeText(value).catch(() => { });
|
|
15
|
+
setCopiedStates((prev) => ({ ...prev, [id]: true }));
|
|
16
|
+
const existing = timersRef.current[id];
|
|
17
|
+
if (existing)
|
|
18
|
+
clearTimeout(existing);
|
|
19
|
+
if (timeout > 0) {
|
|
20
|
+
timersRef.current[id] = setTimeout(() => {
|
|
21
|
+
timersRef.current[id] = undefined;
|
|
22
|
+
reset(id);
|
|
23
|
+
}, timeout);
|
|
24
|
+
}
|
|
25
|
+
}, [timeout, reset]);
|
|
20
26
|
const isCopied = useCallback((id) => {
|
|
21
27
|
if (!id)
|
|
22
28
|
return false;
|
|
23
29
|
return copiedStates[id] || false;
|
|
24
30
|
}, [copiedStates]);
|
|
25
|
-
const getText = useCallback((id) =>
|
|
26
|
-
if (!id)
|
|
27
|
-
return '';
|
|
28
|
-
return copiedTexts[id] || '';
|
|
29
|
-
}, [copiedTexts]);
|
|
31
|
+
const getText = useCallback((id) => (id && copiedStates[id] ? copiedLabel : ''), [copiedStates, copiedLabel]);
|
|
30
32
|
useEffect(() => {
|
|
31
|
-
const timers = {};
|
|
32
|
-
Object.entries(copiedStates).forEach(([id, copied]) => {
|
|
33
|
-
if (copied) {
|
|
34
|
-
timers[id] = setTimeout(() => {
|
|
35
|
-
reset(id);
|
|
36
|
-
}, timeout);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
33
|
return () => {
|
|
40
|
-
Object.values(
|
|
34
|
+
Object.values(timersRef.current).forEach((t) => t && clearTimeout(t));
|
|
35
|
+
timersRef.current = {};
|
|
41
36
|
};
|
|
42
|
-
}, [
|
|
37
|
+
}, []);
|
|
43
38
|
return {
|
|
44
39
|
isCopied,
|
|
45
40
|
copiedText: getText,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface UseDrawerAnimationOptions {
|
|
2
|
+
isOpen: boolean;
|
|
3
|
+
animationDuration?: number;
|
|
4
|
+
}
|
|
5
|
+
interface UseDrawerAnimationReturn {
|
|
6
|
+
/** Whether the Portal should be mounted */
|
|
7
|
+
mounted: boolean;
|
|
8
|
+
/** Whether the drawer should be in the "open" visual state */
|
|
9
|
+
shouldShowOpen: boolean;
|
|
10
|
+
/** Callback to trigger unmount after exit animation */
|
|
11
|
+
handleAnimationEnd: () => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Custom hook for managing drawer animations with proper timing
|
|
15
|
+
* Ensures Portal mounts → closed state → animate to open → animate to closed → unmount
|
|
16
|
+
*/
|
|
17
|
+
export declare function useDrawerAnimation({ isOpen, }: UseDrawerAnimationOptions): UseDrawerAnimationReturn;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useState, useEffect, useCallback } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Custom hook for managing drawer animations with proper timing
|
|
4
|
+
* Ensures Portal mounts → closed state → animate to open → animate to closed → unmount
|
|
5
|
+
*/
|
|
6
|
+
export function useDrawerAnimation({ isOpen, }) {
|
|
7
|
+
const [mounted, setMounted] = useState(false);
|
|
8
|
+
const [shouldShowOpen, setShouldShowOpen] = useState(false);
|
|
9
|
+
// Handle opening: mount → wait for DOM → trigger open animation
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (isOpen && !mounted) {
|
|
12
|
+
// Step 1: Mount the Portal
|
|
13
|
+
setMounted(true);
|
|
14
|
+
setShouldShowOpen(false);
|
|
15
|
+
// Step 2: Next frame, trigger the open animation
|
|
16
|
+
requestAnimationFrame(() => {
|
|
17
|
+
requestAnimationFrame(() => {
|
|
18
|
+
setShouldShowOpen(true);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}, [isOpen, mounted]);
|
|
23
|
+
// Handle closing: trigger close animation
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (!isOpen && mounted) {
|
|
26
|
+
setShouldShowOpen(false);
|
|
27
|
+
// Don't unmount here - wait for animation to complete
|
|
28
|
+
}
|
|
29
|
+
}, [isOpen, mounted]);
|
|
30
|
+
// Callback for when animation completes
|
|
31
|
+
const handleAnimationEnd = useCallback(() => {
|
|
32
|
+
if (!isOpen && mounted) {
|
|
33
|
+
// Animation finished and we're closing - unmount
|
|
34
|
+
setMounted(false);
|
|
35
|
+
}
|
|
36
|
+
}, [isOpen, mounted]);
|
|
37
|
+
return {
|
|
38
|
+
mounted,
|
|
39
|
+
shouldShowOpen,
|
|
40
|
+
handleAnimationEnd,
|
|
41
|
+
};
|
|
42
|
+
}
|