Components
Button
Displays a button or a component that looks like a button. Supports multiple variants, sizes, and states.
Variants
Buttons come in several variants for different use cases.
Sizes
Use the size prop to change the button size.
With Icons
Add icons before or after the button text.
Loading
Use a spinner icon and disabled state when loading.
Installation
Copy and paste the following code into your project:
components/ui/button.tsxtsx
1import * as React from "react";2import { cn } from "@sunsatosolutions/ui";3import { cva, type VariantProps } from "class-variance-authority";45const buttonVariants = cva(6 "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",7 {8 variants: {9 variant: {10 default: "bg-primary text-primary-foreground shadow hover:bg-primary/90",11 destructive: "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",12 outline: "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",13 secondary: "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",14 ghost: "hover:bg-accent hover:text-accent-foreground",15 link: "text-primary underline-offset-4 hover:underline",16 },17 size: {18 default: "h-9 px-4 py-2",19 sm: "h-8 rounded-md px-3 text-xs",20 lg: "h-10 rounded-md px-8",21 icon: "h-9 w-9",22 },23 },24 defaultVariants: {25 variant: "default",26 size: "default",27 },28 }29);3031export interface ButtonProps32 extends React.ButtonHTMLAttributes<HTMLButtonElement>,33 VariantProps<typeof buttonVariants> {}3435const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(36 ({ className, variant, size, ...props }, ref) => {37 return (38 <button39 className={cn(buttonVariants({ variant, size, className }))}40 ref={ref}41 {...props}42 />43 );44 }45);46Button.displayName = "Button";4748export { Button, buttonVariants };Usage
import { Button } from "@/components/ui/button";
export default function Example() {
return <Button variant="outline">Click me</Button>;
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
variant | string | "default" | The visual style of the button |
size | string | "default" | The size of the button |
disabled | boolean | false | Whether the button is disabled |