waveterm/frontend/app/element/button.tsx

35 lines
935 B
TypeScript
Raw Normal View History

// Copyright 2024, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0
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> {
forwardedRef?: React.RefObject<HTMLButtonElement>;
className?: string;
2024-07-18 08:41:33 +02:00
children?: React.ReactNode;
}
2024-07-18 08:41:33 +02:00
const Button = React.memo(({ className = "primary", children, disabled, ...props }: ButtonProps) => {
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 (
2024-09-13 07:22:31 +02:00
<button
tabIndex={disabled ? -1 : 0}
className={clsx("button", className, {
disabled,
hasIcon,
})}
disabled={disabled}
{...props}
>
{children}
</button>
2024-06-18 06:50:33 +02:00
);
2024-06-26 18:31:43 +02:00
});
export { Button };