v1.3.5
Basics

Buttons and links

Buttons in five looks and three sizes, a busy state with a spinner, and links for text and navigation.

Live example

Variants

Sizes and icons

Copy: press one

Busy: press one

Links

Direction

Copy

Claude Code
Cursor
v0
Lovable
Other
Add the "Buttons and links" components from FiltersUI to this project. It is free and MIT licensed, from filtersui.com.

Buttons and links: Buttons in five looks and three sizes, a busy state with a spinner, and links for text and navigation.

Needs: React 19, Tailwind CSS 4.2 or later and TypeScript. If this project uses another setup, adapt the classes, keep the look.

## Install

If this project has a components.json, run: npx shadcn@latest add https://filtersui.com/r/buttons.json
and skip the files below.

Otherwise save each file below at the path shown, from the project root (or inside src/ if the project keeps its code there). Keep the folder layout: the files import each other by relative paths.

Install these npm packages: npm install clsx tailwind-merge

### components/filters-ui/ui/button.tsx

```tsx
"use client";

import { useEffect, useRef, useState, type ButtonHTMLAttributes, type ReactNode } from "react";
import { cn } from "../lib/cn";
import { BUTTON_BASE, buttonClasses, type ButtonSize, type ButtonVariant } from "./button-classes";

export type ButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
  /** Default "primary". */
  variant?: ButtonVariant;
  /** "sm" 32px, "md" 40px, "lg" 44px. Default "md". */
  size?: ButtonSize;
  /** An icon before the label, drawn in currentColor. */
  before?: ReactNode;
  /** An icon after the label. */
  after?: ReactNode;
  /** While a request runs: presses do nothing and, after 150ms, a spinner takes the label's place for at least 400ms. */
  busy?: boolean;
};

function Spinner() {
  return (
    <svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true" focusable="false" className="size-4 animate-spin">      <circle cx="8" cy="8" r="6.5" stroke="currentColor" strokeOpacity="0.25" strokeWidth="2" />
      <path d="M8 1.5A6.5 6.5 0 0 1 14.5 8" stroke="currentColor" strokeWidth="2" strokeLinecap="round" />
    </svg>
  );
}

/** "idle", then "busy" once a request has run 150ms, kept at least 400ms, then "leaving" for the spinner's exit. */
function useSpinner(busy: boolean) {
  const [phase, setPhase] = useState<"idle" | "busy" | "leaving">("idle");
  const since = useRef(0);
  useEffect(() => {
    let timer: ReturnType<typeof setTimeout> | undefined;
    if (busy && phase !== "busy") {
      timer = setTimeout(
        () => {
          since.current = Date.now();
          setPhase("busy");
        },
        phase === "leaving" ? 0 : 150,
      );
    } else if (!busy && phase === "busy") {
      timer = setTimeout(() => setPhase("leaving"), Math.max(0, 400 - (Date.now() - since.current)));
    } else if (!busy && phase === "leaving") {
      timer = setTimeout(() => setPhase("idle"), 200);
    }
    return () => clearTimeout(timer);
  }, [busy, phase]);
  return phase;
}

const SWAP = "transition-[opacity,translate,filter] ease-in-out motion-reduce:transition-none";

/**
 * A button in five looks and three sizes, 10px corners. It presses to 0.97 and shows a 2px --fu-accent-soft focus ring.
 * It is never drawn disabled: while busy it keeps its look, its width and its focus, and ignores presses.
 */
export function Button({
  variant = "primary",
  size = "md",
  before,
  after,
  busy = false,
  type = "button",
  className,
  children,
  onClick,
  ...props
}: ButtonProps) {
  const phase = useSpinner(busy);
  const blocked = busy || phase === "busy";

  return (
    <button
      type={type}
      aria-busy={blocked || undefined}
      onClick={(event) => {
        // Also stops a submit button from sending its form.
        if (blocked) {
          event.preventDefault();
          return;
        }
        onClick?.(event);
      }}
      className={buttonClasses({ variant, size, before: before != null, after: after != null, className })}
      {...props}
    >
      <span
        className={cn(
          "inline-flex items-center gap-[inherit]",
          SWAP,
          phase === "busy" ? "-translate-y-1 opacity-0 blur-[2px] duration-150" : "delay-[110ms] duration-[170ms]",
        )}
      >
        {before != null && (
          <span aria-hidden="true" className="inline-flex shrink-0">
            {before}
          </span>
        )}
        {children}
        {after != null && (
          <span aria-hidden="true" className="inline-flex shrink-0">
            {after}
          </span>
        )}
      </span>
      {phase !== "idle" && (
        <span aria-hidden="true" className="pointer-events-none absolute inset-0 grid place-items-center">
          <span
            className={cn(
              "grid",
              SWAP,
              phase === "busy"
                ? "translate-y-0 opacity-100 blur-none delay-[110ms] duration-[170ms] starting:translate-y-1 starting:opacity-0 starting:blur-[2px]"
                : "-translate-y-1 opacity-0 blur-[2px] duration-150",
            )}
          >
            <Spinner />
          </span>
        </span>
      )}
    </button>
  );
}

export type IconButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, "children" | "aria-label"> & {
  /** The accessible name, e.g. "Copy link". Required: the icon alone says nothing to a screen reader. */
  label: string;
  /** "sm" 32px, "md" 36px, "lg" 44px square. Default "md". */
  size?: ButtonSize;
  /** "ghost": no fill until hovered. "secondary": a --fu-surface-3 square. Default "ghost". */
  variant?: "ghost" | "secondary";
  children: ReactNode;
};

const ICON_TAP = "pointer-coarse:after:absolute pointer-coarse:after:content-['']";

const ICON_SIZES: Record<ButtonSize, string> = {
  sm: cn("size-8 [&_svg]:size-4", ICON_TAP, "pointer-coarse:after:-inset-1.5"),
  md: cn("size-9 [&_svg]:size-5", ICON_TAP, "pointer-coarse:after:-inset-1"),
  lg: "size-11 [&_svg]:size-5",
};

/** A square button holding one icon, --fu-mute until hovered. */
export function IconButton({ label, size = "md", variant = "ghost", type = "button", className, children, ...props }: IconButtonProps) {
  return (
    <button
      type={type}
      aria-label={label}
      className={cn(
        BUTTON_BASE,
        ICON_SIZES[size],
        "text-[var(--fu-mute,#BDBDBD)] hover:bg-[var(--fu-hover,#333333)] hover:text-[var(--fu-text,#F8F5F1)]",
        variant === "secondary" ? "bg-[var(--fu-surface-3,#2A2A2A)] forced-colors:border forced-colors:border-[ButtonText]" : "bg-transparent",
        className,
      )}
      {...props}
    >
      <span aria-hidden="true" className="inline-flex">
        {children}
      </span>
    </button>
  );
}
```

