# Principles

The rules the rest of the guidelines follow from. When a page is silent, these decide.

API [NavList](/ui/storybook/?path=/docs/ui-primitives-navlist--docs) [Tooltip](/ui/storybook/?path=/docs/ui-primitives-tooltip--docs) [Toolbar](/ui/storybook/?path=/docs/ui-toolbar--docs) [DropdownMenu](/ui/storybook/?path=/docs/ui-primitives-dropdownmenu--docs) [ConfirmDialog](/ui/storybook/?path=/docs/ui-confirmdialog--docs) [Skeleton](/ui/storybook/?path=/docs/ui-primitives-skeleton--docs) [LoadFailure](/ui/storybook/?path=/docs/ui-loadfailure--docs) [InfoPopover](/ui/storybook/?path=/docs/ui-primitives-infopopover--docs)

## Content first, chrome quiet

**People live in these tools all day; the interface recedes so the work stays in front.**

A log, a diff, a list of cards is what someone opened the app for. Toolbars, borders and badges are there to serve it, so they take the muted colours, the small sizes and the edges of the screen. A tag keeps its own colour, on a light fill: it tells tags apart, and asks for no more attention than the muted colours do. Give emphasis to one thing per view, the action most people came to take, and let everything else stay calm. Every extra border, shadow or colour competes with the content for the same attention.

```tsx
import {
  INBOX_LABEL_COLORS,
  INBOX_PEOPLE,
  INBOX_THREADS,
  type InboxThread,
} from "@orz/fixtures/inbox.ts";
import { Badge } from "@orz/ui/components/badge";
import { Button } from "@orz/ui/components/button";
import { Frame } from "@orz/ui/components/frame";
import { Input } from "@orz/ui/components/input";
import { Pane } from "@orz/ui/components/pane";
import { ToolbarButton } from "@orz/ui/components/toolbar";
import {
  Tooltip,
  TooltipContent,
  TooltipProvider,
  TooltipTrigger,
} from "@orz/ui/components/tooltip";
import { Markdown } from "@orz/ui-markdown";
import { ArchiveIcon, MailIcon, SendIcon, Trash2Icon } from "lucide-react";

const THREAD = INBOX_THREADS.find(
  (thread) => thread.id === "touch-sizes",
) as InboxThread;
const MESSAGE = THREAD.messages.at(-1);

const ACTIONS = [
  { label: "Archive", Icon: ArchiveIcon },
  { label: "Delete", Icon: Trash2Icon },
  { label: "Mark as unread", Icon: MailIcon },
];

export function QuietThread() {
  return (
    <TooltipProvider>
      <Frame asChild>
        <Pane purpose="panel" asChild className="flex flex-col">
          <article>
            <Pane
              purpose="toolbar"
              edge="bottom"
              className="flex items-center gap-0.5 px-2 py-1"
            >
              {ACTIONS.map(({ label, Icon }) => (
                <Tooltip key={label}>
                  <TooltipTrigger asChild>
                    <ToolbarButton size="icon-sm" aria-label={label}>
                      <Icon />
                    </ToolbarButton>
                  </TooltipTrigger>
                  <TooltipContent>{label}</TooltipContent>
                </Tooltip>
              ))}
            </Pane>
            <Pane purpose="document">
              <header className="grid gap-1 px-4 pt-3">
                <h3 className="font-semibold text-prose leading-snug">
                  {THREAD.subject}
                </h3>
                <p className="flex gap-1">
                  {THREAD.labels.map((label) => (
                    <Badge
                      key={label}
                      variant="marker"
                      color={INBOX_LABEL_COLORS[label]}
                    >
                      {label}
                    </Badge>
                  ))}
                </p>
              </header>
              {MESSAGE && (
                <div className="grid gap-1 px-4 py-3">
                  <p className="font-medium text-ui">
                    {INBOX_PEOPLE[MESSAGE.from]}
                  </p>
                  <Markdown className="text-ui">{MESSAGE.body}</Markdown>
                </div>
              )}
            </Pane>
            <Pane purpose="panel" edge="top" asChild className="flex gap-2 p-3">
              <form
                aria-label="Reply"
                onSubmit={(event) => event.preventDefault()}
              >
                <Input aria-label="Reply" placeholder="Reply in markdown…" />
                <Button type="submit">
                  <SendIcon />
                  Send
                </Button>
              </form>
            </Pane>
          </article>
        </Pane>
      </Frame>
    </TooltipProvider>
  );
}
```

