fosrl.pangolin/src/components/ui/button.tsx

83 lines
3.1 KiB
TypeScript
Raw Normal View History

2024-11-02 23:46:08 -04:00
import * as React from "react";
import { Slot } from "@radix-ui/react-slot";
import { cva, type VariantProps } from "class-variance-authority";
2024-10-06 09:55:45 -04:00
2025-01-01 21:41:31 -05:00
import { cn } from "@app/lib/cn";
2024-11-02 23:46:08 -04:00
import { Loader2 } from "lucide-react";
2024-10-06 09:55:45 -04:00
const buttonVariants = cva(
2025-06-30 09:33:48 -07:00
"cursor-pointer inline-flex items-center justify-center whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-0 disabled:pointer-events-none disabled:opacity-50",
2024-10-06 18:05:20 -04:00
{
variants: {
variant: {
2024-11-02 23:46:08 -04:00
default:
2025-06-30 09:33:48 -07:00
"bg-primary text-primary-foreground hover:bg-primary/90 shadow-2xs",
2024-10-06 18:05:20 -04:00
destructive:
2025-06-30 09:33:48 -07:00
"bg-destructive text-white dark:text-destructive-foreground hover:bg-destructive/90 shadow-2xs",
2024-10-06 18:05:20 -04:00
outline:
2025-06-30 09:33:48 -07:00
"border border-input bg-card hover:bg-accent hover:text-accent-foreground shadow-2xs",
2025-03-01 17:45:38 -05:00
outlinePrimary:
2025-06-30 09:33:48 -07:00
"border border-primary bg-card hover:bg-primary/10 text-primary shadow-2xs",
2024-10-06 18:05:20 -04:00
secondary:
2025-06-30 09:33:48 -07:00
"bg-secondary border border-input border text-secondary-foreground hover:bg-secondary/80 shadow-2xs",
2024-10-06 18:05:20 -04:00
ghost: "hover:bg-accent hover:text-accent-foreground",
2025-03-16 15:20:19 -04:00
squareOutlinePrimary:
2025-06-30 09:33:48 -07:00
"border border-primary bg-card hover:bg-primary/10 text-primary rounded-md shadow-2xs",
2025-03-16 15:20:19 -04:00
squareOutline:
2025-06-30 09:33:48 -07:00
"border border-input bg-card hover:bg-accent hover:text-accent-foreground rounded-md shadow-2xs",
2025-03-16 15:20:19 -04:00
squareDefault:
2025-06-30 09:33:48 -07:00
"bg-primary text-primary-foreground hover:bg-primary/90 rounded-md shadow-2xs",
text: "",
2025-03-16 15:20:19 -04:00
link: "text-primary underline-offset-4 hover:underline"
2024-10-06 18:05:20 -04:00
},
size: {
2025-06-30 09:33:48 -07:00
default: "h-9 rounded-md px-3",
sm: "h-8 rounded-md px-3",
lg: "h-10 rounded-md px-8",
2025-06-30 09:33:48 -07:00
icon: "h-9 w-9 rounded-md"
2025-01-04 20:22:01 -05:00
}
2024-10-06 18:05:20 -04:00
},
defaultVariants: {
variant: "default",
2025-03-16 15:20:19 -04:00
size: "default"
}
2024-10-06 18:05:20 -04:00
}
2024-11-02 23:46:08 -04:00
);
2024-10-06 09:55:45 -04:00
export interface ButtonProps
2024-10-06 18:05:20 -04:00
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
2024-11-02 23:46:08 -04:00
VariantProps<typeof buttonVariants> {
asChild?: boolean;
loading?: boolean; // Add loading prop
2024-10-06 09:55:45 -04:00
}
2025-04-12 19:57:37 -04:00
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
(
{
className,
variant,
size,
asChild = false,
loading = false,
...props
},
ref
) => {
const Comp = asChild ? Slot : "button";
return (
<Comp
className={cn(buttonVariants({ variant, size, className }))}
ref={ref}
disabled={loading || props.disabled} // Disable button when loading
{...props}
>
2025-06-27 16:43:09 -04:00
{/* {loading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />} */}
2025-04-12 19:57:37 -04:00
{props.children}
</Comp>
);
2024-10-06 18:05:20 -04:00
}
2025-04-12 19:57:37 -04:00
);
2024-11-02 23:46:08 -04:00
Button.displayName = "Button";
2024-10-06 09:55:45 -04:00
2024-11-02 23:46:08 -04:00
export { Button, buttonVariants };