### components/filters-ui/lib/cn.ts

```ts
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";

export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs));
}
```

### components/filters-ui/ui/button-classes.ts

```ts
import { cn } from "../lib/cn";

// The button looks as class names. Kept apart from button.tsx, a client module, so server pages can call them too.

export type ButtonVariant = "primary" | "secondary" | "ghost" | "quiet" | "quiet-accent";
export type ButtonSize = "sm" | "md" | "lg";

export const BUTTON_BASE = cn(
  "relative inline-flex shrink-0 cursor-pointer items-center justify-center rounded-[10px] font-[inherit] font-medium whitespace-nowrap no-underline select-none",
  "[-webkit-tap-highlight-color:transparent] transition-[background-color,color,scale] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)]",
  "active:scale-[0.97] active:duration-75 motion-reduce:transition-none motion-reduce:active:scale-100",
  "outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-solid focus-visible:outline-[var(--fu-accent-soft,#8FAAFF)]",
  "aria-busy:cursor-progress aria-busy:active:scale-100",
);

const VARIANTS: Record<ButtonVariant, string> = {
  primary:
    "bg-[var(--fu-accent,#3B57E6)] text-[var(--fu-on-accent,#FFFFFF)] hover:bg-[var(--fu-accent-hover,#3450D4)] forced-colors:border forced-colors:border-[ButtonText]",
  secondary:
    "bg-[var(--fu-surface-3,#2A2A2A)] text-[var(--fu-text,#F8F5F1)] hover:bg-[var(--fu-hover,#333333)] forced-colors:border forced-colors:border-[ButtonText]",
  ghost: "bg-transparent text-[var(--fu-text,#F8F5F1)] hover:bg-[var(--fu-hover-wash,rgb(255_255_255/0.14))]",
  quiet: "bg-transparent text-[var(--fu-mute,#BDBDBD)] hover:text-[var(--fu-text,#F8F5F1)]",
  "quiet-accent":
    "bg-transparent text-[var(--fu-accent-soft,#8FAAFF)] decoration-1 underline-offset-[5px] hover:text-[var(--fu-accent-pale,#D1DDFF)] [@media(hover:hover)]:hover:underline",
};

// Below 44px a touch screen gets a taller invisible target through ::after.
const TAP = "pointer-coarse:after:absolute pointer-coarse:after:inset-x-0 pointer-coarse:after:content-['']";

const SIZES: Record<ButtonSize, { box: string; before: string; after: string }> = {
  sm: { box: cn("h-8 gap-1.5 px-3 text-[13px] leading-5 [&_svg]:size-4", TAP, "pointer-coarse:after:-inset-y-1.5"), before: "ps-2.5", after: "pe-2.5" },
  md: { box: cn("h-10 gap-2 px-3.5 text-[15px] leading-5 [&_svg]:size-4", TAP, "pointer-coarse:after:-inset-y-0.5"), before: "ps-3", after: "pe-3" },
  lg: { box: "h-11 gap-2 px-4 text-[15px] leading-5 [&_svg]:size-[18px]", before: "ps-3.5", after: "pe-3.5" },
};

/** The classes of a button, for a link or a router link that should look like one. */
export function buttonClasses({
  variant = "primary",
  size = "md",
  before = false,
  after = false,
  className,
}: { variant?: ButtonVariant; size?: ButtonSize; before?: boolean; after?: boolean; className?: string } = {}) {
  return cn(BUTTON_BASE, VARIANTS[variant], SIZES[size].box, before && SIZES[size].before, after && SIZES[size].after, className);
}
```

