Button
Pill-shaped button with brand, soft and ghost variants.
Installation
$
pnpm dlx apen-ui@latest add buttonAlso installsclass-variance-authorityradix-ui
Manual installation
Copy the source into components/ui/button.tsx and install class-variance-authority radix-ui.
components/ui/button.tsx
import * as React from "react"
import { Slot } from "radix-ui"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
const buttonVariants = cva(
"inline-flex shrink-0 items-center justify-center gap-2 rounded-full text-sm font-semibold whitespace-nowrap transition-all outline-none select-none active:scale-[0.98] focus-visible:ring-4 focus-visible:ring-ring/25 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
{
variants: {
variant: {
default:
"bg-primary text-primary-foreground shadow-sm shadow-primary/20 hover:bg-primary/90",
brand:
"bg-brand-gradient text-white shadow-sm shadow-primary/25 hover:opacity-90",
secondary:
"bg-secondary text-secondary-foreground hover:bg-accent",
outline:
"border border-input bg-card hover:bg-accent hover:text-accent-foreground",
ghost: "hover:bg-accent hover:text-accent-foreground",
destructive:
"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/25",
link: "text-primary underline-offset-4 hover:underline",
},
size: {
default: "h-10 px-5",
sm: "h-8 px-3.5 text-xs",
lg: "h-12 px-7 text-base",
icon: "size-10",
"icon-sm": "size-8",
"icon-lg": "size-12",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
)
function Button({
className,
variant,
size,
asChild = false,
...props
}: React.ComponentProps<"button"> &
VariantProps<typeof buttonVariants> & {
asChild?: boolean
}) {
const Comp = asChild ? Slot.Root : "button"
return (
<Comp
data-slot="button"
className={cn(buttonVariants({ variant, size, className }))}
{...props}
/>
)
}
export { Button, buttonVariants }