@babylonlabs-io/core-ui 1.30.0 → 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.
@@ -3,3 +3,4 @@ import { SettingMenu } from "./SettingMenu";
3
3
  declare const _default: Meta<typeof SettingMenu>;
4
4
  export default _default;
5
5
  export declare const Default: StoryFn;
6
+ export declare const WithThemeToggle: StoryFn;
@@ -1,8 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useState } from "react";
3
+ import { FaSun, FaMoon } from "react-icons/fa";
3
4
  import { SettingMenu } from "./SettingMenu";
4
5
  import { Button } from "@/components/Button";
5
6
  import { useIsMobile } from "@/hooks/useIsMobile";
7
+ import { ThemeIcon } from "@/components/Icons";
6
8
  export default {
7
9
  title: "Widgets/sections/SettingMenu",
8
10
  component: SettingMenu,
@@ -11,7 +13,6 @@ export default {
11
13
  },
12
14
  tags: ["autodocs"],
13
15
  };
14
- const ThemeIcon = () => (_jsxs("svg", { width: "40", height: "40", viewBox: "0 0 40 40", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [_jsx("rect", { width: "40", height: "40", rx: "20", fill: "#387085", 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: "#387085" })] }));
15
16
  const ReportABugIcon = () => (_jsxs("svg", { width: "40", height: "40", viewBox: "0 0 40 40", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [_jsx("rect", { width: "40", height: "40", rx: "20", fill: "#387085", fillOpacity: "0.12" }), _jsx("path", { d: "M23.73 11H16.27L11 16.27V23.73L16.27 29H23.73L29 23.73V16.27L23.73 11ZM20 25.3C19.28 25.3 18.7 24.72 18.7 24C18.7 23.28 19.28 22.7 20 22.7C20.72 22.7 21.3 23.28 21.3 24C21.3 24.72 20.72 25.3 20 25.3ZM21 21H19V15H21V21Z", fill: "#387085" })] }));
16
17
  export const Default = () => {
17
18
  const [selectedTheme, setSelectedTheme] = useState("auto");
@@ -33,3 +34,16 @@ export const Default = () => {
33
34
  };
34
35
  return (_jsx("div", { className: "p-4", children: _jsxs(SettingMenu, { children: [_jsx(SettingMenu.Title, { children: "Settings" }), _jsxs(SettingMenu.Group, { background: "secondary", children: [_jsxs(SettingMenu.SubMenu, { icon: _jsx(ThemeIcon, {}), children: ["Theme", _jsx(SettingMenu.Description, { children: getThemeDescription() }), _jsx(SettingMenu.Item, { selected: selectedTheme === "light", onClick: () => handleThemeChange("light"), children: "Light" }), _jsx(SettingMenu.Item, { selected: selectedTheme === "dark", onClick: () => handleThemeChange("dark"), children: "Dark" }), _jsx(SettingMenu.Item, { selected: selectedTheme === "auto", onClick: () => handleThemeChange("auto"), children: "Auto" })] }), _jsx(SettingMenu.Item, { icon: _jsx(ReportABugIcon, {}), onClick: () => console.log("Report bug clicked"), children: "Report a Bug" })] }), isMobile && _jsx(SettingMenu.Spacer, {}), _jsxs(SettingMenu.Group, { background: "secondary", children: [_jsx(SettingMenu.Item, { onClick: () => window.open("https://example.com/terms", "_blank"), children: "Terms of Use" }), _jsx(SettingMenu.Item, { onClick: () => window.open("https://example.com/privacy", "_blank"), children: "Privacy Policy" })] }), _jsx(SettingMenu.Spacer, {}), _jsx(SettingMenu.CustomContent, { className: "my-4 flex justify-center", children: _jsx(Button, { className: "!bg-[#D5FCE8] !text-black", variant: "contained", children: "Switch to BABY Staking" }) })] }) }));
35
36
  };
