@windrun-huaiin/third-ui 11.0.6 → 11.0.7

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.
@@ -5,11 +5,11 @@ export interface GradientButtonProps {
5
5
  align?: 'left' | 'center' | 'right';
6
6
  disabled?: boolean;
7
7
  className?: string;
8
- iconSizeValue?: number;
8
+ iconClassName?: string;
9
9
  href?: string;
10
10
  openInNewTab?: boolean;
11
11
  onClick?: () => void | Promise<void>;
12
12
  loadingText?: React.ReactNode;
13
13
  preventDoubleClick?: boolean;
14
14
  }
15
- export declare function GradientButton({ title, icon, align, disabled, className, href, openInNewTab, onClick, loadingText, preventDoubleClick, iconSizeValue, }: GradientButtonProps): import("react/jsx-runtime").JSX.Element;
15
+ export declare function GradientButton({ title, icon, align, disabled, className, href, openInNewTab, onClick, loadingText, preventDoubleClick, iconClassName, }: GradientButtonProps): import("react/jsx-runtime").JSX.Element;
@@ -9,12 +9,11 @@ var server = require('@windrun-huaiin/base-ui/components/server');
9
9
  var Link = require('next/link');
10
10
  var React = require('react');
11
11
 
12
- function GradientButton({ title, icon, align = 'left', disabled = false, className = "", href, openInNewTab = true, onClick, loadingText, preventDoubleClick = true, iconSizeValue, }) {
12
+ function GradientButton({ title, icon, align = 'left', disabled = false, className = "", href, openInNewTab = true, onClick, loadingText, preventDoubleClick = true, iconClassName, }) {
13
13
  const [isLoading, setIsLoading] = React.useState(false);
14
14
  const actualLoadingText = loadingText || (title === null || title === void 0 ? void 0 : title.toString().trim()) || 'Loading...';
15
- const iconSizeClass = (iconSizeValue && Number.isInteger(iconSizeValue) && iconSizeValue > 0)
16
- ? `h-${iconSizeValue} w-${iconSizeValue}`
17
- : 'h-4 w-4';
15
+ const defaultIconClass = "h-4 w-4";
16
+ const finalIconClass = utils.cn("text-white", iconClassName || defaultIconClass);
18
17
  // set justify class according to alignment
19
18
  const getAlignmentClass = () => {
20
19
  switch (align) {
@@ -55,7 +54,7 @@ function GradientButton({ title, icon, align = 'left', disabled = false, classNa
55
54
  const iconProvided = icon !== undefined;
56
55
  const iconNode = (() => {
57
56
  if (isLoading) {
58
- return jsxRuntime.jsx(server.globalLucideIcons.Loader2, { className: utils.cn(iconSizeClass, 'text-white animate-spin') });
57
+ return jsxRuntime.jsx(server.globalLucideIcons.Loader2, { className: utils.cn(finalIconClass, 'animate-spin') });
59
58
  }
60
59
  if (iconProvided) {
61
60
  if (icon === null || icon === false) {
@@ -63,12 +62,12 @@ function GradientButton({ title, icon, align = 'left', disabled = false, classNa
63
62
  }
64
63
  if (React.isValidElement(icon)) {
65
64
  return React.cloneElement(icon, {
66
- className: utils.cn(iconSizeClass, 'text-white', icon.props.className),
65
+ className: utils.cn(finalIconClass, icon.props.className),
67
66
  });
68
67
  }
69
68
  return icon;
70
69
  }
71
- return jsxRuntime.jsx(server.globalLucideIcons.ArrowRight, { className: utils.cn(iconSizeClass, 'text-white') });
70
+ return jsxRuntime.jsx(server.globalLucideIcons.ArrowRight, { className: utils.cn(finalIconClass) });
72
71
  })();
73
72
  const shouldRenderIcon = iconNode !== null && iconNode !== undefined;
74
73
  const buttonContent = onClick ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [shouldRenderIcon ? jsxRuntime.jsx("span", { children: iconNode }) : null, jsxRuntime.jsx("span", { className: utils.cn(shouldRenderIcon && 'ml-1'), children: displayTitle })] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("span", { children: displayTitle }), shouldRenderIcon ? jsxRuntime.jsx("span", { className: "ml-1", children: iconNode }) : null] }));
@@ -7,12 +7,11 @@ import { globalLucideIcons } from '@windrun-huaiin/base-ui/components/server';
7
7
  import Link from 'next/link';
8
8
  import React, { useState } from 'react';
9
9
 
10
- function GradientButton({ title, icon, align = 'left', disabled = false, className = "", href, openInNewTab = true, onClick, loadingText, preventDoubleClick = true, iconSizeValue, }) {
10
+ function GradientButton({ title, icon, align = 'left', disabled = false, className = "", href, openInNewTab = true, onClick, loadingText, preventDoubleClick = true, iconClassName, }) {
11
11
  const [isLoading, setIsLoading] = useState(false);
12
12
  const actualLoadingText = loadingText || (title === null || title === void 0 ? void 0 : title.toString().trim()) || 'Loading...';
13
- const iconSizeClass = (iconSizeValue && Number.isInteger(iconSizeValue) && iconSizeValue > 0)
14
- ? `h-${iconSizeValue} w-${iconSizeValue}`
15
- : 'h-4 w-4';
13
+ const defaultIconClass = "h-4 w-4";
14
+ const finalIconClass = cn("text-white", iconClassName || defaultIconClass);
16
15
  // set justify class according to alignment
17
16
  const getAlignmentClass = () => {
18
17
  switch (align) {
@@ -53,7 +52,7 @@ function GradientButton({ title, icon, align = 'left', disabled = false, classNa
53
52
  const iconProvided = icon !== undefined;
54
53
  const iconNode = (() => {
55
54
  if (isLoading) {
56
- return jsx(globalLucideIcons.Loader2, { className: cn(iconSizeClass, 'text-white animate-spin') });
55
+ return jsx(globalLucideIcons.Loader2, { className: cn(finalIconClass, 'animate-spin') });
57
56
  }
58
57
  if (iconProvided) {
59
58
  if (icon === null || icon === false) {
@@ -61,12 +60,12 @@ function GradientButton({ title, icon, align = 'left', disabled = false, classNa
61
60
  }
62
61
  if (React.isValidElement(icon)) {
63
62
  return React.cloneElement(icon, {
64
- className: cn(iconSizeClass, 'text-white', icon.props.className),
63
+ className: cn(finalIconClass, icon.props.className),
65
64
  });
66
65
  }
67
66
  return icon;
68
67
  }
69
- return jsx(globalLucideIcons.ArrowRight, { className: cn(iconSizeClass, 'text-white') });
68
+ return jsx(globalLucideIcons.ArrowRight, { className: cn(finalIconClass) });
70
69
  })();
71
70
  const shouldRenderIcon = iconNode !== null && iconNode !== undefined;
72
71
  const buttonContent = onClick ? (jsxs(Fragment, { children: [shouldRenderIcon ? jsx("span", { children: iconNode }) : null, jsx("span", { className: cn(shouldRenderIcon && 'ml-1'), children: displayTitle })] })) : (jsxs(Fragment, { children: [jsx("span", { children: displayTitle }), shouldRenderIcon ? jsx("span", { className: "ml-1", children: iconNode }) : null] }));
@@ -18,7 +18,7 @@ interface SingleButtonProps {
18
18
  loadingText?: string;
19
19
  minWidth?: string;
20
20
  className?: string;
21
- iconSizeValue?: number;
21
+ iconClassName?: string;
22
22
  }
23
23
  interface SplitButtonProps {
24
24
  type: 'split';
@@ -29,7 +29,7 @@ interface SplitButtonProps {
29
29
  className?: string;
30
30
  mainButtonClassName?: string;
31
31
  dropdownButtonClassName?: string;
32
- iconSizeValue?: number;
32
+ iconClassName?: string;
33
33
  }
34
34
  type xButtonProps = SingleButtonProps | SplitButtonProps;
35
35
  export declare function XButton(props: xButtonProps): import("react/jsx-runtime").JSX.Element;
@@ -12,14 +12,19 @@ function XButton(props) {
12
12
  const [isLoading, setIsLoading] = React.useState(false);
13
13
  const [menuOpen, setMenuOpen] = React.useState(false);
14
14
  const menuRef = React.useRef(null);
15
- const { iconSizeValue } = props;
16
- const isCustomSize = iconSizeValue && Number.isInteger(iconSizeValue) && iconSizeValue > 0;
17
- const loadingIconClass = isCustomSize
18
- ? `w-${iconSizeValue} h-${iconSizeValue} mr-1 animate-spin`
19
- : "w-5 h-5 mr-1 animate-spin";
20
- const chevronIconClass = isCustomSize
21
- ? `w-${iconSizeValue + 1} h-${iconSizeValue + 1}`
22
- : "w-6 h-6";
15
+ const { iconClassName } = props;
16
+ const defaultIconClass = "w-5 h-5";
17
+ const finalIconClass = iconClassName || defaultIconClass;
18
+ const loadingIconClass = utils.cn(finalIconClass, "mr-1 animate-spin");
19
+ const chevronIconClass = "w-6 h-6";
20
+ const renderIcon = (icon) => {
21
+ if (React.isValidElement(icon)) {
22
+ return React.cloneElement(icon, {
23
+ className: utils.cn(finalIconClass, icon.props.className),
24
+ });
25
+ }
26
+ return icon;
27
+ };
23
28
  // click outside to close menu
24
29
  React.useEffect(() => {
25
30
  if (props.type === 'split') {
@@ -59,7 +64,7 @@ function XButton(props) {
59
64
  const isDisabled = button.disabled || isLoading;
60
65
  // loadingText: props.loadingText > button.text > 'Loading...'
61
66
  const actualLoadingText = loadingText || ((_a = button.text) === null || _a === void 0 ? void 0 : _a.trim()) || 'Loading...';
62
- return (jsxRuntime.jsx("button", { onClick: () => handleButtonClick(button.onClick), disabled: isDisabled, className: utils.cn("w-full sm:w-auto", minWidth, baseButtonClass, "rounded-full", isDisabled && disabledClass, className), title: button.text, children: isLoading ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(server.globalLucideIcons.Loader2, { className: loadingIconClass }), jsxRuntime.jsx("span", { children: actualLoadingText })] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [button.icon, jsxRuntime.jsx("span", { children: button.text })] })) }));
67
+ return (jsxRuntime.jsx("button", { onClick: () => handleButtonClick(button.onClick), disabled: isDisabled, className: utils.cn("w-full sm:w-auto", minWidth, baseButtonClass, "rounded-full", isDisabled && disabledClass, className), title: button.text, children: isLoading ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(server.globalLucideIcons.Loader2, { className: loadingIconClass }), jsxRuntime.jsx("span", { children: actualLoadingText })] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [renderIcon(button.icon), jsxRuntime.jsx("span", { children: button.text })] })) }));
63
68
  }
64
69
  // Split button
65
70
  const { mainButton, menuItems, loadingText, menuWidth = 'w-full sm:w-40', className = '', mainButtonClassName = '', dropdownButtonClassName = '' } = props;
@@ -67,7 +72,7 @@ function XButton(props) {
67
72
  // loadingText prioty:props.loadingText > mainButton.text > 'Loading...'
68
73
  const actualLoadingText = loadingText || ((_b = mainButton.text) === null || _b === void 0 ? void 0 : _b.trim()) || 'Loading...';
69
74
  return (jsxRuntime.jsxs("div", { className: utils.cn("relative flex flex-col sm:flex-row items-stretch w-full sm:w-auto bg-neutral-200 dark:bg-neutral-800 rounded-full gap-2 sm:gap-0", className), children: [jsxRuntime.jsx("button", { onClick: () => handleButtonClick(mainButton.onClick), disabled: isMainDisabled, className: utils.cn("flex-1 w-full", baseButtonClass, "rounded-full sm:rounded-l-full sm:rounded-r-none", isMainDisabled && disabledClass, mainButtonClassName), onMouseDown: e => { if (e.button === 2)
70
- e.preventDefault(); }, children: isLoading ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(server.globalLucideIcons.Loader2, { className: loadingIconClass }), jsxRuntime.jsx("span", { children: actualLoadingText })] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [mainButton.icon, jsxRuntime.jsx("span", { children: mainButton.text })] })) }), jsxRuntime.jsx("button", { type: "button", className: utils.cn("flex items-center justify-center w-full sm:w-10 py-1.5 bg-neutral-200 dark:bg-neutral-800 text-neutral-700 dark:text-white cursor-pointer transition hover:bg-neutral-300 dark:hover:bg-neutral-700 rounded-full sm:rounded-none sm:rounded-r-full sm:border-l sm:border-neutral-300 sm:dark:border-neutral-700", dropdownButtonClassName), onClick: e => { e.stopPropagation(); setMenuOpen(v => !v); }, "aria-label": "More actions", "aria-expanded": menuOpen, children: jsxRuntime.jsx(server.globalLucideIcons.ChevronDown, { className: chevronIconClass }) }), menuOpen && (jsxRuntime.jsx("div", { ref: menuRef, className: `absolute right-0 top-full ${menuWidth} bg-white dark:bg-neutral-800 text-neutral-800 dark:text-white text-sm rounded-xl shadow-lg z-50 border border-neutral-200 dark:border-neutral-700 overflow-hidden animate-fade-in`, children: menuItems.map((item, index) => (jsxRuntime.jsxs("button", { onClick: () => {
75
+ e.preventDefault(); }, children: isLoading ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(server.globalLucideIcons.Loader2, { className: loadingIconClass }), jsxRuntime.jsx("span", { children: actualLoadingText })] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [renderIcon(mainButton.icon), jsxRuntime.jsx("span", { children: mainButton.text })] })) }), jsxRuntime.jsx("button", { type: "button", className: utils.cn("flex items-center justify-center w-full sm:w-10 py-1.5 bg-neutral-200 dark:bg-neutral-800 text-neutral-700 dark:text-white cursor-pointer transition hover:bg-neutral-300 dark:hover:bg-neutral-700 rounded-full sm:rounded-none sm:rounded-r-full sm:border-l sm:border-neutral-300 sm:dark:border-neutral-700", dropdownButtonClassName), onClick: e => { e.stopPropagation(); setMenuOpen(v => !v); }, "aria-label": "More actions", "aria-expanded": menuOpen, children: jsxRuntime.jsx(server.globalLucideIcons.ChevronDown, { className: chevronIconClass }) }), menuOpen && (jsxRuntime.jsx("div", { ref: menuRef, className: `absolute right-0 top-full ${menuWidth} bg-white dark:bg-neutral-800 text-neutral-800 dark:text-white text-sm rounded-xl shadow-lg z-50 border border-neutral-200 dark:border-neutral-700 overflow-hidden animate-fade-in`, children: menuItems.map((item, index) => (jsxRuntime.jsxs("button", { onClick: () => {
71
76
  handleButtonClick(item.onClick);
72
77
  setMenuOpen(false);
73
78
  }, disabled: item.disabled, className: `flex items-center w-full px-4 py-3 transition hover:bg-neutral-300 dark:hover:bg-neutral-600 text-left relative ${item.disabled ? disabledClass : ''}`, style: item.splitTopBorder ? { borderTop: '1px solid #AC62FD' } : undefined, children: [jsxRuntime.jsxs("span", { className: "flex items-center", children: [item.icon, jsxRuntime.jsx("span", { children: item.text })] }), item.tag && (jsxRuntime.jsx("span", { className: "absolute right-3 top-1 text-[10px] font-semibold", style: { color: item.tag.color || '#A855F7', pointerEvents: 'none' }, children: item.tag.text }))] }, index))) }))] }));
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { __awaiter } from '../node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.mjs';
3
3
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
4
- import { useState, useRef, useEffect } from 'react';
4
+ import React, { useState, useRef, useEffect } from 'react';
5
5
  import { globalLucideIcons } from '@windrun-huaiin/base-ui/components/server';
6
6
  import { cn } from '@windrun-huaiin/lib/utils';
7
7
 
@@ -10,14 +10,19 @@ function XButton(props) {
10
10
  const [isLoading, setIsLoading] = useState(false);
11
11
  const [menuOpen, setMenuOpen] = useState(false);
12
12
  const menuRef = useRef(null);
13
- const { iconSizeValue } = props;
14
- const isCustomSize = iconSizeValue && Number.isInteger(iconSizeValue) && iconSizeValue > 0;
15
- const loadingIconClass = isCustomSize
16
- ? `w-${iconSizeValue} h-${iconSizeValue} mr-1 animate-spin`
17
- : "w-5 h-5 mr-1 animate-spin";
18
- const chevronIconClass = isCustomSize
19
- ? `w-${iconSizeValue + 1} h-${iconSizeValue + 1}`
20
- : "w-6 h-6";
13
+ const { iconClassName } = props;
14
+ const defaultIconClass = "w-5 h-5";
15
+ const finalIconClass = iconClassName || defaultIconClass;
16
+ const loadingIconClass = cn(finalIconClass, "mr-1 animate-spin");
17
+ const chevronIconClass = "w-6 h-6";
18
+ const renderIcon = (icon) => {
19
+ if (React.isValidElement(icon)) {
20
+ return React.cloneElement(icon, {
21
+ className: cn(finalIconClass, icon.props.className),
22
+ });
23
+ }
24
+ return icon;
25
+ };
21
26
  // click outside to close menu
22
27
  useEffect(() => {
23
28
  if (props.type === 'split') {
@@ -57,7 +62,7 @@ function XButton(props) {
57
62
  const isDisabled = button.disabled || isLoading;
58
63
  // loadingText: props.loadingText > button.text > 'Loading...'
59
64
  const actualLoadingText = loadingText || ((_a = button.text) === null || _a === void 0 ? void 0 : _a.trim()) || 'Loading...';
60
- return (jsx("button", { onClick: () => handleButtonClick(button.onClick), disabled: isDisabled, className: cn("w-full sm:w-auto", minWidth, baseButtonClass, "rounded-full", isDisabled && disabledClass, className), title: button.text, children: isLoading ? (jsxs(Fragment, { children: [jsx(globalLucideIcons.Loader2, { className: loadingIconClass }), jsx("span", { children: actualLoadingText })] })) : (jsxs(Fragment, { children: [button.icon, jsx("span", { children: button.text })] })) }));
65
+ return (jsx("button", { onClick: () => handleButtonClick(button.onClick), disabled: isDisabled, className: cn("w-full sm:w-auto", minWidth, baseButtonClass, "rounded-full", isDisabled && disabledClass, className), title: button.text, children: isLoading ? (jsxs(Fragment, { children: [jsx(globalLucideIcons.Loader2, { className: loadingIconClass }), jsx("span", { children: actualLoadingText })] })) : (jsxs(Fragment, { children: [renderIcon(button.icon), jsx("span", { children: button.text })] })) }));
61
66
  }
62
67
  // Split button
63
68
  const { mainButton, menuItems, loadingText, menuWidth = 'w-full sm:w-40', className = '', mainButtonClassName = '', dropdownButtonClassName = '' } = props;
@@ -65,7 +70,7 @@ function XButton(props) {
65
70
  // loadingText prioty:props.loadingText > mainButton.text > 'Loading...'
66
71
  const actualLoadingText = loadingText || ((_b = mainButton.text) === null || _b === void 0 ? void 0 : _b.trim()) || 'Loading...';
67
72
  return (jsxs("div", { className: cn("relative flex flex-col sm:flex-row items-stretch w-full sm:w-auto bg-neutral-200 dark:bg-neutral-800 rounded-full gap-2 sm:gap-0", className), children: [jsx("button", { onClick: () => handleButtonClick(mainButton.onClick), disabled: isMainDisabled, className: cn("flex-1 w-full", baseButtonClass, "rounded-full sm:rounded-l-full sm:rounded-r-none", isMainDisabled && disabledClass, mainButtonClassName), onMouseDown: e => { if (e.button === 2)
68
- e.preventDefault(); }, children: isLoading ? (jsxs(Fragment, { children: [jsx(globalLucideIcons.Loader2, { className: loadingIconClass }), jsx("span", { children: actualLoadingText })] })) : (jsxs(Fragment, { children: [mainButton.icon, jsx("span", { children: mainButton.text })] })) }), jsx("button", { type: "button", className: cn("flex items-center justify-center w-full sm:w-10 py-1.5 bg-neutral-200 dark:bg-neutral-800 text-neutral-700 dark:text-white cursor-pointer transition hover:bg-neutral-300 dark:hover:bg-neutral-700 rounded-full sm:rounded-none sm:rounded-r-full sm:border-l sm:border-neutral-300 sm:dark:border-neutral-700", dropdownButtonClassName), onClick: e => { e.stopPropagation(); setMenuOpen(v => !v); }, "aria-label": "More actions", "aria-expanded": menuOpen, children: jsx(globalLucideIcons.ChevronDown, { className: chevronIconClass }) }), menuOpen && (jsx("div", { ref: menuRef, className: `absolute right-0 top-full ${menuWidth} bg-white dark:bg-neutral-800 text-neutral-800 dark:text-white text-sm rounded-xl shadow-lg z-50 border border-neutral-200 dark:border-neutral-700 overflow-hidden animate-fade-in`, children: menuItems.map((item, index) => (jsxs("button", { onClick: () => {
73
+ e.preventDefault(); }, children: isLoading ? (jsxs(Fragment, { children: [jsx(globalLucideIcons.Loader2, { className: loadingIconClass }), jsx("span", { children: actualLoadingText })] })) : (jsxs(Fragment, { children: [renderIcon(mainButton.icon), jsx("span", { children: mainButton.text })] })) }), jsx("button", { type: "button", className: cn("flex items-center justify-center w-full sm:w-10 py-1.5 bg-neutral-200 dark:bg-neutral-800 text-neutral-700 dark:text-white cursor-pointer transition hover:bg-neutral-300 dark:hover:bg-neutral-700 rounded-full sm:rounded-none sm:rounded-r-full sm:border-l sm:border-neutral-300 sm:dark:border-neutral-700", dropdownButtonClassName), onClick: e => { e.stopPropagation(); setMenuOpen(v => !v); }, "aria-label": "More actions", "aria-expanded": menuOpen, children: jsx(globalLucideIcons.ChevronDown, { className: chevronIconClass }) }), menuOpen && (jsx("div", { ref: menuRef, className: `absolute right-0 top-full ${menuWidth} bg-white dark:bg-neutral-800 text-neutral-800 dark:text-white text-sm rounded-xl shadow-lg z-50 border border-neutral-200 dark:border-neutral-700 overflow-hidden animate-fade-in`, children: menuItems.map((item, index) => (jsxs("button", { onClick: () => {
69
74
  handleButtonClick(item.onClick);
70
75
  setMenuOpen(false);
71
76
  }, disabled: item.disabled, className: `flex items-center w-full px-4 py-3 transition hover:bg-neutral-300 dark:hover:bg-neutral-600 text-left relative ${item.disabled ? disabledClass : ''}`, style: item.splitTopBorder ? { borderTop: '1px solid #AC62FD' } : undefined, children: [jsxs("span", { className: "flex items-center", children: [item.icon, jsx("span", { children: item.text })] }), item.tag && (jsx("span", { className: "absolute right-3 top-1 text-[10px] font-semibold", style: { color: item.tag.color || '#A855F7', pointerEvents: 'none' }, children: item.tag.text }))] }, index))) }))] }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@windrun-huaiin/third-ui",
3
- "version": "11.0.6",
3
+ "version": "11.0.7",
4
4
  "description": "Third-party integrated UI components for windrun-huaiin projects",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -12,7 +12,7 @@ export interface GradientButtonProps {
12
12
  align?: 'left' | 'center' | 'right';
13
13
  disabled?: boolean;
14
14
  className?: string;
15
- iconSizeValue?: number;
15
+ iconClassName?: string;
16
16
  // for Link
17
17
  href?: string;
18
18
  openInNewTab?: boolean;
@@ -34,14 +34,13 @@ export function GradientButton({
34
34
  onClick,
35
35
  loadingText,
36
36
  preventDoubleClick = true,
37
- iconSizeValue,
37
+ iconClassName,
38
38
  }: GradientButtonProps) {
39
39
  const [isLoading, setIsLoading] = useState(false);
40
40
  const actualLoadingText = loadingText || title?.toString().trim() || 'Loading...'
41
41
 
42
- const iconSizeClass = (iconSizeValue && Number.isInteger(iconSizeValue) && iconSizeValue > 0)
43
- ? `h-${iconSizeValue} w-${iconSizeValue}`
44
- : 'h-4 w-4';
42
+ const defaultIconClass = "h-4 w-4";
43
+ const finalIconClass = cn("text-white", iconClassName || defaultIconClass);
45
44
 
46
45
  // set justify class according to alignment
47
46
  const getAlignmentClass = () => {
@@ -89,7 +88,7 @@ export function GradientButton({
89
88
 
90
89
  const iconNode = (() => {
91
90
  if (isLoading) {
92
- return <icons.Loader2 className={cn(iconSizeClass, 'text-white animate-spin')} />;
91
+ return <icons.Loader2 className={cn(finalIconClass, 'animate-spin')} />;
93
92
  }
94
93
 
95
94
  if (iconProvided) {
@@ -99,14 +98,14 @@ export function GradientButton({
99
98
 
100
99
  if (React.isValidElement<{ className?: string }>(icon)) {
101
100
  return React.cloneElement(icon, {
102
- className: cn(iconSizeClass, 'text-white', icon.props.className),
101
+ className: cn(finalIconClass, icon.props.className),
103
102
  });
104
103
  }
105
104
 
106
105
  return icon;
107
106
  }
108
107
 
109
- return <icons.ArrowRight className={cn(iconSizeClass, 'text-white')} />;
108
+ return <icons.ArrowRight className={cn(finalIconClass)} />;
110
109
  })();
111
110
 
112
111
  const shouldRenderIcon = iconNode !== null && iconNode !== undefined;
@@ -1,6 +1,6 @@
1
1
  'use client'
2
2
 
3
- import { useState, useRef, useEffect, ReactNode } from 'react'
3
+ import React, { useState, useRef, useEffect, ReactNode } from 'react'
4
4
  import { globalLucideIcons as icons } from '@windrun-huaiin/base-ui/components/server'
5
5
  import { cn } from '@windrun-huaiin/lib/utils'
6
6
 
@@ -28,7 +28,7 @@ interface SingleButtonProps {
28
28
  loadingText?: string
29
29
  minWidth?: string
30
30
  className?: string
31
- iconSizeValue?: number
31
+ iconClassName?: string
32
32
  }
33
33
 
34
34
  // split button config
@@ -41,7 +41,7 @@ interface SplitButtonProps {
41
41
  className?: string
42
42
  mainButtonClassName?: string
43
43
  dropdownButtonClassName?: string
44
- iconSizeValue?: number
44
+ iconClassName?: string
45
45
  }
46
46
 
47
47
  type xButtonProps = SingleButtonProps | SplitButtonProps
@@ -51,16 +51,22 @@ export function XButton(props: xButtonProps) {
51
51
  const [menuOpen, setMenuOpen] = useState(false)
52
52
  const menuRef = useRef<HTMLDivElement>(null)
53
53
 
54
- const { iconSizeValue } = props
55
- const isCustomSize = iconSizeValue && Number.isInteger(iconSizeValue) && iconSizeValue > 0
54
+ const { iconClassName } = props
55
+ const defaultIconClass = "w-5 h-5"
56
+ const finalIconClass = iconClassName || defaultIconClass
56
57
 
57
- const loadingIconClass = isCustomSize
58
- ? `w-${iconSizeValue} h-${iconSizeValue} mr-1 animate-spin`
59
- : "w-5 h-5 mr-1 animate-spin"
58
+ const loadingIconClass = cn(finalIconClass, "mr-1 animate-spin")
60
59
 
61
- const chevronIconClass = isCustomSize
62
- ? `w-${iconSizeValue + 1} h-${iconSizeValue + 1}`
63
- : "w-6 h-6"
60
+ const chevronIconClass = "w-6 h-6"
61
+
62
+ const renderIcon = (icon: ReactNode) => {
63
+ if (React.isValidElement<{ className?: string }>(icon)) {
64
+ return React.cloneElement(icon, {
65
+ className: cn(finalIconClass, icon.props.className),
66
+ });
67
+ }
68
+ return icon;
69
+ };
64
70
 
65
71
  // click outside to close menu
66
72
  useEffect(() => {
@@ -126,7 +132,7 @@ export function XButton(props: xButtonProps) {
126
132
  </>
127
133
  ) : (
128
134
  <>
129
- {button.icon}
135
+ {renderIcon(button.icon)}
130
136
  <span>{button.text}</span>
131
137
  </>
132
138
  )}
@@ -165,7 +171,7 @@ export function XButton(props: xButtonProps) {
165
171
  </>
166
172
  ) : (
167
173
  <>
168
- {mainButton.icon}
174
+ {renderIcon(mainButton.icon)}
169
175
  <span>{mainButton.text}</span>
170
176
  </>
171
177
  )}