### components/filters-ui/ui/copy-button.tsx

```tsx
"use client";

import { useEffect, useRef, useState, type ButtonHTMLAttributes } from "react";
import { cn } from "../lib/cn";
import { buttonClasses, type ButtonSize, type ButtonVariant } from "./button-classes";
import { CheckIcon, CopyIcon } from "./icons";

/** Writes text to the clipboard. Falls back to a hidden textarea where the async API is missing or refused. */
export async function copyToClipboard(text: string) {
  try {
    if (window.isSecureContext && navigator.clipboard) {
      await navigator.clipboard.writeText(text);
      return true;
    }
  } catch {}
  const area = document.createElement("textarea");
  area.value = text;
  area.setAttribute("readonly", "");
  area.style.position = "fixed";
  area.style.opacity = "0";
  area.style.pointerEvents = "none";
  document.body.appendChild(area);
  const active = document.activeElement as HTMLElement | null;
  area.select();
  let done = false;
  try {
    done = document.execCommand("copy");
  } catch {}
  area.remove();
  active?.focus();
  return done;
}

type State = "idle" | "copied" | "failed";

const EASE = "ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none";
const SHOWN = "scale-100 opacity-100 blur-none";
const GONE = "scale-50 opacity-0 blur-[2px]";

/** The copy glyph turns into a check that draws itself in, then turns back. Decorative: the button carries the name. */
export function CopyGlyph({ copied, className }: { copied: boolean; className?: string }) {
  return (
    <span aria-hidden="true" className={cn("relative inline-grid size-[1em] shrink-0 place-items-center [&>*]:[grid-area:1/1]", className)}>
      <CopyIcon className={cn("size-full transition-[scale,opacity,filter] duration-200", EASE, copied ? GONE : SHOWN)} />
      <CheckIcon
        strokeWidth={2.5}
        className={cn(
          "size-full text-[var(--fu-accent-soft,#8FAAFF)] transition-[scale,opacity,filter] duration-200",
          EASE,
          // The check path is about 23 units long, so a 23 dash offset hides it and 0 draws it.
          "[&_path]:[stroke-dasharray:23] [&_path]:transition-[stroke-dashoffset] [&_path]:duration-[320ms] [&_path]:ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:[&_path]:transition-none",
          copied ? cn(SHOWN, "[&_path]:[stroke-dashoffset:0] [&_path]:delay-[80ms]") : cn(GONE, "[&_path]:[stroke-dashoffset:23]"),
        )}
      />
    </span>
  );
}

export type CopyButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, "onClick" | "children" | "type"> & {
  /** What to copy. A function is read at press time, for text that is costly to build. */
  text: string | (() => string);
  /** The visible words. Leave out for an icon-only square, which then needs `aria-label`. */
  label?: string;
  /** Shown for 1.6s after a copy. Default "Copied". */
  copiedLabel?: string;
  /** What screen readers hear after a copy, e.g. "Prompt copied". Default: copiedLabel. */
  announce?: string;
  /** Default "secondary". */
  variant?: ButtonVariant;
  /** Default "md". */
  size?: ButtonSize;
  /** Show the copy glyph before the words. Default true. */
  icon?: boolean;
  /** Called after each attempt. */
  onCopy?: (ok: boolean) => void;
};

const ICON_SQUARE: Record<ButtonSize, string> = {
  sm: "w-8 px-0 [&_svg]:size-4",
  md: "w-10 px-0 [&_svg]:size-[18px]",
  lg: "w-11 px-0 [&_svg]:size-5",
};

// The glyph's box is exactly its icon's size, so the icon centres on the words and the gap is the button's own.
const GLYPH: Record<ButtonSize, string> = { sm: "size-4", md: "size-4", lg: "size-[18px]" };
const SQUARE_GLYPH: Record<ButtonSize, string> = { sm: "size-4", md: "size-[18px]", lg: "size-5" };

/**
 * Copies text and confirms it in place: "Copy" and its glyph blur over to "Copied" with a check that draws in, and a
 * polite status tells screen readers. The button keeps its width, its focus and its look, with even space on both
 * sides of whatever it shows; a second press inside the 1.6s window copies again and is announced again. On failure
 * it says "Failed". Icon-only, it also shows a small "Copy" / "Copied" tip on hover and keyboard focus.
 */
export function CopyButton({
  text,
  label,
  copiedLabel = "Copied",
  announce,
  variant = "secondary",
  size = "md",
  icon = true,
  onCopy,
  className,
  "aria-label": ariaLabel,
  ...props
}: CopyButtonProps) {
  const [state, setState] = useState<State>("idle");
  const [status, setStatus] = useState("");
  const reset = useRef<ReturnType<typeof setTimeout>>(undefined);
  const speak = useRef<ReturnType<typeof setTimeout>>(undefined);
  useEffect(
    () => () => {
      clearTimeout(reset.current);
      clearTimeout(speak.current);
    },
    [],
  );

  const copy = async () => {
    const ok = await copyToClipboard(typeof text === "function" ? text() : text);
    setState(ok ? "copied" : "failed");
    onCopy?.(ok);
    // Emptied first, so a repeat copy inside the window is read out again.
    setStatus("");
    clearTimeout(speak.current);
    speak.current = setTimeout(() => setStatus(ok ? (announce ?? copiedLabel) : "Copy failed"), 60);
    clearTimeout(reset.current);
    reset.current = setTimeout(() => {
      setState("idle");
      setStatus("");
    }, 1600);
  };

  const copied = state === "copied";
  const iconOnly = label === undefined;
  const words: Record<State, string | undefined> = { idle: label, copied: copiedLabel, failed: "Failed" };

  return (
    <>
      <button
        type="button"
        onClick={copy}
        aria-label={iconOnly ? (copied ? copiedLabel : (ariaLabel ?? "Copy")) : ariaLabel}
        data-state={state}
        className={cn(
          buttonClasses({ variant, size }),
          iconOnly && ICON_SQUARE[size],
          "group/copy",
          className,
        )}
        {...props}
      >
        {iconOnly ? (
          icon && <CopyGlyph copied={copied} className={SQUARE_GLYPH[size]} />
        ) : (
          // Each state, glyph and words, sits unseen in one grid cell, so the widest sets the width. The shown state lies
          // centred over them, with the same space on both sides, and the states blur over into each other.
          <span className="relative inline-grid [gap:inherit]">
            {(Object.keys(words) as State[]).map((key) => (
              <span key={key} aria-hidden="true" className="invisible inline-flex items-center [gap:inherit] [grid-area:1/1]">
                {icon && <span className={cn("shrink-0", GLYPH[size])} />}
                {words[key]}
              </span>
            ))}
            {(Object.keys(words) as State[]).map((key) => (
              <span
                key={key}
                aria-hidden={key !== state || undefined}
                className={cn(
                  "absolute inset-0 flex items-center justify-center [gap:inherit] transition-[opacity,filter] duration-150 ease-in-out motion-reduce:transition-none",
                  key === state ? "opacity-100 blur-none" : "pointer-events-none opacity-0 blur-[2px]",
                )}
              >
                {icon && <CopyGlyph copied={key === "copied" && copied} className={GLYPH[size]} />}
                {words[key]}
              </span>
            ))}
          </span>
        )}
        {iconOnly && (
          <span
            aria-hidden="true"
            className={cn(
              "pointer-events-none absolute bottom-[calc(100%+6px)] left-1/2 z-[2] -translate-x-1/2 rounded-[8px] px-2 py-1 whitespace-nowrap",
              "bg-[var(--fu-text,#F8F5F1)] text-[12px] leading-4 font-medium text-[var(--fu-surface-1,#171717)]",
              "translate-y-1 opacity-0 transition-[opacity,translate] duration-150 ease-in-out motion-reduce:transition-none",
              "[@media(hover:hover)]:group-hover/copy:translate-y-0 [@media(hover:hover)]:group-hover/copy:opacity-100",
              "group-focus-visible/copy:translate-y-0 group-focus-visible/copy:opacity-100",
              copied && "translate-y-0 opacity-100",
            )}
          >
            {copied ? copiedLabel : state === "failed" ? "Failed" : (ariaLabel ?? "Copy")}
          </span>
        )}
      </button>
      <span className="sr-only" role="status" aria-live="polite">
        {status}
      </span>
    </>
  );
}
```

