waveterm/frontend/app/element/button.tsx

29 lines
740 B
TypeScript
Raw Normal View History

2024-06-18 06:50:33 +02:00
import clsx from "clsx";
import React from "react";
import "./button.less";
2024-06-18 06:50:33 +02:00
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
className?: string;
}
2024-06-26 18:31:43 +02:00
const Button: React.FC<ButtonProps> = React.memo(({ className = "primary", children, disabled, ...props }) => {
2024-06-18 06:50:33 +02:00
const hasIcon = React.Children.toArray(children).some(
(child) => React.isValidElement(child) && (child as React.ReactElement).type === "svg"
);
return (
<button
className={clsx("button", className, {
disabled,
hasIcon,
})}
disabled={disabled}
{...props}
>
{children}
</button>
);
2024-06-26 18:31:43 +02:00
});
export { Button };