2024-08-21 02:01:29 +02:00
|
|
|
// 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";
|
2024-05-15 01:53:03 +02:00
|
|
|
import "./button.less";
|
|
|
|
|
2024-06-18 06:50:33 +02:00
|
|
|
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
2024-08-07 01:48:25 +02:00
|
|
|
forwardedRef?: React.RefObject<HTMLButtonElement>;
|
2024-05-15 01:53:03 +02:00
|
|
|
className?: string;
|
2024-07-18 08:41:33 +02:00
|
|
|
children?: React.ReactNode;
|
2024-05-15 01:53:03 +02:00
|
|
|
}
|
|
|
|
|
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-08-20 00:49:40 +02:00
|
|
|
<div className="button">
|
|
|
|
<button
|
|
|
|
className={clsx("button-inner", className, {
|
|
|
|
disabled,
|
|
|
|
hasIcon,
|
|
|
|
})}
|
|
|
|
disabled={disabled}
|
|
|
|
{...props}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</button>
|
|
|
|
</div>
|
2024-06-18 06:50:33 +02:00
|
|
|
);
|
2024-06-26 18:31:43 +02:00
|
|
|
});
|
2024-05-15 01:53:03 +02:00
|
|
|
|
|
|
|
export { Button };
|