### components/filters-ui/ui/icons.tsx

```tsx
import type { ReactNode, SVGProps } from "react";

/*
 * Icon paths from Lucide (https://lucide.dev), ISC License.
 * Copyright (c) for portions of Lucide are held by Cole Bemis 2013-2022 as part of Feather (MIT).
 * All other copyright (c) for Lucide are held by Lucide Contributors 2022.
 * Permission to use, copy, modify, and/or distribute this software for any purpose with or
 * without fee is hereby granted, provided that the above copyright notice and this permission
 * notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
 * SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

export type IconProps = Omit<SVGProps<SVGSVGElement>, "children"> & { size?: number };

function Icon({ size = 20, strokeWidth = 2, children, ...props }: IconProps & { children: ReactNode }) {
  return (
    <svg
      width={size}
      height={size}
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      strokeWidth={strokeWidth}
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
      focusable="false"
      {...props}
    >
      {children}
    </svg>
  );
}

export function ChevronDownIcon(props: IconProps) {
  return (
    <Icon {...props}>
      <path d="m6 9 6 6 6-6" />
    </Icon>
  );
}

export function XIcon(props: IconProps) {
  return (
    <Icon {...props}>
      <path d="M18 6 6 18" />
      <path d="m6 6 12 12" />
    </Icon>
  );
}

export function CheckIcon(props: IconProps) {
  return (
    <Icon {...props}>
      <path d="M20 6 9 17l-5-5" />
    </Icon>
  );
}

export function SearchIcon(props: IconProps) {
  return (
    <Icon {...props}>
      <circle cx="11" cy="11" r="8" />
      <path d="m21 21-4.3-4.3" />
    </Icon>
  );
}

export function ArrowUpRightIcon(props: IconProps) {
  return (
    <Icon {...props}>
      <path d="M7 7h10v10" />
      <path d="M7 17 17 7" />
    </Icon>
  );
}

export function PlusIcon(props: IconProps) {
  return (
    <Icon {...props}>
      <path d="M5 12h14" />
      <path d="M12 5v14" />
    </Icon>
  );
}

export function CopyIcon(props: IconProps) {
  return (
    <Icon {...props}>
      <rect width="14" height="14" x="8" y="8" rx="2" ry="2" />
      <path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" />
    </Icon>
  );
}

export function SlidersIcon(props: IconProps) {
  return (
    <Icon {...props}>
      <path d="M21 4h-7" />
      <path d="M10 4H3" />
      <path d="M21 12h-9" />
      <path d="M8 12H3" />
      <path d="M21 20h-5" />
      <path d="M12 20H3" />
      <path d="M14 2v4" />
      <path d="M8 10v4" />
      <path d="M16 18v4" />
    </Icon>
  );
}

export function ArrowRightIcon(props: IconProps) {
  return (
    <Icon {...props}>
      <path d="M5 12h14" />
      <path d="m12 5 7 7-7 7" />
    </Icon>
  );
}

export function SearchXIcon(props: IconProps) {
  return (
    <Icon {...props}>
      <path d="m13.5 8.5-5 5" />
      <path d="m8.5 8.5 5 5" />
      <circle cx="11" cy="11" r="8" />
      <path d="m21 21-4.3-4.3" />
    </Icon>
  );
}

export function StarIcon(props: IconProps) {
  return (
    <Icon {...props}>
      <path d="M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z" />
    </Icon>
  );
}

export function HistoryIcon(props: IconProps) {
  return (
    <Icon {...props}>
      <path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" />
      <path d="M3 3v5h5" />
      <path d="M12 7v5l4 2" />
    </Icon>
  );
}

export function ListTreeIcon(props: IconProps) {
  return (
    <Icon {...props}>
      <path d="M21 12h-8" />
      <path d="M21 6H8" />
      <path d="M21 18h-8" />
      <path d="M3 6v4c0 1.1.9 2 2 2h3" />
      <path d="M3 10v6c0 1.1.9 2 2 2h3" />
    </Icon>
  );
}

export function CircleAlertIcon(props: IconProps) {
  return (
    <Icon {...props}>
      <circle cx="12" cy="12" r="10" />
      <path d="M12 8v4" />
      <path d="M12 16h.01" />
    </Icon>
  );
}
```