A conversation from Mail. The subject and the message carry the weight; the toolbar is ghost icons in the muted colour, the tags are light fills of their own colours, and **Send** is the one filled button.

## Dense with a pointer, generous with a thumb

**One look under every pointer; a coarse one adds the room a thumb needs.**

A mouse can hit a 28px button all day, and a dense screen shows more of the work at once. A thumb cannot, so on a coarse pointer the same components, drawn the same, take that room by themselves: a hit area around each control, space between neighbours, rows tall enough to tap. Write one layout and let the components make the room; do not branch the app on screen width to pass bigger sizes. [Density](/ui/guidelines/foundations/density/index.md) has the sizes and when to step down from them, [Touch & mobile](/ui/guidelines/platforms/touch-and-mobile/index.md) what a coarse pointer adds.

```tsx
import { INBOX_THREADS } from "@orz/fixtures/inbox.ts";
import { Frame } from "@orz/ui/components/frame";
import { Label } from "@orz/ui/components/label";
import { List, ListItem, ListItemSelect } from "@orz/ui/components/list";
import { Pane } from "@orz/ui/components/pane";
import { ToolbarButton } from "@orz/ui/components/toolbar";
import {
  Tooltip,
  TooltipContent,
  TooltipProvider,
  TooltipTrigger,
} from "@orz/ui/components/tooltip";
import { useSelection } from "@orz/ui/hooks/use-selection";
import { ArchiveIcon, MailOpenIcon, Trash2Icon } from "lucide-react";

const INBOX = INBOX_THREADS.filter((thread) => !thread.folder).slice(0, 3);

const ACTIONS = [
  { label: "Archive", Icon: ArchiveIcon },
  { label: "Delete", Icon: Trash2Icon },
  { label: "Mark as read", Icon: MailOpenIcon },
];

export function MailSelection() {
  const selection = useSelection(
    INBOX.map((thread) => thread.id),
    { defaultSelected: INBOX.slice(0, 2).map((thread) => thread.id) },
  );
  return (
    <TooltipProvider>
      <Frame asChild>
        <Pane purpose="panel">
          <Pane
            purpose="toolbar"
            edge="bottom"
            className="flex items-center gap-0.5 px-1.5 py-1"
          >
            <span className="px-2 text-ui tabular-nums">
              {selection.selected.length} selected
            </span>
            {ACTIONS.map(({ label, Icon }) => (
              <Tooltip key={label}>
                <TooltipTrigger asChild>
                  <ToolbarButton aria-label={label}>
                    <Icon />
                  </ToolbarButton>
                </TooltipTrigger>
                <TooltipContent>{label}</TooltipContent>
              </Tooltip>
            ))}
          </Pane>
          <List purpose="listbox" selection={selection}>
            <ul aria-label="Conversations">
              {INBOX.map((thread) => (
                <ListItem key={thread.id} value={thread.id} asChild>
                  <li className="flex min-h-row items-center gap-3 px-3 py-2 touch:min-h-touch">
                    <ListItemSelect id={`selection-${thread.id}`} />
                    <Label
                      htmlFor={`selection-${thread.id}`}
                      className="block min-w-0 flex-1 truncate font-normal"
                    >
                      {thread.subject}
                    </Label>
                  </li>
                </ListItem>
              ))}
            </ul>
          </List>
        </Pane>
      </Frame>
    </TooltipProvider>
  );
}
```

Press **Touch** above the example: nothing is drawn larger, but the toolbar's buttons move apart and its bar makes room for their hit areas, with no change to the code.

## Nothing only on hover

**Every action is reachable by keyboard and by touch.**

