# Styles

A style draws the components: their shape, type, density and motion. The user picks it beside the theme, and no style may move what keeps a screen usable.

API [Theme](/ui/storybook/?path=/docs/ui-foundations-theme--docs) [ThemeMenu](/ui/storybook/?path=/docs/ui-thememenu--docs) [Card](/ui/storybook/?path=/docs/ui-primitives-card--docs) [EmptyState](/ui/storybook/?path=/docs/ui-emptystate--docs) [Kbd](/ui/storybook/?path=/docs/ui-primitives-kbd--docs) [LinkCard](/ui/storybook/?path=/docs/ui-primitives-linkcard--docs) [GroupHeading](/ui/storybook/?path=/docs/ui-primitives-groupheading--docs) [List](/ui/storybook/?path=/docs/ui-primitives-list--docs) [NavList](/ui/storybook/?path=/docs/ui-primitives-navlist--docs) [Pane](/ui/storybook/?path=/docs/ui-primitives-pane--docs) [SegmentedControl](/ui/storybook/?path=/docs/ui-primitives-segmentedcontrol--docs) [Toggle](/ui/storybook/?path=/docs/ui-primitives-toggle--docs) [Separator](/ui/storybook/?path=/docs/ui-primitives-separator--docs) [TabNav](/ui/storybook/?path=/docs/ui-primitives-tabnav--docs) [Table](/ui/storybook/?path=/docs/ui-primitives-table--docs) [Tree](/ui/storybook/?path=/docs/ui-primitives-tree--docs) [Toolbar](/ui/storybook/?path=/docs/ui-toolbar--docs) [CodeEditor](/ui/storybook/?path=/docs/ui-codemirror-codeeditor--docs)

**Leave how the components are drawn to the style, and build every surface of your own from the same components and tokens, so a style the user picks redraws it too.** A theme says what colour each role is; a style says what shape it takes. Together they are the look, and both are the user's.

```tsx
import { Button } from "@orz/ui/components/button";
import {
  Card,
  CardContent,
  CardHeader,
  CardTitle,
} from "@orz/ui/components/card";
import { Checkbox } from "@orz/ui/components/checkbox";
import { FrameBar } from "@orz/ui/components/frame";
import { Input } from "@orz/ui/components/input";
import { Label } from "@orz/ui/components/label";
import {
  SegmentedControl,
  SegmentedControlItem,
} from "@orz/ui/components/segmented-control";
import {
  Tabs,
  TabsContent,
  TabsList,
  TabsTrigger,
} from "@orz/ui/components/tabs";
import { useStyle } from "@orz/ui/theme";
import { FilterIcon } from "lucide-react";

export function StyleSwitch() {
  const { committed, styles, setStyle } = useStyle();
  return (
    <div className="grid gap-4">
      <SegmentedControl
        aria-label="Style"
        value={committed}
        onValueChange={setStyle}
        className="justify-self-start"
      >
        {styles.map(({ id, label }) => (
          <SegmentedControlItem key={id} value={id}>
            {label}
          </SegmentedControlItem>
        ))}
      </SegmentedControl>
      <Card className="max-w-md">
        <CardHeader icon={<FilterIcon />}>
          <CardTitle>New filter</CardTitle>
        </CardHeader>
        <CardContent className="grid gap-3">
          <Tabs variant="framed" defaultValue="match">
            <FrameBar>
              <TabsList>
                <TabsTrigger value="match">Match</TabsTrigger>
                <TabsTrigger value="action">Action</TabsTrigger>
              </TabsList>
            </FrameBar>
            <TabsContent value="match" className="grid gap-2 p-3">
              <Label htmlFor="style-switch-from">From</Label>
              <Input id="style-switch-from" defaultValue="bot-one" />
            </TabsContent>
            <TabsContent value="action" className="flex items-center gap-2 p-3">
              <Checkbox id="style-switch-archive" defaultChecked />
              <Label htmlFor="style-switch-archive">Skip the Inbox</Label>
            </TabsContent>
          </Tabs>
          <div className="flex justify-end gap-2">
            <Button variant="outline">Cancel</Button>
            <Button>Create filter</Button>
          </div>
        </CardContent>
      </Card>
    </div>
  );
}
```

The buttons above call `setStyle`, and the whole page redraws, this text included: the card's header, the tabs, the field and the buttons change their corners, edges, type and height, and the site's own chrome follows, because it is built from the same components. Pick a style in the top bar's theme menu for the same.

