import { CircleNotchIcon } from "../icons"; import type { ComponentProps, ReactNode } from "react"; import { Link } from "../provider"; import { cn } from "./cn"; export type ButtonVariant = "primary" | "secondary" | "ghost" | "destructive" | "secondary-destructive"; export type ButtonSize = "sm" | "base" | "lg"; interface Look { variant?: ButtonVariant; size?: ButtonSize; shape?: "square"; icon?: ReactNode; loading?: boolean; } const VARIANT: Record = { primary: "bg-primary text-on-primary shadow-[inset_0_1px_0_rgb(255_255_255/0.16),0_1px_2px_rgb(0_0_0/0.2)] hover:bg-primary-hover", secondary: "bg-control text-ink shadow-control hover:bg-control-hover", ghost: "bg-transparent text-muted hover:bg-hover hover:text-ink", destructive: "bg-danger text-white shadow-[inset_0_1px_0_rgb(255_255_255/0.16),0_1px_2px_rgb(0_0_0/0.2)] hover:brightness-110", "secondary-destructive": "bg-control text-danger shadow-[0_0_0_1px_color-mix(in_oklab,var(--danger)_45%,transparent)] hover:bg-danger-tint", }; const SIZE: Record = { sm: "h-7 gap-1.5 rounded-chip px-2.5 text-compact pointer-coarse:h-9", base: "h-8 gap-1.5 rounded-control px-3 text-compact pointer-coarse:h-10", lg: "h-10 gap-2 rounded-control px-4 text-callout pointer-coarse:h-12", }; const SQUARE: Record = { sm: "size-7 px-0 pointer-coarse:size-9", base: "size-8 px-0 pointer-coarse:size-10", lg: "size-10 px-0 pointer-coarse:size-12" }; function classes({ variant = "secondary", size = "base", shape }: Look, className?: string): string { return cn( "pressable inline-flex shrink-0 cursor-pointer items-center justify-center font-medium whitespace-nowrap select-none", "disabled:cursor-not-allowed disabled:opacity-45 aria-disabled:cursor-not-allowed aria-disabled:opacity-45", "[&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:opacity-80", VARIANT[variant], SIZE[size], shape === "square" && SQUARE[size], className, ); } function Content({ icon, loading, children }: { icon?: ReactNode; loading?: boolean; children?: ReactNode }) { return ( <> {loading ? : icon} {children} ); } export type ButtonProps = Look & ComponentProps<"button">; /** * A pressable control. Primary is the one ink action on a surface; secondary sits on a soft ring. On a touch * screen every size grows, because a finger needs a larger target than a pointer. */ export function Button({ variant, size, shape, icon, loading = false, className, children, disabled, type = "button", ...props }: ButtonProps) { return ( ); } export type LinkButtonProps = Look & ComponentProps<"a"> & { href: string }; /** A link styled as a button; it navigates through the app's router. */ export function LinkButton({ variant, size, shape, icon, loading, className, children, href, ...props }: LinkButtonProps) { return ( {children} ); }