Hover is a hint, never the only way in. A row's actions are on screen, or behind a visible `⋯` menu, rather than waiting for a hover that a keyboard and a thumb cannot give. In a control that is one Tab stop, a tree, the `⋯` shows on the current row, the focused one and the one under the pointer, and on every row on a touch screen, and Shift+F10 opens it. A selectable tree's checkbox shows on a row's icon only under the pointer, but it is a shortcut: Space selects from the keyboard, and the row's menu holds **Select** for a thumb and a pointer alike. A tooltip repeats a label the control already carries; it never holds the only copy. Every control can be reached with Tab and used with the keys a native control would take.

```tsx
import { DropdownMenuItem } from "@orz/ui/components/dropdown-menu";
import {
  Toolbar,
  ToolbarButton,
  ToolbarOverflow,
} from "@orz/ui/components/toolbar";
import {
  ArchiveIcon,
  ForwardIcon,
  LinkIcon,
  MailIcon,
  Trash2Icon,
} from "lucide-react";

const ACTIONS = [
  { label: "Archive", key: "E", Icon: ArchiveIcon },
  { label: "Delete", key: "#", Icon: Trash2Icon },
  { label: "Mark as unread", key: "Shift U", Icon: MailIcon },
];

export function ReachableActions() {
  return (
    <Toolbar aria-label="Thread actions" overflowAlign="start" className="p-0">
      {ACTIONS.map(({ label, key, Icon }) => (
        <ToolbarButton key={label} aria-label={label} shortcut={key}>
          <Icon />
        </ToolbarButton>
      ))}
      <ToolbarOverflow contentClassName="w-44">
        <DropdownMenuItem>
          <ForwardIcon /> Forward
        </DropdownMenuItem>
        <DropdownMenuItem>
          <LinkIcon /> Copy link
        </DropdownMenuItem>
      </ToolbarOverflow>
    </Toolbar>
  );
}
```

Tab to Mail's thread toolbar and walk it with the arrow keys: the bar is one Tab stop. Each tooltip opens on focus as it does on hover, and repeats the button's name with its shortcut; **More actions** opens with Enter or Space.

## A place is a link

**Whatever has an address is an `a[href]`; the app takes over a plain click and no other.**

A folder, a section, a file, an open item: anything the reader can go to has a URL, and the control that goes there is a link to it. The browser then does the rest by itself. A middle click or ⌘/Ctrl-click opens it in a new tab, Shift-click in a new window, the context menu copies its address, and hovering it shows where it leads. A `button` that calls the router does none of that. An app that moves in place keeps the link and takes over only the plain left click, through its router's link passed with `asChild` or `isPlainClick` from `@orz/ui/lib/link`.

What acts rather than goes stays a button: Archive, Save, a menu's trigger. So does picking a row in a list box, which chooses in place, and a place held only in app state, with no address to give; a hash (`#profile`) is often address enough to make it a link. [Navigation](/ui/guidelines/patterns/navigation/index.md) has the components.

```tsx
import {
  NavList,
  NavListCount,
  NavListFrame,
  NavListItem,
  NavListLink,
} from "@orz/ui/components/nav-list";
import { Pane } from "@orz/ui/components/pane";
import { isPlainClick } from "@orz/ui/lib/link";
import {
  ArchiveIcon,
  FileTextIcon,
  InboxIcon,
  type LucideIcon,
  SendIcon,
} from "lucide-react";
import { useState } from "react";

const MAIL = `${import.meta.env.BASE_URL}demos/mail/`;

const FOLDERS: { query: string; title: string; Icon: LucideIcon }[] = [
  { query: "in:inbox", title: "Inbox", Icon: InboxIcon },
  { query: "in:sent", title: "Sent", Icon: SendIcon },
  { query: "in:drafts", title: "Drafts", Icon: FileTextIcon },
  { query: "in:archive", title: "Archive", Icon: ArchiveIcon },
];

export function MailFolders() {
  const [open, setOpen] = useState("in:inbox");
  return (
    <Pane purpose="sidebar" className="w-56 p-2">
      <NavListFrame asChild>
        <nav aria-label="Folders">
          <NavList>
            {FOLDERS.map(({ query, title, Icon }) => (
              <NavListItem key={query}>
                <NavListLink
                  href={`${MAIL}?q=${query}`}
                  current={query === open}
                  onClick={(event) => {
                    // Every other click is the browser's: a new tab, a new window, a menu.
                    if (!isPlainClick(event)) return;
                    event.preventDefault();
                    setOpen(query);
                  }}
                >
                  <Icon />
                  {title}
                  {query === "in:inbox" && <NavListCount>8</NavListCount>}
                </NavListLink>
              </NavListItem>
            ))}
          </NavList>
        </nav>
      </NavListFrame>
    </Pane>
  );
}
```