### components/filters-ui/ui/link.tsx

```tsx
import type { AnchorHTMLAttributes, ReactNode } from "react";
import { cn } from "../lib/cn";
import { ArrowUpRightIcon, ChevronDownIcon } from "./icons";

export type LinkVariant = "inline" | "quiet";

export type LinkStyle = {
  /** "inline": accent text, always underlined, for a link inside a sentence. "quiet": muted text that lights up, for navigation. Default "inline". */
  variant?: LinkVariant;
  /** A quiet link's colour at rest: "mute" (--fu-mute) or "dim" (--fu-dim). Default "mute". */
  tone?: "mute" | "dim";
  /** A quiet link's height: "md" 36px, "lg" 44px (a header). Default "md". */
  size?: "md" | "lg";
  className?: string;
};

const FOCUS =
  "rounded-[4px] outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-solid focus-visible:outline-[var(--fu-accent-soft,#8FAAFF)] [-webkit-tap-highlight-color:transparent]";

/** The classes of a link, for a router link such as next/link. Pair a quiet one with LinkArrow for an arrow that nudges on hover. */
export function linkClasses({ variant = "inline", tone = "mute", size = "md", className }: LinkStyle = {}) {
  return cn(
    "group/link transition-[color,text-decoration-color] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",
    FOCUS,
    variant === "inline"
      ? cn(
          "text-[var(--fu-accent-soft,#8FAAFF)] underline decoration-1 underline-offset-[3px] decoration-[color:var(--fu-link-line,rgb(143_170_255/0.4))]",
          "transition-[color,text-decoration-color,text-underline-offset]",
          "hover:text-[var(--fu-accent-pale,#D1DDFF)] hover:decoration-[color:var(--fu-accent-pale,#D1DDFF)] hover:underline-offset-[5px] active:opacity-80",
        )
      : cn(
          "relative inline-flex items-center gap-1 text-[14px] leading-5 whitespace-nowrap no-underline hover:text-[var(--fu-text,#F8F5F1)]",
          tone === "dim" ? "text-[var(--fu-dim,#929292)]" : "text-[var(--fu-mute,#BDBDBD)]",
          size === "lg" ? "h-11" : "h-9 pointer-coarse:after:absolute pointer-coarse:after:inset-x-0 pointer-coarse:after:-inset-y-1 pointer-coarse:after:content-['']",
        ),
    className,
  );
}

/** A 16px chevron that nudges 2px its way while its link is hovered. Back links point and nudge back: left, or right in RTL. */
export function LinkArrow({ direction = "forward", className }: { direction?: "forward" | "back"; className?: string }) {
  return (
    <ChevronDownIcon
      size={16}
      className={cn(
        "shrink-0 transition-[translate] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",
        direction === "back"
          ? "rotate-90 group-hover/link:-translate-x-0.5 rtl:-rotate-90 rtl:group-hover/link:translate-x-0.5"
          : "-rotate-90 group-hover/link:translate-x-0.5 rtl:rotate-90 rtl:group-hover/link:-translate-x-0.5",
        className,
      )}
    />
  );
}

/** A quiet link's words: a 1px line draws in under them from the start edge while the link is hovered or focused. */
export function LinkText({ children, className }: { children: ReactNode; className?: string }) {
  return (
    <span
      className={cn(
        "bg-[linear-gradient(currentColor,currentColor)] bg-[length:0%_1px] bg-[position:0_100%] rtl:bg-[position:100%_100%] bg-no-repeat pb-px",
        "transition-[background-size] duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",
        "[@media(hover:hover)]:group-hover/link:bg-[length:100%_1px] group-focus-visible/link:bg-[length:100%_1px]",
        className,
      )}
    >
      {children}
    </span>
  );
}

/** The up-right arrow after a link that opens a new tab, with the words a screen reader needs. */
export function ExternalMark() {
  return (
    <>
      <ArrowUpRightIcon
        size={12}
        strokeWidth={2.5}
        className={cn(
          "ms-1 inline-block shrink-0 align-[-1px] opacity-70",
          "transition-[translate] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] group-hover/link:translate-x-px group-hover/link:-translate-y-px motion-reduce:transition-none",
        )}
      />
      <span className="sr-only"> (opens in a new tab)</span>
    </>
  );
}

export type TextLinkProps = AnchorHTMLAttributes<HTMLAnchorElement> &
  LinkStyle & {
    /** A chevron before ("back") or after ("forward") the words. */
    arrow?: "forward" | "back";
  };

/**
 * A link: "inline" inside a sentence (--fu-accent-soft, underlined, so colour is never its only mark) or "quiet" for
 * navigation (muted, no underline). target="_blank" adds an up-right arrow, "opens in a new tab" and rel="noopener".
 * An action with no URL is a Button with variant "quiet", not a link.
 */
export function TextLink({ variant, tone, size, arrow, target, rel, className, children, ...props }: TextLinkProps) {
  const external = target === "_blank";
  return (
    <a target={target} rel={rel ?? (external ? "noopener" : undefined)} className={linkClasses({ variant, tone, size, className })} {...props}>
      {arrow === "back" && <LinkArrow direction="back" />}
      {variant === "quiet" ? <LinkText>{children}</LinkText> : children}
      {arrow === "forward" && <LinkArrow />}
      {external && <ExternalMark />}
    </a>
  );
}
```

