@babylonlabs-io/core-ui 1.29.1 → 1.31.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/Icons/common/ThemeIcon.d.ts +2 -0
- package/dist/components/Icons/common/ThemeIcon.js +7 -0
- package/dist/components/Icons/index.d.ts +1 -0
- package/dist/components/Icons/index.js +1 -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/MenuItem.d.ts +14 -0
- package/dist/components/Menu/MenuItem.js +14 -7
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +2 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +1884 -1795
- package/dist/index.es.js.map +1 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/widgets/sections/SettingMenu/SettingMenu.stories.d.ts +1 -0
- package/dist/widgets/sections/SettingMenu/SettingMenu.stories.js +15 -1
- package/dist/widgets/sections/SettingMenu/components/SettingMenuItem.d.ts +15 -0
- package/dist/widgets/sections/SettingMenu/components/SettingMenuItem.js +3 -3
- package/package.json +1 -1
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { iconColorVariants } from "../index";
|
|
3
|
+
import { twJoin } from "tailwind-merge";
|
|
4
|
+
export const ThemeIcon = ({ className = "", size = 40, variant = "default", color, }) => {
|
|
5
|
+
const colorClass = color || iconColorVariants[variant];
|
|
6
|
+
return (_jsxs("svg", { style: { width: size, height: size }, viewBox: "0 0 40 40", fill: "none", xmlns: "http://www.w3.org/2000/svg", className: twJoin("transition-opacity duration-200", className), children: [_jsx("rect", { width: "40", height: "40", rx: "20", fill: "currentColor", fillOpacity: "0.12" }), _jsx("path", { d: "M20 30C25.52 30 30 25.52 30 20C30 14.48 25.52 10 20 10C14.48 10 10 14.48 10 20C10 25.52 14.48 30 20 30ZM21 12.07C24.94 12.56 28 15.92 28 20C28 24.08 24.95 27.44 21 27.93V12.07Z", fill: "currentColor", className: colorClass })] }));
|
|
7
|
+
};
|
|
@@ -26,3 +26,4 @@ export { CollapseIcon } from "./common/CollapseIcon";
|
|
|
26
26
|
export { OpenIcon } from "./common/OpenIcon";
|
|
27
27
|
export { ChevronLeftIcon } from "./common/ChevronLeftIcon";
|
|
28
28
|
export { BugReportIcon } from "./common/BugReportIcon";
|
|
29
|
+
export { ThemeIcon } from "./common/ThemeIcon";
|
|
@@ -21,3 +21,4 @@ export { CollapseIcon } from "./common/CollapseIcon";
|
|
|
21
21
|
export { OpenIcon } from "./common/OpenIcon";
|
|
22
22
|
export { ChevronLeftIcon } from "./common/ChevronLeftIcon";
|
|
23
23
|
export { BugReportIcon } from "./common/BugReportIcon";
|
|
24
|
+
export { ThemeIcon } from "./common/ThemeIcon";
|
|
@@ -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
|
+
};
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
interface MenuItemToggleProps {
|
|
3
|
+
/** Current toggle value */
|
|
4
|
+
value?: boolean;
|
|
5
|
+
/** Default toggle value */
|
|
6
|
+
defaultValue?: boolean;
|
|
7
|
+
/** Toggle change handler */
|
|
8
|
+
onChange?: (value: boolean) => void;
|
|
9
|
+
/** Icon to show when toggle is active */
|
|
10
|
+
activeIcon?: React.ReactNode;
|
|
11
|
+
/** Icon to show when toggle is inactive */
|
|
12
|
+
inactiveIcon?: React.ReactNode;
|
|
13
|
+
}
|
|
2
14
|
interface MenuItemProps {
|
|
3
15
|
/** Leading icon or element */
|
|
4
16
|
icon?: React.ReactNode;
|
|
@@ -20,6 +32,8 @@ interface MenuItemProps {
|
|
|
20
32
|
selected?: boolean;
|
|
21
33
|
/** Role attribute for accessibility */
|
|
22
34
|
role?: string;
|
|
35
|
+
/** Toggle configuration - when provided, renders a toggle switch as suffix */
|
|
36
|
+
toggle?: MenuItemToggleProps;
|
|
23
37
|
}
|
|
24
38
|
export declare const MenuItem: React.FC<MenuItemProps>;
|
|
25
39
|
export {};
|
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { twJoin } from "tailwind-merge";
|
|
3
3
|
import { useMenuContext } from "./MenuContext";
|
|
4
|
-
|
|
4
|
+
import { Toggle } from "../Toggle/Toggle";
|
|
5
|
+
export const MenuItem = ({ icon, name, description, onClick, disabled = false, className, children, suffix, selected = false, role = "menuitem", toggle, }) => {
|
|
5
6
|
const menuContext = useMenuContext();
|
|
7
|
+
const toggleElement = toggle ? (_jsx(Toggle, { value: toggle.value, defaultValue: toggle.defaultValue, onChange: toggle.onChange })) : null;
|
|
8
|
+
const finalSuffix = toggleElement || suffix;
|
|
6
9
|
const handleClick = () => {
|
|
7
|
-
if (disabled
|
|
10
|
+
if (disabled)
|
|
8
11
|
return;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (
|
|
12
|
+
if (toggleElement)
|
|
13
|
+
return;
|
|
14
|
+
if (onClick) {
|
|
15
|
+
onClick();
|
|
16
|
+
}
|
|
17
|
+
if (menuContext && !finalSuffix) {
|
|
12
18
|
menuContext.onClose();
|
|
13
19
|
}
|
|
14
20
|
};
|
|
15
|
-
// If children are provided, render them instead of the default layout
|
|
16
21
|
if (children) {
|
|
17
22
|
return (_jsx("button", { onClick: handleClick, disabled: disabled, className: twJoin("w-full text-left", disabled && "cursor-not-allowed opacity-50", className), children: children }));
|
|
18
23
|
}
|
|
19
|
-
return (_jsxs("
|
|
24
|
+
return (_jsxs("div", { className: twJoin("flex w-full items-center justify-between p-6", "transition-colors", !toggleElement && "cursor-pointer hover:bg-accent-secondary/5", // Only hover if no toggle
|
|
25
|
+
"text-left", selected && "bg-accent-secondary/10", disabled && "cursor-not-allowed opacity-50", toggleElement && "cursor-default", // Disable pointer cursor when toggle is present
|
|
26
|
+
className), role: role, "aria-selected": selected, onClick: handleClick, children: [_jsxs("div", { className: "flex items-center gap-3", children: [icon && _jsx("div", { className: "flex-shrink-0", children: icon }), _jsxs("div", { className: "flex flex-col", children: [_jsx("div", { className: "text-sm font-medium text-accent-primary", children: name }), description && _jsx("div", { className: "text-xs text-accent-secondary", children: description })] })] }), finalSuffix && (_jsx("div", { className: "flex-shrink-0", children: finalSuffix }))] }));
|
|
20
27
|
};
|