Click a folder and it opens here, as an app's would. Middle-click it, or open it from the context menu, and Mail opens on that folder in a new tab.

## Undo over confirm

**Confirm only what cannot be undone.**

A confirmation dialog asks a question people learn to answer without reading. For an action that can be taken back, act at once and offer **Undo** in a toast. Keep the dialog for the few that cannot: deleting what no one can restore, sending what cannot be unsent. Then name the thing and the consequence, and make the destructive button say what it does.

```tsx
import { type AccessToken, TOKENS } from "@orz/fixtures/account.ts";
import { INBOX_THREADS, type InboxThread } from "@orz/fixtures/inbox.ts";
import { Button } from "@orz/ui/components/button";
import { ConfirmDialog } from "@orz/ui/components/confirm-dialog";
import { List, ListItem } from "@orz/ui/components/list";
import { KeyRoundIcon, MailIcon } from "lucide-react";
import { useState } from "react";
import { toast } from "sonner";

const THREAD = INBOX_THREADS.find(
  (thread) => thread.id === "release-0-9",
) as InboxThread;
const TOKEN = TOKENS[0] as AccessToken;

export function UndoOrConfirm() {
  const [archived, setArchived] = useState(false);
  const [revoked, setRevoked] = useState(false);
  const [confirming, setConfirming] = useState(false);
  return (
    <div className="text-ui">
      <List purpose="collection">
        <ul>
          <ListItem asChild>
            <li className="flex min-h-row items-center gap-2 py-1">
              <MailIcon className="size-4 shrink-0 text-muted-foreground" />
              <span className="min-w-0 flex-1 truncate">
                {THREAD.subject}
                {archived && (
                  <span className="text-muted-foreground"> · Archived</span>
                )}
              </span>
              <Button
                variant="outline"
                size="sm"
                disabled={archived}
                onClick={() => {
                  setArchived(true);
                  toast("Conversation archived", {
                    action: {
                      label: "Undo",
                      onClick: () => setArchived(false),
                    },
                  });
                }}
              >
                Archive
              </Button>
            </li>
          </ListItem>
          <ListItem asChild>
            <li className="flex min-h-row items-center gap-2 py-1">
              <KeyRoundIcon className="size-4 shrink-0 text-muted-foreground" />
              <span className="min-w-0 flex-1 truncate">
                <span className="font-mono">{TOKEN.name}</span>
                {revoked && (
                  <span className="text-muted-foreground"> · Revoked</span>
                )}
              </span>
              <Button
                variant="destructive"
                size="sm"
                disabled={revoked}
                aria-label={`Revoke ${TOKEN.name}`}
                onClick={() => setConfirming(true)}
              >
                Revoke…
              </Button>
            </li>
          </ListItem>
        </ul>
      </List>
      <ConfirmDialog
        open={confirming}
        onOpenChange={setConfirming}
        title={`Revoke the token for ${TOKEN.name}?`}
        description="Anything that signs in with it stops working at once. A revoked token cannot be restored: you would create a new one and update everything that used the old."
        confirmLabel="Revoke"
        destructive
        onConfirm={() => {
          setRevoked(true);
          setConfirming(false);
          toast(`Revoked the token for ${TOKEN.name}`);
        }}
      />
    </div>
  );
}
```

Archive the conversation: it goes at once, and **Undo** in the toast brings it back. Revoking the token cannot be taken back, so Settings asks first, and names the token and what stops working.

## The theme is the user's

**No hard-coded colours; every surface reads the tokens.**

