SPB Git forge

spb/polyllm

Public
15commits 1branches 0releases
2.2 MBsize
maindefault branch
13 days agolast push
TypeScript 97.4% SQL 1% JavaScript 0.9% CSS 0.6%
2.4 KB · 61 lines tsx
Raw Blame History
1"use client";2import * as React from "react";3import { Slot } from "@radix-ui/react-slot";4import { cva, type VariantProps } from "class-variance-authority";5import { Loader2 } from "lucide-react";6import { cn } from "@/lib/utils";78const buttonVariants = cva(9  "inline-flex items-center justify-center gap-1.5 whitespace-nowrap rounded-md text-sm font-medium transition-[background-color,color,border-color,box-shadow,transform] duration-150 select-none disabled:pointer-events-none disabled:opacity-50 active:scale-[0.985] [&_svg]:shrink-0 [&_svg]:size-4",10  {11    variants: {12      variant: {13        primary: "bg-fg text-bg hover:opacity-90 shadow-xs",14        accent: "bg-accent text-accent-fg hover:bg-accent-strong shadow-xs",15        secondary: "bg-bg-muted text-fg hover:bg-border",16        outline: "border border-border bg-bg-elevated text-fg hover:bg-bg-subtle hover:border-border-strong",17        ghost: "text-fg-muted hover:bg-bg-muted hover:text-fg",18        danger: "bg-danger text-white hover:opacity-90",19        "danger-soft": "bg-danger-soft text-danger hover:bg-danger hover:text-white",20        link: "text-accent underline-offset-4 hover:underline h-auto p-0",21      },22      size: {23        xs: "tap h-7 px-2 text-xs rounded-sm [&_svg]:size-3.5",24        sm: "tap h-8 px-2.5 text-[13px]",25        md: "h-9 px-3.5",26        lg: "h-11 px-5 text-[15px] rounded-lg",27        icon: "tap size-8 p-0",28        "icon-sm": "tap size-7 p-0 rounded-sm [&_svg]:size-3.5",29        "icon-lg": "size-10 p-0 rounded-lg",30      },31    },32    defaultVariants: { variant: "primary", size: "md" },33  },34);3536export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {37  asChild?: boolean;38  loading?: boolean;39}4041export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(function Button(42  { className, variant, size, asChild = false, loading = false, children, disabled, ...props },43  ref,44) {45  if (asChild) {46    return (47      <Slot className={cn(buttonVariants({ variant, size }), className)} ref={ref} {...props}>48        {children}49      </Slot>50    );51  }52  return (53    <button className={cn(buttonVariants({ variant, size }), className)} ref={ref} disabled={disabled || loading} {...props}>54      {loading ? <Loader2 className="animate-spin" aria-hidden /> : null}55      {children}56    </button>57  );58});5960export { buttonVariants };61