## What it does

- Primary, secondary, ghost and quiet looks in 32, 40 and 44px, all with 10px corners and the same press and focus ring.
- Busy never greys a button out: it keeps its colour, width and focus, ignores presses and swaps its label for a spinner.
- Inline links are always underlined, so colour is never their only mark; quiet links suit navigation and back links.
- A link that opens a new tab gets a small up-right arrow and says so to screen readers.

## Props and value

Button (components/filters-ui/ui/button.tsx) holds this value: None. Set busy while a request runs.

- variant: "primary" | "secondary" | "ghost" | "quiet" | "quiet-accent" (default "primary"). Accent fill, grey fill, no fill with a wash on hover, or muted text that lights up (accent text for quiet-accent).
- size: "sm" | "md" | "lg" (default "md"). 32, 40 or 44px high. sm and md grow their tap area to 44px on touch screens.
- before / after: ReactNode (optional). An icon before or after the label, drawn in currentColor.
- busy: boolean (default false). Presses do nothing; after 150ms a spinner takes the label's place for at least 400ms. The button keeps its focus and width.
- IconButton label: string (required). IconButton: the accessible name of an icon-only button, e.g. "Copy link".
- TextLink variant: "inline" | "quiet" (default "inline"). TextLink: "inline" for a link in a sentence (accent, underlined), "quiet" for navigation (muted, no underline).
- TextLink arrow: "forward" | "back" (optional). TextLink: a chevron that nudges 2px its way on hover.
- buttonClasses / linkClasses: (style) => string (optional). The same looks as class names (ui/button-classes.ts, ui/link.tsx), for a router link such as next/link, or a server component.

