mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-03 03:10:50 +08:00
- Added a check to determine if children are present before rendering them in the button. - Improved button rendering logic for better handling of empty or false children values.
41 lines
1023 B
TypeScript
41 lines
1023 B
TypeScript
import type { ButtonHTMLAttributes, PropsWithChildren } from 'react';
|
|
|
|
type ButtonVariant = 'primary' | 'secondary' | 'ghost' | 'danger';
|
|
type ButtonSize = 'md' | 'sm';
|
|
|
|
interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
variant?: ButtonVariant;
|
|
size?: ButtonSize;
|
|
fullWidth?: boolean;
|
|
loading?: boolean;
|
|
}
|
|
|
|
export function Button({
|
|
children,
|
|
variant = 'primary',
|
|
size = 'md',
|
|
fullWidth = false,
|
|
loading = false,
|
|
className = '',
|
|
disabled,
|
|
...rest
|
|
}: PropsWithChildren<ButtonProps>) {
|
|
const hasChildren = children !== null && children !== undefined && children !== false;
|
|
const classes = [
|
|
'btn',
|
|
`btn-${variant}`,
|
|
size === 'sm' ? 'btn-sm' : '',
|
|
fullWidth ? 'btn-full' : '',
|
|
className
|
|
]
|
|
.filter(Boolean)
|
|
.join(' ');
|
|
|
|
return (
|
|
<button className={classes} disabled={disabled || loading} {...rest}>
|
|
{loading && <span className="loading-spinner" aria-hidden="true" />}
|
|
{hasChildren && <span>{children}</span>}
|
|
</button>
|
|
);
|
|
}
|