## What a style changes

A style is the tokens `@orz/ui`'s components read for everything but colour, and the look each component carries for it where a token cannot draw it:

- **Shape.** Corner radii, and how an edge is drawn: a 1px rule, or the two-tone bevel a Windows 2000 button has.
- **Depth.** Whether surfaces cast shadows, and what lifts a menu or a dialog above the page: a light shadow under each layer, or a raised bevel.
- **Type.** The families, the size of body text and each step of the scale.
- **Density at a pointer.** The height of a control and of a row, and the padding inside them.
- **Focus.** How the focus indicator is drawn: a solid ring, or a dotted rectangle.
- **State.** How a selected row, a highlighted menu item and the current tab are told apart.
- **Motion.** How long an overlay takes to arrive, and whether it fades, zooms or slides.
- **Its own colours.** A style may ask its themes for colour tokens beyond the shared ones, such as raymond's 3D face and edges and its title bar's gradient.

## What a style never changes

These hold under every style, and outrank it:

- The components' structure, props and behaviour. Code written against one style runs under all of them.
- What a coarse pointer adds: a 36px hit area around every control, neighbouring targets that far apart, and 16px text in a field, so a phone does not zoom. How a part is drawn stays the style's under either pointer ([Touch & mobile](/ui/guidelines/platforms/touch-and-mobile/index.md#hit-areas)).
- The contrast floors: 4.5:1 for text, 3:1 for an edge a control is found by and for a state cue. Every palette a style ships is held to them ([Accessibility](/ui/guidelines/content/accessibility/index.md#contrast)).
- A visible focus indicator, and reduced motion ([Motion](/ui/guidelines/foundations/motion/index.md#reduced-motion)).

## Offering styles

A theme belongs to the styles it lists in `styles`, or to the default style when it lists none, so the user picks a style and then one of its themes.

- **Offer the styles whose stylesheets you import.** `createThemeStore({ styles, defaultStyle })` takes them and starts a new user on `defaultStyle`; without `styles` the store offers the default style alone, and the menu has no Style row. Beside the default style, `@orz/ui` ships raymond, Windows 2000: import `@orz/ui/styles/raymond.css` after `@orz/ui/styles.css`, and offer `raymondStyle` from `@orz/themes`, whose built-in themes include its own. That import is what turns on every part's raymond look, in every package; an app that leaves it out carries none of raymond's CSS. Imported before `@orz/ui/styles.css`, only its colours and sizes apply, and no part is drawn in raymond.
- **Let the user switch.** With more than one style, `ThemeMenu` shows a Style row above the modes, which switches on a click; from code, `setStyle` on the store or from `useStyle()` switches it. Either way the user lands on the theme they last picked under that style, or on its first theme.
- **Hold the user to one style** by offering that one alone. A terminal theme is not tied to a style: terminal output is content, and its own pick shows under any.

## Your own surfaces

A style draws a part by what it is for. The same rows are a menu, a list box or a folder pane depending on what picking one does, and a region is a document to read, a toolbar to act on it, or the window's face around them; each style draws each of those its own way. Say which with `purpose`, or with the component made for it, and the style does the rest:

- **Places to go** are a `NavList`, in a `NavListFrame` when it is a pane of the app's frame, whose groups' toggles raymond draws as a tree view's +/- boxes, a hierarchy the reader opens and closes a `Tree`, which raymond draws as a tree view, or a `TabNav` for a row of sections; see [Navigation](/ui/guidelines/patterns/navigation/index.md).
- **A list** is `List` with `purpose="listbox"` when its rows are things to pick, `"menu"` when they are actions, and `"collection"` when they are things the user keeps, each row carrying its own actions (access tokens with a Revoke button). Mark a list box's rows with `ListItem`'s props, never a fill of your own: the row whose item is open beside the list takes `current`, rows ticked or picked take `selected`, and in a list whose focus stays in a field, as a search box's results, the row the keys are on takes `highlighted`. A style may draw a picked row that shows a ticked checkbox by the tick alone, and keep its highlight for the open one. A list set in the flow of a surface (a card, a sheet, a pane) rather than filling a column, a pull request's commits say, takes `framed` instead of a border of its own. Framed, it is a frame, which never stands on the ground alone: a list there is rows in a `Card` ([Surfaces](/ui/guidelines/foundations/surfaces/index.md)).
- **A table's rows** are marked by `TableRow`'s attributes, never a fill of your own: the row whose details are open beside the table takes `aria-current="true"`, and rows picked for an action take `data-state="selected"`. A style may draw a picked row that shows a ticked checkbox by the tick alone, and keep its highlight for the current one.
- **A region** is `Pane` with `purpose="app"` for the box an app's panes sit side by side in, `"document"` for what is read or written (a message, a diff), `"toolbar"` for the controls that act on it, `"statusbar"` for the line along the foot that says how it stands (a line count, the first error), `"sidebar"` for the column of places to go beside the rest, and `"panel"` for the rest of the window. A window of the app's own that floats over the rest, a docked composer say, is `"window"`, with `docked` naming the edge it sits against, and its caption `"titlebar"`. The bar across the top of a site that its pages scroll under is `"banner"`, which keeps the height you give it, since what sticks below it is offset by that height. The pane draws its own look in every style: name the side that meets its neighbour with `edge` rather than a border of your own. A box that stands on the ground on its own, a module or a comment, is a `Card`; a box set in a pane's flow rather than filling it, a block or a sample, is a `Frame`, its heading line and its closing actions on `FrameBar`s ([Surfaces](/ui/guidelines/foundations/surfaces/index.md)).
- **An editor** is `CodeEditor` or `MarkdownEditor` with `purpose="field"`, the default, when it is one input among others on a form or under a message, and `"document"` when it is the file or text its pane exists to edit and fills that pane, which draws the edges.
- **A row of commands** is a `Toolbar` of `ToolbarButton`s, each named with `aria-label` when it shows an icon alone, and a mode of the tool picked from two or three there is a `SegmentedControl`, which a style may draw as toolbar buttons only one of which stays down. A command with its variants beside it is a `SplitButton`. A tag or filter that is on or off on its own is a `Toggle`, which a style may draw as a toolbar button that stays down.
- **A group of controls' title** on a form or settings screen is a `GroupHeading`; a group that wants a frame of its own is a `Card`. A rule between the group's rows is a `Separator` with `purpose="row"`, and one between groups that space does not set apart keeps the default `"group"`.
- **What stands in an empty list or pane** is an `EmptyState`: its icon, its title, the line under it and the next step, which a style may set in its window text.
- **A docs page's own parts** are components too. The sections of the page in view are a `NavList variant="rail"`, a link to another page with a line on what is there a `LinkCard`, a live sample a block, a `ContentFrame` under a `ContentHeader` whose **Source** shows its file, a table of sentences a `Table purpose="prose"`, and a key to press a `Kbd`. Set the prose itself in the prose scale ([Typography](/ui/guidelines/foundations/typography/index.md)), which a style sizes for itself.

A style redraws these where they stand: it keeps what they hold and in what order, adds nothing you did not write, and may tighten their spacing. So size a toolbar or a header by the padding around its controls rather than a fixed height, and a style's denser controls bring the bar in with them. A `Toolbar` keeps its order too, but how many of its commands fit at a width follows each style's sizes, and the rest wait in its `⋯`: give it an order and priorities, never a breakpoint ([Toolbars](/ui/guidelines/patterns/toolbars/index.md)). A list or pane that scrolls puts its scroller inside, so a style's sunken edge stays drawn around it.

**Do**

Build a panel from `Card`, a toolbar from `Toolbar` and `ToolbarButton`, a list from `List`, its rows at `min-h-row`, and round a part of your own with `rounded-control` or `rounded-surface`. Under another style it changes with everything around it.

**Don't**

Write `rounded-lg`, `h-8` or `shadow-md` on a part of your own, hand-roll a list or a toolbar from bare markup, or style by `[data-style="raymond"]` or `raymond:`. The first two stay as they are when the style changes; the last breaks under every style you did not write it for.

The numbers the other guideline pages give, a row's height or a button's, are the default style's. Another style draws the same parts at its own sizes, and the pages' rules hold for it all the same.

## In the demos

- [Gallery](/ui/demos/gallery/index.md): Pick Raymond in the top bar's theme menu: every tile redraws, its lid, its controls and the viewer inside it, because the gallery draws nothing of its own, only the components.
- [Settings](/ui/demos/settings/index.md): Open Appearance's Theme menu and pick Raymond in its Style row: the whole demo redraws as Windows 2000 from the same components, and Default brings back the theme last picked under it.