## Usage

A working example. Imports assume @/ points at the project root; change @/components/filters-ui if this project uses another alias.

```tsx
"use client";

import { useEffect, useRef, useState, type MouseEvent, type ReactNode } from "react";
import { Button } from "@/components/filters-ui/ui/button";
import { CopyButton } from "@/components/filters-ui/ui/copy-button";
import { PlusIcon } from "@/components/filters-ui/ui/icons";
import { TextLink } from "@/components/filters-ui/ui/link";

function Row({ title, children }: { title: string; children: ReactNode }) {
  return (
    <section className="@container flex flex-col gap-3">
      <h3 className="text-[13px] leading-5 font-medium text-[var(--fu-dim,#929292)]">{title}</h3>
      <div className="flex flex-wrap items-center gap-2">{children}</div>
    </section>
  );
}

export default function ButtonsExample() {
  const [busy, setBusy] = useState<string | null>(null);
  const timer = useRef<ReturnType<typeof setTimeout>>(undefined);
  useEffect(() => () => clearTimeout(timer.current), []);

  // Stands in for a request that takes a moment.
  const send = (name: string) => {
    setBusy(name);
    clearTimeout(timer.current);
    timer.current = setTimeout(() => setBusy(null), 1600);
  };

  // Placeholder links: they stay on this page.
  const stay = (event: MouseEvent<HTMLAnchorElement>) => event.preventDefault();

  return (
    <div className="flex w-full max-w-[460px] flex-col gap-8">
      <Row title="Variants">
        <Button>Show 138 cars</Button>
        <Button variant="secondary">Save search</Button>
        {/* In a narrow column the two quiet looks take their own line, pulled back so their words start on the edge. */}
        <span className="flex gap-2 @max-[420px]:-ms-3.5 @max-[420px]:basis-full">
          <Button variant="ghost">Clear all</Button>
          <Button variant="quiet">Cancel</Button>
        </span>
      </Row>
      <Row title="Sizes and icons">
        <Button size="sm" variant="secondary" before={<PlusIcon />}>
          Add filter
        </Button>
        <Button size="lg">Search cars</Button>
      </Row>
      <Row title="Copy: press one">
        <CopyButton text="npx shadcn@latest add https://filtersui.com/r/buttons.json" label="Copy code" announce="Code copied" />
        <CopyButton variant="primary" size="lg" text="Show me cars under $30k" label="Copy prompt" announce="Prompt copied" />
        <CopyButton size="lg" text="https://filtersui.com/basics/buttons" aria-label="Copy link" announce="Link copied" />
      </Row>
      <Row title="Busy: press one">
        <Button busy={busy === "save"} onClick={() => send("save")}>
          Save search
        </Button>
        <Button variant="secondary" busy={busy === "apply"} onClick={() => send("apply")}>
          Apply
        </Button>
      </Row>
      <Row title="Links">
        <p className="w-full text-[15px] leading-[1.6] text-[var(--fu-mute,#BDBDBD)]">
          Free and MIT licensed, from{" "}
          <TextLink href="https://filtersui.com" target="_blank">
            filtersui.com
          </TextLink>
          .
        </p>
        <div className="-ms-1 flex flex-wrap items-center gap-x-5">
          <TextLink variant="quiet" arrow="back" href="#" onClick={stay}>
            All cars
          </TextLink>
          <TextLink variant="quiet" arrow="forward" href="#" onClick={stay}>
            Next page
          </TextLink>
        </div>
      </Row>
    </div>
  );
}
```

