Files
2026-04-01 15:52:53 -07:00

188 lines
6.3 KiB
TypeScript

import React, { ReactNode } from "react";
import { classNames } from "../../functions";
const SIZE = {
xs: "px-2 py-1 text-xs",
sm: "px-4 py-2 text-base",
default: "px-4 py-3 text-base",
lg: "px-6 py-4 text-base",
none: "p-0 text-base",
};
const FILLED = {
default: "bg-transparent opacity-80 hover:opacity-100",
red: "bg-red bg-opacity-80 w-full rounded text-high-emphesis hover:bg-opacity-100 disabled:bg-opacity-80",
blue: "bg-blue bg-opacity-80 w-full rounded text-high-emphesis hover:bg-opacity-100 disabled:bg-opacity-80",
indigo: "bg-blue bg-opacity-80 w-full rounded text-high-emphesis hover:bg-opacity-100 disabled:bg-opacity-80",
pink: "bg-gradient-to-r from-pink to-opaque-pink w-full rounded text-high-emphesis opacity-80 hover:opacity-100 disabled:bg-opacity-80",
gray: "border rounded shadow-sm focus:ring-2 focus:ring-offset-2 bg-dark-700 bg-opacity-80 w-full text-primary border-dark-800 hover:bg-opacity-100 focus:ring-offset-dark-700 focus:ring-dark-800 disabled:bg-opacity-80",
green:
"bg-green bg-opacity-80 w-full rounded text-high-emphesis hover:bg-opacity-100 disabled:bg-opacity-80",
gradient:
"w-full text-high-emphesis bg-gradient-to-r from-blue to-pink opacity-80 hover:opacity-100 disabled:bg-opacity-80",
};
const OUTLINED = {
default: "bg-transparent opacity-80 hover:opacity-100",
red: "bg-red bg-opacity-20 outline-red rounded-full text-red hover:bg-opacity-40 disabled:bg-opacity-20",
blue: "bg-blue bg-opacity-20 outline-blue rounded-full text-blue hover:bg-opacity-40 disabled:bg-opacity-20",
indigo:
"bg-indigo-600 bg-opacity-25 outline-indigo-600 rounded-full text-indigo-gray-300 hover:bg-opacity-50 disabled:bg-opacity-20",
pink: "bg-pink bg-opacity-20 outline-pink rounded-full text-pink hover:bg-opacity-40 disabled:bg-opacity-20",
gray: "bg-black bg-opacity-50 outline-gray rounded-full text-gray hover:bg-opacity-100 disabled:bg-opacity-20",
green:
"bg-green bg-opacity-20 border border-green rounded-full text-green hover:bg-opacity-40 disabled:bg-opacity-20",
gradient:
"border border-transparent border-gradient-r-blue-pink-dark-900 opacity-80 hover:opacity-100 disabled:bg-opacity-20",
};
const EMPTY = {
default:
"flex bg-transparent justify-center items-center disabled:opacity-50 disabled:cursor-auto bg-opacity-80 hover:bg-opacity-100",
blue:
"flex bg-transparent justify-center items-center disabled:opacity-50 disabled:cursor-auto bg-opacity-80 hover:bg-opacity-100",
pink:
"flex bg-transparent justify-center items-center disabled:opacity-50 disabled:cursor-auto bg-opacity-80 hover:bg-opacity-100",
gray:
"flex bg-transparent justify-center items-center disabled:opacity-50 disabled:cursor-auto bg-opacity-80 hover:bg-opacity-100",
green:
"flex bg-transparent justify-center items-center disabled:opacity-50 disabled:cursor-auto bg-opacity-80 hover:bg-opacity-100",
gradient:
"flex bg-transparent justify-center items-center disabled:opacity-50 disabled:cursor-auto bg-opacity-80 hover:bg-opacity-100",
indigo:
"flex bg-transparent justify-center items-center disabled:opacity-50 disabled:cursor-auto bg-opacity-80 hover:bg-opacity-100",
red:
"flex bg-transparent justify-center items-center disabled:opacity-50 disabled:cursor-auto bg-opacity-80 hover:bg-opacity-100",
};
const LINK = {
default:
"text-primary hover:text-high-emphesis focus:text-high-emphesis whitespace-nowrap focus:ring-0",
blue:
"text-primary hover:text-high-emphesis focus:text-high-emphesis whitespace-nowrap focus:ring-0",
pink:
"text-primary hover:text-high-emphesis focus:text-high-emphesis whitespace-nowrap focus:ring-0",
gray:
"text-primary hover:text-high-emphesis focus:text-high-emphesis whitespace-nowrap focus:ring-0",
green:
"text-primary hover:text-high-emphesis focus:text-high-emphesis whitespace-nowrap focus:ring-0",
gradient:
"text-primary hover:text-high-emphesis focus:text-high-emphesis whitespace-nowrap focus:ring-0",
red:
"text-primary hover:text-high-emphesis focus:text-high-emphesis whitespace-nowrap focus:ring-0",
indigo:
"text-primary hover:text-high-emphesis focus:text-high-emphesis whitespace-nowrap focus:ring-0",
};
const VARIANT = {
outlined: OUTLINED,
filled: FILLED,
empty: EMPTY,
link: LINK,
};
export type ButtonColor =
| "blue"
| "pink"
| "gradient"
| "gray"
| "default"
| "red"
| "green"
| "indigo";
export type ButtonSize = "xs" | "sm" | "lg" | "default" | "none";
export type ButtonVariant = "outlined" | "filled" | "empty" | "link";
export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
color?: ButtonColor;
size?: ButtonSize;
variant?: ButtonVariant;
ref?: React.Ref<HTMLButtonElement>;
children?: React.ReactNode;
className?: string;
disabled?: boolean;
onClick?: () => void;
}
function Button({
children,
className = undefined,
color = "default",
size = "default",
variant = "filled",
...rest
}: ButtonProps): React.ReactElement {
return (
<button
className={classNames(
VARIANT[variant][color],
variant ? "empty" : SIZE[size],
" disabled:cursor-not-allowed focus:outline-none",
// 'rounded focus:outline-none focus:ring disabled:opacity-50 disabled:cursor-not-allowed font-medium',
className ? className : ''
)}
{...rest}
>
<>{children}</>
</button>
);
}
export default Button;
export function ButtonConfirmed({
confirmed,
disabled,
...rest
}: { confirmed?: boolean; disabled?: boolean } & ButtonProps) {
if (confirmed) {
return (
<Button
variant="outlined"
color="green"
size="lg"
className={classNames(
disabled ? "cursor-not-allowed" : '',
"border opacity-50"
)}
disabled={disabled}
{...rest}
/>
);
} else {
return (
<Button
color={disabled ? "gray" : "gradient"}
size="lg"
disabled={disabled}
{...rest}
/>
);
}
}
export function ButtonError({
error,
disabled,
...rest
}: {
error?: boolean;
disabled?: boolean;
} & ButtonProps) {
if (error) {
return <Button color="red" size="lg" {...rest} />;
} else {
return (
<Button
color={disabled ? "gray" : "gradient"}
disabled={disabled}
size="lg"
{...rest}
/>
);
}
}