# Button

Press, loading, success and disabled states.

Access: free. Category: Essentials. Kind: primitive.

## When to use

- Use it when a product interface needs press, loading, success and disabled states.
- Choose it when the host application can supply the required state and keep business logic outside the presentation component.

## Alternatives

- Choose button-group instead when a labelled cluster of native button actions with shared separator geometry, horizontal or vertical orientation, and narrow wrapping is the actual interface need, rather than button.

## Setup for agents

Use React 19 and TypeScript. Initialize shadcn for your framework, then merge this exact entry into components.json:

```json
{
  "registries": {
    "@tidal-pro": {
      "url": "https://tidalui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TIDALUI_TOKEN}"
      }
    }
  }
}
```

The namespace must be named **@tidal-pro** because transitive Pro dependencies use that namespace. Obtain an agent key from your active Pro account at https://tidalui.com/account. Keep TIDALUI_TOKEN in your local environment, never in components.json, client code, Git or logs.

```sh
export TIDALUI_TOKEN='your-private-agent-key'
npx shadcn@latest add @tidal-pro/waitlist-form
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Free command: `npx shadcn@latest add https://tidalui.com/r/<name>.json`.
Pro command: `npx shadcn@latest add @tidal-pro/<name>`.

Import the base stylesheet and every stylesheet listed on the installed item's metadata. For example:

```tsx
import "./components/ui/tidal.css";
import "./components/ui/hero-section.css";
// Place installed components inside this wrapper:
<div className="tidal-scope" data-theme="dark">...</div>
```

Omit data-theme for the default light theme. Put the attribute on the same tidal-scope element for dark mode. Every component installs the shared free tidal-base dependency. After upgrading, run `npx shadcn@latest add https://tidalui.com/r/tidal-base.json --overwrite` to receive current tokens. Review local modifications before overwriting.

Vite: Use React + TypeScript. Map @/* to ./src/* in paths and Vite resolve.alias. Import tidal.css and each component stylesheet in your application entry.

Next.js 15 App Router: Next.js App Router: import tidal.css and component CSS in app/layout.tsx. Interactive examples belong in a client component with "use client". Map @/* to ./* or ./src/* to match your project.

TypeScript 6: use paths without baseUrl:

```json
{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}
```

Pro registry requests are server/CLI-only. Use the same-origin account interface in a browser; cross-origin Authorization preflights are intentionally unsupported.


## Install Button

```sh
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Stylesheets: `components/ui/tidal.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import{TidalButton}from"./components/ui/tidal-button";
export default()=><div className="tidal-scope"><TidalButton/></div>;
```

## Structured props

- `TidalButton.loading?: boolean | undefined` (default false): Optional loading value accepted by this exported component.
- `TidalButton.variant?: "primary" | "secondary" | "ghost" | undefined` (default "primary"): Optional variant value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/tidal-button.tsx) | [Manifest](https://tidalui.com/examples/tidal-button.json). Install the listed additional dependencies. Consumer fixture: TypeScript pass; Vite pass. This fixture check is distinct from the actual shadcn install receipt.

```tsx
import "./components/ui/tidal.css";

import { useState, useRef, useEffect, useLayoutEffect } from "react";

import { ArrowUpRight, Check, Plus } from "lucide-react";

import { TidalButton } from "./components/ui/tidal-button";



const tidalExampleStyles = ".button-specimen{width:100%;max-width:320px;background:linear-gradient(150deg,var(--t-surface),var(--t-subtle));border:1px solid var(--t-border);border-radius:18px;padding:18px;box-shadow:0 10px 20px -10px #0000001a,0 1px 2px #00000008}\n.button-arrangement{display:flex;justify-content:center;align-items:center;flex-wrap:wrap;gap:8px;padding:23px 0 18px}\n.button-arrangement .tidal-button{font-size:10px;padding:0 12px}\n.specimen-bottomline{display:flex;align-items:center;justify-content:space-between;font-size:8px;color:var(--t-muted);gap:6px}\n.specimen-bottomline kbd{font:11px ui-monospace,monospace;border:1px solid var(--t-border);border-radius:5px;padding:3px 5px;color:var(--t-muted);white-space:nowrap}";

export function ButtonDemo() {
  const [state, setState] = useState<"idle" | "loading" | "saved">("idle");
  const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
  const saveButton = useRef<HTMLButtonElement>(null);
  const focusOwner = useRef<HTMLElement | null>(null);
  useEffect(() => () => clearTimeout(timer.current), []);
  useLayoutEffect(() => {
    if (state !== "saved" || !focusOwner.current) return;
    const active = document.activeElement;
    if (active === document.body || active === focusOwner.current)
      saveButton.current?.focus({ preventScroll: true });
    focusOwner.current = null;
  }, [state]);
  function reset() {
    clearTimeout(timer.current);
    setState("idle");
  }
  return (
    <div className="button-specimen">
      <div className="button-arrangement">
        <TidalButton
          ref={saveButton}
          loading={state === "loading"}
          onClick={(event) => {
            clearTimeout(timer.current);
            focusOwner.current = event.currentTarget;
            setState("loading");
            timer.current = setTimeout(() => setState("saved"), 650);
          }}
        >
          {state === "saved" ? <Check size={16} /> : null}
          {state === "saved" ? "Changes saved" : "Save changes"}
        </TidalButton>
        <TidalButton variant="secondary" onClick={reset}>
          Reset <ArrowUpRight size={16} />
        </TidalButton>
        <TidalButton
          variant="ghost"
          onClick={() => {
            clearTimeout(timer.current);
            setState("saved");
          }}
        >
          <Plus size={16} />
          Add to project
        </TidalButton>
      </div>
      <div className="specimen-bottomline">
        <span>Hover and press.</span>
        <kbd>↵</kbd>
      </div>
    </div>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <ButtonDemo />
    </div>
  );
}

```

## Gotchas

- Install the declared registry dependencies and render inside a tidal-scope with the foundation stylesheet loaded.

## Theme and accessibility

{"tokens":["--t-accent","--t-border","--t-border-strong","--t-canvas","--t-danger","--t-display","--t-ease-out","--t-ease-spring","--t-faint","--t-font","--t-ink","--t-line","--t-muted","--t-primary","--t-primary-contrast","--t-radius-card","--t-radius-control","--t-radius-overlay","--t-radius-panel","--t-ring","--t-shadow-lg","--t-shadow-soft","--t-soft","--t-subtle","--t-surface","--t-wash"],"darkMode":true}

{"keyboard":["Tab and Shift+Tab follow the component's native focus order."],"aria":"The component wires labels and relationships from consumer-provided visible text or ARIA props; preserve those labels in production.","notes":"Verify focus visibility, text alternatives, contrast, and reduced motion in the final composition."}

Native button props; variant: primary | secondary | ghost; loading: boolean