## Connect it to my data

Ask me where these buttons and links go. Use Button for actions and set busy while a request runs; use TextLink, or linkClasses and buttonClasses on my router's link component (such as next/link), for anything that has a URL. An action with no URL stays a Button, never a link.

## Keep the look

It is dark by default and needs no setup. To change colours, set these CSS variables on :root or on a parent element. These are the dark defaults:

```css
:root {
  --fu-accent: #3B57E6;
  --fu-accent-hover: #3450D4;
  --fu-accent-pale: #D1DDFF;
  --fu-accent-soft: #8FAAFF;
  --fu-dim: #929292;
  --fu-hover: #333333;
  --fu-hover-wash: rgb(255 255 255/0.14);
  --fu-link-line: rgb(143 170 255/0.4);
  --fu-mute: #BDBDBD;
  --fu-on-accent: #FFFFFF;
  --fu-surface-1: #171717;
  --fu-surface-3: #2A2A2A;
  --fu-text: #F8F5F1;
}
```

To turn on the light theme, set these values under this project's own light selector (written as .light here). If it has none, put them on :root inside @media (prefers-color-scheme: light).

```css
.light {
  --fu-accent: #3B57E6;
  --fu-accent-hover: #2F4AD0;
  --fu-accent-pale: #253A9E;
  --fu-accent-soft: #3049D2;
  --fu-dim: #555552;
  --fu-hover: rgb(29 27 24/0.11);
  --fu-hover-wash: rgb(29 27 24/0.07);
  --fu-link-line: rgb(52 80 216/0.4);
  --fu-mute: #444442;
  --fu-on-accent: #FFFFFF;
  --fu-surface-1: #FFFFFF;
  --fu-surface-3: rgb(29 27 24/0.07);
  --fu-text: #1B1B19;
}
```

Keep the sizes, corners, spacing and motion as they are.

## Direction and language

It lays out with start and end, so it works on a right-to-left page or inside any element with dir="rtl": arrows, bars, charts and the arrow keys follow. Keep the start and end classes; do not swap them for left and right.

## Keep the accessibility

- A busy button carries aria-busy and stays focusable; it is never disabled.
- IconButton requires a label; icons are hidden from screen readers.
- Focus shows a 2px outline that survives forced colours mode; filled buttons gain a border there.
- Buttons and links are native: Tab reaches them, Enter or Space presses a button, Enter follows a link.
- A busy button keeps its place in the tab order.

When done, run the app, tell me which page to open, and show me it working.

What it does

  • Primary, secondary, ghost and quiet looks in 32, 40 and 44px, all with 10px corners and the same press and focus ring.
  • Busy never greys a button out: it keeps its colour, width and focus, ignores presses and swaps its label for a spinner.
  • Inline links are always underlined, so colour is never their only mark; quiet links suit navigation and back links.
  • A link that opens a new tab gets a small up-right arrow and says so to screen readers.

Keyboard

  • Buttons and links are native: Tab reaches them, Enter or Space presses a button, Enter follows a link.
  • A busy button keeps its place in the tab order.

Props

Value. None. Set busy while a request runs.

Button props
PropDescription
variant
Default "primary"

Accent fill, grey fill, no fill with a wash on hover, or muted text that lights up (accent text for quiet-accent).

"primary" | "secondary" | "ghost" | "quiet" | "quiet-accent"
size
Default "md"

32, 40 or 44px high. sm and md grow their tap area to 44px on touch screens.

"sm" | "md" | "lg"
before / after
Optional

An icon before or after the label, drawn in currentColor.

ReactNode
busy
Default false

Presses do nothing; after 150ms a spinner takes the label's place for at least 400ms. The button keeps its focus and width.

boolean
IconButton label
Required

IconButton: the accessible name of an icon-only button, e.g. "Copy link".

string
TextLink variant
Default "inline"

TextLink: "inline" for a link in a sentence (accent, underlined), "quiet" for navigation (muted, no underline).

"inline" | "quiet"
TextLink arrow
Optional

TextLink: a chevron that nudges 2px its way on hover.

"forward" | "back"
buttonClasses / linkClasses
Optional

The same looks as class names (ui/button-classes.ts, ui/link.tsx), for a router link such as next/link, or a server component.

(style) => string

Related