import { Button as ShadcnButton, ButtonProps } from "@/components/ui/button"; import { FontName, fonts, iconMap, sidePlacements, } from "@/front/lib/constants"; import { cn } from "@/lib/utils"; import { CustomButtonVariant, IconConfig } from "@/types/front"; import { Link } from "@inertiajs/react"; type CustomSize = "xs" | "md"; type ThemeButtonProps = Omit & { variant?: ButtonProps["variant"] | CustomButtonVariant; size?: ButtonProps["size"] | CustomSize; icon?: IconConfig; isBold?: boolean; font?: FontName; link?: { href: string; label: string; }; }; const customVariantSizes: Record = { xs: "h-7 px-3 text-sm", md: "h-10 px-6 py-2 text-md", }; const customVariantStyles: Record = { tertiary: "bg-primary-foreground text-background hover:bg-primary-foreground/90", inverted: "bg-background hover:bg-secondary/90", }; export default function Button({ icon, isBold = true, font = fonts.GOTHAM, size, variant, children, className, asChild, link, ...props }: ThemeButtonProps) { const Icon = icon ? iconMap[icon.icon] : undefined; const customVariant = variant && variant in customVariantStyles ? customVariantStyles[variant as CustomButtonVariant] : ""; const getSizeClasses = () => { if (size && size in customVariantSizes) { return customVariantSizes[size as CustomSize]; } return "h-9 px-5 text-md"; }; const iconClassName = icon?.className ?? ""; if (link && link.href && link.label) { return ( {icon?.placement !== sidePlacements.RIGHT && Icon && ( )} {link.label} {icon?.placement === sidePlacements.RIGHT && Icon && ( )} ); } if (asChild) { return (
{icon?.placement !== sidePlacements.RIGHT && Icon && ( )} {children} {icon?.placement === sidePlacements.RIGHT && Icon && ( )}
); } return ( {icon?.placement !== sidePlacements.RIGHT && Icon && ( )} {children} {icon?.placement === sidePlacements.RIGHT && Icon && ( )} ); }