# Ink Theme Toggle

Switches day and night: the new theme spreads from the button like a drop of ink, and the pen swaps sun for moon.

Docs: https://ballpoint.st9wd.com/docs/ink-theme-toggle

```bash
npx shadcn@latest add @ballpoint/ink-theme-toggle
```

```tsx
import { InkThemeToggle } from "@/components/ui/ink-theme-toggle"

// On its own: toggles .dark on <html> and remembers it.
<InkThemeToggle />

// With next-themes:
const { resolvedTheme, setTheme } = useTheme()
<InkThemeToggle theme={resolvedTheme} onThemeChange={setTheme} />
```

Props:

- `theme`: `"light" | "dark"`. The current theme, when a theme library manages it.
- `onThemeChange`: `(theme: "light" | "dark") => void`. Called with the new theme, inside the view transition, so the blot reveals it.
- `storageKey`: `string` (default `"theme"`). Where the choice is kept in localStorage when the toggle manages the theme itself.
- `…`: `Button's`. Any other Button prop (variant, size, seed).

## Example

```tsx
import { InkThemeToggle } from "@/components/ui/ink-theme-toggle";

export default function InkThemeToggleDemo() {
  return (
    <div className="flex flex-col items-center gap-3">
      <InkThemeToggle seed="theme-toggle-demo" />
      <p className="text-sm text-ink-3">Night spreads from the button like a drop of ink.</p>
    </div>
  );
}
```

## Controlled

Own the theme (or hand it to next-themes) and the toggle only reports clicks.

```tsx
"use client";

import { useState } from "react";
import { InkThemeToggle } from "@/components/ui/ink-theme-toggle";

// Theme owned by you (or by next-themes): the toggle only reports clicks.
// This copy is a local pretend, so the page itself doesn't change.
export default function InkThemeToggleControlled() {
  const [theme, setTheme] = useState<"light" | "dark">("light");
  return (
    <div className="flex flex-col items-center gap-3">
      <InkThemeToggle theme={theme} onThemeChange={setTheme} variant="outline" seed="ttc-toggle" />
      <p className="text-sm text-ink-3">
        Your state says <span className="font-bold text-ink">{theme}</span>.
      </p>
    </div>
  );
}
```

## In a header

A ghost icon button at the end of a nav bar, where it usually lives.

```tsx
import { Button } from "@/components/ui/button";
import { InkThemeToggle } from "@/components/ui/ink-theme-toggle";

export default function InkThemeToggleHeader() {
  return (
    <header className="flex w-full max-w-lg items-center justify-between gap-6 border-b border-ink-4 pb-3">
      <span className="text-xl font-bold">Field notes</span>
      <nav aria-label="Main" className="flex items-center gap-1">
        <Button variant="ghost" size="sm" seed="ith-docs">
          Pages
        </Button>
        <Button variant="ghost" size="sm" seed="ith-about">
          About
        </Button>
        <InkThemeToggle variant="ghost" size="icon-sm" seed="ith-toggle" />
      </nav>
    </header>
  );
}
```
