# Appearance Menu

> The look menu at the end of the top bar: theme (auto, light, dark), brand colour, density (auto, roomy, compact), motion (normal, lively, off), glass surfaces and, with both kits, the kit.

Component · Navigation · Pro kit · [Live page](https://ui.twentyfirst.media/pro/components/AppearanceMenu/)

The look menu at the end of the top bar: theme (auto, light, dark), brand colour, density (auto,
roomy, compact), motion (normal, lively, off), glass surfaces and, with both kits, the kit. Behind
a sun or a moon, as in the standard app frame. On phones it opens as a bottom sheet.

- Put `AppearanceProvider` around the app instead of `UIProvider`: it applies the choice and keeps
  it in this browser (`storageKey`, default `"tf-appearance"`). It takes every `UIProvider` prop
  (`locale`, `messages`, `floating` …) and `kits={["halo", "pro"]}` when both kits are loaded
  (`themes.css`); then the menu shows the style row.
- `appearanceScript(storageKey)` in `<head>` puts the stored look on `<html>` before the first
  paint, so a reload does not flash.
- Per account instead of per browser: `initial` (the stored value), `onChange(next, patch)` (save
  it), `storageKey={false}`, and `hint="Saved for your account"` on the menu.
- Brand colour: the kit's own primary ("Default"), the six `THEME_PRESETS` (blue, violet, emerald,
  orange, rose, teal) or a custom colour from the colour picker, which goes through `brandTheme`.
  The value (`brand`: a preset key or a hex colour) is part of the stored look and of
  `appearanceScript`, so the colour is there before the first paint too.
- Hovering a choice previews it before it is picked (`onPreview(patch)`, `null` when the pointer
  leaves); inside an `AppearanceProvider` the app shows the preview without storing it.
- With glass on, `AppearanceProvider` paints an `Ambient` behind the app so the glass has something
  to show; `ambient={{ colors: [...] }}` or `ambient={{ src: "/backdrop.jpg" }}` sets your own,
  `ambient={false}` leaves the background to you.
- `rows` picks the rows (`"kit"`, `"theme"`, `"brand"`, `"density"`, `"motion"`, `"surface"`);
  leave out `"brand"` for an app with a fixed brand colour. `value` and `onChange` work without a
  provider (controlled: store the choice per user on your server). `useAppearance()` gives the
  state for your own menu.
- `sheet={false}` keeps the popover on phones. In `AppShell`, `appearance` (or
  `appearance={{ hint: "Saved for your account" }}`) puts the menu at the end of the top bar.
- Kit and theme changes cross-fade where the browser supports view transitions and motion is on.

```tsx
// app/layout.tsx
<head>
  <script dangerouslySetInnerHTML={{ __html: appearanceScript() }} />
</head>
<body>
  <AppearanceProvider kits={["halo", "pro"]} floating="solid">{children}</AppearanceProvider>
</body>

// in the AppShell
<AppShell navigation="sidebar" topbar appearance … />
```

## Example

```tsx
import * as React from "react";
import { AppearanceMenu, AppearanceProvider, useUI } from "@twentyfirstmedia/pro";

export default function Preview() {
  // In an app: <AppearanceProvider kits={["halo", "pro"]}> once around everything, and the menu
  // at the end of the top bar. Here it starts in the docs' kit and theme and keeps the choice.
  const ui = useUI();
  const [open, setOpen] = React.useState(true);
  return (
    <AppearanceProvider
      key={`${ui.kit}-${ui.theme}`}
      scope="subtree"
      storageKey={false}
      kits={["halo", "pro"]}
      defaults={{ kit: ui.kit, theme: ui.theme === "dark" ? "dark" : "light" }}
    >
      <div
        // overflow: on the narrowest docs pages the menu is wider than the preview box; in an app
        // the menu opens as a bottom sheet on phones, here it stays a popover
        style={{
          display: "flex",
          alignItems: "flex-end",
          justifyContent: "flex-end",
          minHeight: 520,
          overflow: "hidden",
        }}
      >
        <AppearanceMenu side="top" open={open} onOpenChange={setOpen} sheet={false} />
      </div>
    </AppearanceProvider>
  );
}
```

## Props

### AppearanceMenu

| Prop | Type | Notes |
| --- | --- | --- |
| `value?` | `Appearance` | The current look; without it the menu reads and writes the nearest `AppearanceProvider`. |
| `onChange?` | `(patch: Partial<Appearance>) => void` |  |
| `kits?` | `Kit[]` | Kits to choose from; with two or more the menu shows the Style row. |
| `rows?` | `AppearanceRow[]` | The rows to show (default: style when there are kits, theme, colour, density, motion and glass). Leave `"brand"` out for an app with a fixed brand colour. |
| `onPreview?` | `(patch: Partial<Appearance> \| null) => void` | While the reader hovers a choice (or drags the custom colour), before it is picked; `null` when the pointer leaves. Without it the menu previews through the nearest `AppearanceProvider`. |
| `sheet?` | `boolean` | On phones the menu opens as a bottom sheet (default true). |
| `hint?` | `ReactNode` | Under the title, e.g. "Saved for your account" (default "Saved on this device"). |
| `align?` | `"start" \| "end"` | Which edge of the trigger the menu lines up with (default `end`, for the top bar's end). |
| `side?` | `"top" \| "bottom"` | Opens below the trigger (default) or above it. |
| `open?` | `boolean` | Controls whether the menu is open (e.g. to show it open in a tour). |
| `onOpenChange?` | `(open: boolean) => void` |  |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |
