feat(button): enhance button component to conditionally render children

- 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.
This commit is contained in:
moxi
2026-01-04 01:12:48 +08:00
parent 6364bac1f2
commit e914337e57

View File

@@ -20,6 +20,7 @@ export function Button({
disabled,
...rest
}: PropsWithChildren<ButtonProps>) {
const hasChildren = children !== null && children !== undefined && children !== false;
const classes = [
'btn',
`btn-${variant}`,
@@ -33,7 +34,7 @@ export function Button({
return (
<button className={classes} disabled={disabled || loading} {...rest}>
{loading && <span className="loading-spinner" aria-hidden="true" />}
<span>{children}</span>
{hasChildren && <span>{children}</span>}
</button>
);
}