Buttons

Variants

Five weights, three sizes, one class map. Focus rings are keyboard-only and the press scale is small enough to feel physical rather than bouncy.

  • variant
  • size
  • focus

Preview

Usage

<Button variant="solid" size="md">Continue</Button>
import { cn } from "@/lib/cn";

export type ButtonVariant = "solid" | "soft" | "outline" | "ghost" | "danger";
export type ButtonSize = "sm" | "md" | "lg";

export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
  variant?: ButtonVariant;
  size?: ButtonSize;
  fullWidth?: boolean;
}

export const buttonSizes: Record<ButtonSize, string> = {
  sm: "h-8 gap-1.5 rounded-lg px-3 text-[13px]",
  md: "h-10 gap-2 rounded-lg px-4 text-sm",
  lg: "h-12 gap-2.5 rounded-xl px-6 text-[15px]",
};

export const buttonVariants: Record<ButtonVariant, string> = {
  solid:
    "bg-accent text-accent-ink hover:brightness-110 active:brightness-95 shadow-[0_1px_2px_rgba(0,0,0,.16)]",
  soft:
    "bg-[color-mix(in_oklab,var(--color-accent)_14%,transparent)] text-accent hover:bg-[color-mix(in_oklab,var(--color-accent)_22%,transparent)]",
  outline:
    "border border-line-strong bg-transparent text-ink hover:bg-surface active:bg-elevated",
  ghost: "bg-transparent text-ink-2 hover:bg-surface hover:text-ink",
  danger: "bg-negative text-white hover:brightness-110 active:brightness-95",
};

export const buttonBase =
  "relative inline-flex select-none items-center justify-center font-medium " +
  "transition-[background-color,color,box-shadow,transform,filter] duration-150 " +
  "outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 " +
  "focus-visible:ring-offset-canvas active:scale-[.985] " +
  "disabled:pointer-events-none disabled:opacity-45";

export function Button({
  variant = "solid",
  size = "md",
  fullWidth,
  className,
  ...rest
}: ButtonProps) {
  return (
    <button
      className={cn(
        buttonBase,
        buttonSizes[size],
        buttonVariants[variant],
        fullWidth && "w-full",
        className,
      )}
      {...rest}
    />
  );
}

export default Button;