People pick a theme to read comfortably, in a dark room, in sunlight, with low vision. An app that writes `#fff` or `text-gray-500` breaks that choice in one place and nobody notices until a user in a dark theme does. Draw with the [colour tokens](/ui/guidelines/foundations/color/index.md), and let [theming](/ui/guidelines/foundations/theming/index.md) do the rest.

```tsx
import { CI_RUN } from "@orz/fixtures/ci-run.ts";
import { Badge } from "@orz/ui/components/badge";
import {
  Card,
  CardAction,
  CardContent,
  CardHeader,
  CardTitle,
} from "@orz/ui/components/card";
import { InlineCode } from "@orz/ui/components/inline-code";
import { List, ListItem } from "@orz/ui/components/list";
import { CircleCheckIcon, CircleXIcon } from "lucide-react";

export function ThemedChecks() {
  return (
    <Card>
      <CardHeader>
        <CardTitle className="min-w-0 flex-1 truncate">
          {CI_RUN.workflow} #{CI_RUN.id}
        </CardTitle>
        <CardAction>
          <InlineCode>{CI_RUN.branch}</InlineCode>
          <Badge intent="danger">
            <CircleXIcon /> Failed
          </Badge>
        </CardAction>
      </CardHeader>
      <CardContent className="px-0">
        <List purpose="collection">
          <ul className="text-ui">
            {CI_RUN.jobs.map((job) => (
              <ListItem key={job.id} asChild>
                <li className="flex min-h-row items-center gap-2 px-3 py-1.5">
                  {job.status === "failed" ? (
                    <CircleXIcon
                      aria-label="failed"
                      className="size-4 shrink-0 text-destructive"
                    />
                  ) : (
                    <CircleCheckIcon
                      aria-label="passed"
                      className="size-4 shrink-0 text-success"
                    />
                  )}
                  <span className="flex-1">{job.name}</span>
                  <span className="text-muted-foreground text-ui-sm tabular-nums">
                    {job.duration}s
                  </span>
                </li>
              </ListItem>
            ))}
          </ul>
        </List>
      </CardContent>
    </Card>
  );
}
```

The checks of a pull request's CI run, drawn only with tokens. Pick another theme from the site's theme menu, light or dark, and every surface, border and status colour follows.

## Say what happened

**Loading, empty, failed and done each look different and say so.**

A blank area could mean any of four things, and the user should never have to guess which. Loading shows the shape of what is coming; empty says there is nothing yet and how to add something; failed says what went wrong and offers a retry; done says so once, briefly, and gets out of the way. A state that cannot be told apart from another is a bug.

