Skip to the page

Page menu

In code: PageMenu

A page with its own short menu beside it, like "On this page" in a document (side="start" puts it before the page): the screens of one area (settings, an account, a guide) beside the reading column, the current one highlighted. Where its box is too narrow for both, the menu goes above the page as one row that scrolls.

Preview

Harbour Studio

Team

Who works here and what each person may do

Use

The code of the preview above
import { useState } from 'react';
import { PageMenu, Stack } from '@/components/ui';

function PageMenuDemo() {
  const [at, setAt] = useState('team');
  const screens = [
    ['profile', 'Profile'],
    ['team', 'Team'],
    ['billing', 'Billing'],
  ];
  return (
    <PageMenu
      label="Settings"
      title="Settings"
      items={screens.map(([id, label]) => ({ href: `#${id}`, label, active: at === id }))}
      onClick={(e) => {
        const link = (e.target as HTMLElement).closest('a');
        if (!link) return;
        e.preventDefault();
        setAt(link.getAttribute('href')!.slice(1));
      }}
    >
      <Stack gap={2}>
        <span className="ui-overline">Harbour Studio</span>
        <h3 className="ui-title">{screens.find(([id]) => id === at)![1]}</h3>
        <p className="ui-muted">Who works here and what each person may do</p>
      </Stack>
    </PageMenu>
  );
}

This page as text, for an AI

Options

OptionTypeWhat it does
items NeededPageMenuItem[]The entries, in order.
label NeededstringThe menu's name, read out by screen readers: "Admin", "Settings", "On this page".
back PageMenuItemThe way out of the area, first and set apart from the entries by space: { href: '/', label: 'Back to Studio', icon }.
foot ReactNodeSomething at the foot of the menu, set apart from the entries by space: an AccountMenu.
side "end" | "start" · default 'end'Where the menu stands beside the page: end (after it, like "On this page") or start (before it, like a settings menu).

It also takes the 280 attributes of the element or UI SDK part it draws: className, aria-label, events and the rest.

Without React

The same look on any HTML, with the classes div.ui-page-menu > .ui-page-menu-main + nav.ui-page-menu-nav.

With the CSS in parts (/ui/css/), it needs these, besides the ones every page loads:

components/page-menu.css

Layout: states, do and don’t

A page with its own short menu beside it, like "On this page" (side="start" puts it before the page, like a settings menu; foot holds something at the foot of the menu, under a hairline, such as an AccountMenu; title shows a small heading above the entries, label only names it for screen readers; the entries are plain links with a hairline between them and an optional icon, the current one in the text colour; back is the way out of the area, first and set apart by space; an entry may have an icon): the screens of one area (settings, an account, a guide) beside the reading column, the current one highlighted (active). Where its box is too narrow for both, the menu goes above the page as one row that scrolls. For a whole app's sections use Sidebar.

States. Layout follows the box it is in, not the window: Split, Grid, AppShell and the site parts stack when their box is narrow, at any width of the window.

Do

  • Space with gap (Stack, Row, Grid), never with margins on children.
  • Put the page's sections straight on the page, under their titles; a Card is one thing a person picks or acts on.
  • Check every screen at 320, 375 and 768 px with the narrow check of rule 10.

Don't

  • Don't give a box a fixed width, or a min-height together with an aspect-ratio.
  • Don't nest a card in a card.
  • Don't put two <main>s on a page: a screen shown inside another page takes Main as="div".