37
+ export const WithThemeToggle = () => {
38
+ const [isLightMode, setIsLightMode] = useState(false);
39
+ const isMobile = useIsMobile();
40
+ return (_jsx("div", { className: "p-4", children: _jsxs(SettingMenu, { children: [_jsx(SettingMenu.Title, { children: "Settings" }), _jsxs(SettingMenu.Group, { background: "secondary", children: [_jsxs(SettingMenu.Item, { icon: _jsx(ThemeIcon, {}), toggle: {
41
+ value: isLightMode,
42
+ onChange: (value) => {
43
+ setIsLightMode(value);
44
+ console.log("Theme changed to:", value ? "Light" : "Dark");
45
+ },
46
+ activeIcon: _jsx(FaSun, { size: 10 }),
47
+ inactiveIcon: _jsx(FaMoon, { size: 10 })
48
+ }, children: ["Theme", _jsx(SettingMenu.Description, { children: "Light mode" })] }), _jsx(SettingMenu.Item, { icon: _jsx(ReportABugIcon, {}), onClick: () => console.log("Report bug clicked"), children: "Report a Bug" })] }), isMobile && _jsx(SettingMenu.Spacer, {}), _jsxs(SettingMenu.Group, { background: "secondary", children: [_jsx(SettingMenu.Item, { onClick: () => window.open("https://example.com/terms", "_blank"), children: "Terms of Use" }), _jsx(SettingMenu.Item, { onClick: () => window.open("https://example.com/privacy", "_blank"), children: "Privacy Policy" })] }), _jsx(SettingMenu.Spacer, {}), _jsx(SettingMenu.CustomContent, { className: "my-4 flex justify-center", children: _jsx(Button, { className: "!bg-[#D5FCE8] !text-black", variant: "contained", children: "Switch to BABY Staking" }) })] }) }));
49
+ };
@@ -1,4 +1,16 @@
1
1
  import React, { ReactNode } from "react";
2
+ interface SettingMenuItemToggleProps {
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
  export interface SettingMenuItemProps {
3
15
  /** Icon element */
4
16
  icon?: ReactNode;
@@ -12,7 +24,10 @@ export interface SettingMenuItemProps {
12
24
  selected?: boolean;
13
25
  /** Additional CSS classes */
14
26
  className?: string;
27
+ /** Toggle configuration - when provided, renders a toggle switch as suffix */
28
+ toggle?: SettingMenuItemToggleProps;
15
29
  /** Children (label and description) */
16
30
  children: ReactNode;
17
31
  }
18
32
  export declare const SettingMenuItem: React.FC<SettingMenuItemProps>;
33
+ export {};
@@ -3,11 +3,11 @@ import React from "react";
3
3
  import { MenuItem } from "@/components/Menu/MenuItem";
4
4
  import { ChevronRightIcon } from "@/elements/Icons";
5
5
  import { SettingMenuDescription } from "./SettingMenuDescription";
6
- export const SettingMenuItem = ({ icon, suffix, onClick, disabled = false, selected = false, className = "", children, }) => {
6
+ export const SettingMenuItem = ({ icon, suffix, onClick, disabled = false, selected = false, className = "", toggle, children, }) => {
7
7
  const childrenArray = React.Children.toArray(children);
8
8
  const label = childrenArray.find((child) => typeof child === "string" || (React.isValidElement(child) && child.type !== SettingMenuDescription));
9
9
  const description = childrenArray.find((child) => React.isValidElement(child) && child.type === SettingMenuDescription);
10
10
  const labelText = typeof label === "string" ? label : "";
11
- const defaultSuffix = onClick ? _jsx(ChevronRightIcon, {}) : undefined;
12
- return (_jsx(MenuItem, { icon: icon, name: labelText, description: description ? description.props.children : undefined, onClick: onClick, disabled: disabled, selected: selected, className: className, suffix: suffix || defaultSuffix }));
11
+ const defaultSuffix = onClick && !toggle ? _jsx(ChevronRightIcon, {}) : undefined;
12
+ return (_jsx(MenuItem, { icon: icon, name: labelText, description: description ? description.props.children : undefined, onClick: onClick, disabled: disabled, selected: selected, className: className, suffix: suffix || defaultSuffix, toggle: toggle }));
13
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babylonlabs-io/core-ui",
3
- "version": "1.30.0",
3
+ "version": "1.31.0",
4
4
  "type": "module",
5
5
  "types": "dist/index.d.ts",
6
6
  "publishConfig": {