```tsx
import { INBOX_PEOPLE, INBOX_THREADS } from "@orz/fixtures/inbox.ts";
import { Button } from "@orz/ui/components/button";
import { EmptyState } from "@orz/ui/components/empty-state";
import { FrameBar } from "@orz/ui/components/frame";
import { List, ListItem } from "@orz/ui/components/list";
import { LoadFailure } from "@orz/ui/components/load-failure";
import { Skeleton } from "@orz/ui/components/skeleton";
import {
  Tabs,
  TabsContent,
  TabsList,
  TabsTrigger,
} from "@orz/ui/components/tabs";
import { FileTextIcon, SquarePenIcon } from "lucide-react";
import { useState } from "react";

const DRAFTS = INBOX_THREADS.filter((thread) => thread.folder === "drafts");

export function MailStates() {
  const [retrying, setRetrying] = useState(false);
  return (
    <Tabs variant="framed" defaultValue="loading">
      <FrameBar>
        <TabsList>
          <TabsTrigger value="loading">Loading</TabsTrigger>
          <TabsTrigger value="empty">Empty</TabsTrigger>
          <TabsTrigger value="failed">Failed</TabsTrigger>
          <TabsTrigger value="loaded">Loaded</TabsTrigger>
        </TabsList>
      </FrameBar>
      <TabsContent
        value="loading"
        className="grid min-h-36 content-start gap-4 p-4"
      >
        {[0, 1].map((row) => (
          <div key={row} className="grid gap-1.5">
            <Skeleton className="h-3 w-24" />
            <Skeleton className="h-4 w-56 max-w-full" />
          </div>
        ))}
      </TabsContent>
      <TabsContent value="empty" className="min-h-36 px-4 py-6">
        <EmptyState
          icon={FileTextIcon}
          title="Nothing in Drafts"
          action={
            <Button variant="outline">
              <SquarePenIcon data-icon="inline-start" /> Compose
            </Button>
          }
        >
          A message you close without sending waits here.
        </EmptyState>
      </TabsContent>
      <TabsContent value="failed" className="min-h-36 p-4">
        <LoadFailure
          message="Couldn't load Drafts."
          detail="503 Service Unavailable"
          retrying={retrying}
          onRetry={() => {
            setRetrying(true);
            setTimeout(() => setRetrying(false), 800);
          }}
        />
      </TabsContent>
      <TabsContent value="loaded" className="min-h-36 p-2">
        <List purpose="listbox">
          <ul aria-label="Drafts">
            {DRAFTS.map((draft) => (
              <ListItem key={draft.id} asChild>
                <li className="grid min-h-row gap-0.5 px-2.5 py-2">
                  <span className="text-muted-foreground text-ui-sm">
                    <span className="font-medium text-foreground">Draft</span>{" "}
                    To:{" "}
                    {draft.messages
                      .at(-1)
                      ?.to?.map((login) => INBOX_PEOPLE[login] ?? login)
                      .join(", ")}
                  </span>
                  <span className="truncate text-ui">{draft.subject}</span>
                </li>
              </ListItem>
            ))}
          </ul>
        </List>
      </TabsContent>
    </Tabs>
  );
}
```

Mail's Drafts in each state. Done is the toast under **Undo over confirm** above: one line, and gone again.

## Shown, not told

**The interface says nothing it already shows; an explanation waits behind (i).**

A label, a control's state, a Save button that is there or is not: the screen already tells the reader most of what a sentence under it would. Write that sentence anyway and every row grows a line of grey text the reader learns to skip, taking the one line that mattered with it. So no subtitle restates its heading, and no "Changes apply at once" sits over switches that do. What a reader may need and cannot see, what a setting does or why an option is there, goes behind an `InfoPopover` right after the label it explains: one press away with a mouse, a thumb or the keys.

Words that report stay on screen: an empty, failed or done message (*Say what happened*), a field's error, and a limit the reader needs while typing. [Writing](/ui/guidelines/content/writing/index.md#explanations) draws the line.

```tsx
import { InfoPopover } from "@orz/ui/components/info-popover";
import { Label } from "@orz/ui/components/label";
import { Separator } from "@orz/ui/components/separator";
import { Switch } from "@orz/ui/components/switch";

const ROWS = [
  { id: "principles-line-numbers", label: "Line numbers", on: true },
  {
    id: "principles-format",
    label: "Format on save",
    on: false,
    info: "Tidies indentation and trailing spaces each time a file is saved.",
  },
  {
    id: "principles-weekly",
    label: "Weekly summary",
    on: true,
    info: "A Monday email of what changed last week, sent even when notifications are off.",
  },
];

export function ExplainedSettings() {
  return (
    <div className="grid">
      {ROWS.map(({ id, label, on, info }, index) => (
        <div key={id}>
          {index > 0 && <Separator />}
          <div className="flex items-center justify-between gap-4 py-3 touch:min-h-touch">
            <div className="flex items-center gap-1">
              <Label htmlFor={id}>{label}</Label>
              {info && (
                <InfoPopover label={`About ${label.toLowerCase()}`}>
                  {info}
                </InfoPopover>
              )}
            </div>
            <Switch id={id} defaultChecked={on} />
          </div>
        </div>
      ))}
    </div>
  );
}
```

Two of these settings need a word on what they do, and carry it behind their (i); **Line numbers** says it all in its name. Press an (i), or Tab to it and press Enter.

## In the demos

- [Mail](/ui/demos/mail/index.md): Archiving asks nothing and offers Undo, no action waits for hover, and the list says whether it is empty, filtered out or failed to refresh.
