2022-11-18 05:11:52 -08:00
|
|
|
import { MouseEventHandler, ReactNode } from "react";
|
|
|
|
|
|
|
|
export enum ButtonStyle {
|
|
|
|
primary,
|
|
|
|
success,
|
|
|
|
danger,
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface Props {
|
|
|
|
onClick?: MouseEventHandler<HTMLButtonElement>;
|
|
|
|
style?: ButtonStyle;
|
|
|
|
bold?: boolean;
|
2023-01-02 15:07:10 -08:00
|
|
|
disabled?: boolean;
|
2022-11-20 07:54:25 -08:00
|
|
|
noRound?: boolean;
|
2022-11-18 05:11:52 -08:00
|
|
|
children?: ReactNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function Button(props: Props) {
|
|
|
|
if (props.style === undefined) {
|
|
|
|
return PrimaryButton(props);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (props.style) {
|
|
|
|
case ButtonStyle.primary:
|
|
|
|
return PrimaryButton(props);
|
|
|
|
case ButtonStyle.success:
|
|
|
|
return SuccessButton(props);
|
|
|
|
case ButtonStyle.danger:
|
|
|
|
return DangerButton(props);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function PrimaryButton(props: Props) {
|
|
|
|
return (
|
|
|
|
<button
|
|
|
|
type="button"
|
2023-01-02 15:07:10 -08:00
|
|
|
disabled={props.disabled}
|
2022-11-18 05:11:52 -08:00
|
|
|
onClick={props.onClick}
|
2022-11-20 07:54:25 -08:00
|
|
|
className={`bg-blue-500 dark:bg-blue-500 hover:bg-blue-700 hover:dark:bg-blue-800 p-2 ${
|
|
|
|
!props.noRound && "rounded-md"
|
2023-01-02 15:07:10 -08:00
|
|
|
} ${props.disabled && "cursor-not-allowed"} text-white`}
|
2022-11-18 05:11:52 -08:00
|
|
|
>
|
|
|
|
<span className={props.bold ? "font-bold" : ""}>{props.children}</span>
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function SuccessButton(props: Props) {
|
|
|
|
return (
|
|
|
|
<button
|
|
|
|
type="button"
|
2023-01-02 15:07:10 -08:00
|
|
|
disabled={props.disabled}
|
2022-11-18 05:11:52 -08:00
|
|
|
onClick={props.onClick}
|
2022-11-20 07:54:25 -08:00
|
|
|
className={`bg-green-600 dark:bg-green-700 hover:bg-green-700 hover:dark:bg-green-800 p-2 ${
|
|
|
|
!props.noRound && "rounded-md"
|
2023-01-02 15:07:10 -08:00
|
|
|
} ${props.disabled && "cursor-not-allowed"} text-white`}
|
2022-11-18 05:11:52 -08:00
|
|
|
>
|
|
|
|
<span className={props.bold ? "font-bold" : ""}>{props.children}</span>
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function DangerButton(props: Props) {
|
|
|
|
return (
|
|
|
|
<button
|
|
|
|
type="button"
|
2023-01-02 15:07:10 -08:00
|
|
|
disabled={props.disabled}
|
2022-11-18 05:11:52 -08:00
|
|
|
onClick={props.onClick}
|
2022-11-20 07:54:25 -08:00
|
|
|
className={`bg-red-600 dark:bg-red-700 hover:bg-red-700 hover:dark:bg-red-800 p-2 ${
|
|
|
|
!props.noRound && "rounded-md"
|
2023-01-02 15:07:10 -08:00
|
|
|
} ${props.disabled && "cursor-not-allowed"} text-white`}
|
2022-11-18 05:11:52 -08:00
|
|
|
>
|
|
|
|
<span className={props.bold ? "font-bold" : ""}>{props.children}</span>
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|