Files
echecsfrance/src/components/Button.tsx
T
owenrees e7557f0926 upgrade TS to v7
update readme to reflect new lint and format plugins, apply formatting rules
2026-09-29 22:39:31 +02:00

57 lines
1.7 KiB
TypeScript

import { type ComponentProps } from "react";
import { type VariantProps, cva } from "class-variance-authority";
import { twMerge } from "tailwind-merge";
export const buttonVariants = cva("flex items-center justify-center transition-all duration-200", {
variants: {
intent: {
primary: [
"text-center",
"text-white",
"focus:outline-none focus:ring-2 focus:ring-primary-500",
"bg-primary-600",
"hover:bg-primary-800",
"disabled:opacity-25",
"dark:text-white dark:hover:bg-primary-700",
],
secondary: [
"text-primary dark:text-white",
"hover:text-white dark:hover:text-white",
"hover:bg-primary hover:text-white",
"border border-primary",
"focus:outline-none focus:ring-2 focus:ring-primary-500",
"disabled:opacity-25",
],
tertiary: [
"text-gray-900 dark:text-neutral-400",
"hover:text-primary dark:hover:text-white",
"focus:outline-none focus:ring-2 focus:ring-primary-500",
"disabled:opacity-25",
],
},
size: {
small: ["text-sm font-medium", "px-3 py-2", "sm:w-fit", "rounded-lg"],
medium: ["text-sm font-medium", "px-5 py-3", "sm:w-fit", "rounded-lg"],
compacted: ["rounded-none", "px-0 py-0"],
},
},
defaultVariants: {
intent: "primary",
size: "medium",
},
});
type ButtonVariants = VariantProps<typeof buttonVariants>;
export type ButtonProps = ComponentProps<"button"> & ButtonVariants;
export const Button = ({
className,
intent,
size,
...props
}: ButtonProps & { className?: string }) => (
<button className={twMerge(buttonVariants({ intent, size, className }))} {...props} />
);