diff --git a/storybook/stories/design-system/patterns/settings-page.mdx b/storybook/stories/design-system/patterns/settings-page.mdx new file mode 100644 index 00000000000000..88d50bbb0cc29a --- /dev/null +++ b/storybook/stories/design-system/patterns/settings-page.mdx @@ -0,0 +1,171 @@ +import { Canvas, Markdown, Meta } from '@storybook/addon-docs/blocks'; +import * as SettingsPageStories from './settings-page.story'; +import SimpleSource from './settings-page/simple.tsx?raw'; +import SectionsSource from './settings-page/sections.tsx?raw'; +import FailedSaveSource from './settings-page/failed-save.tsx?raw'; +import AdjacentPagesSource from './settings-page/adjacent-pages.tsx?raw'; +import SubpagesSource from './settings-page/subpages.tsx?raw'; +import AdjacentPagesAndSubpagesSource from './settings-page/adjacent-pages-and-subpages.tsx?raw'; +import RecordsSubpageSource from './settings-page/records-subpage.tsx?raw'; +import RecordsDialogSource from './settings-page/records-dialog.tsx?raw'; +import RecordsDrawerSource from './settings-page/records-drawer.tsx?raw'; + + + +# Settings Page + +Templates for settings screens, composed from the admin-ui `Page`, `@wordpress/ui` components, `@wordpress/theme` tokens and DataViews. Start from the template closest to your settings, then replace the fields. + +These templates are starting points, not requirements. Not every settings page needs to match one exactly: adapt the structure to what your settings need, and combine or depart from the templates where that serves people better. + +Several of the `@wordpress/ui` components they use, including `Button`, `Dialog`, `Drawer` and `AlertDialog`, are still marked “Use with caution”, so their APIs may change. Treat the templates as the direction settings pages are heading, not as a recommendation to migrate existing screens yet. + +## Building blocks + +Every template uses the same parts: + +- **`Page`** from `@wordpress/admin-ui` provides the header: a title or breadcrumbs, optional section navigation, and the actions area where Save lives. +- **`Card`** from `@wordpress/ui` groups related settings. Give each card a short title, and a description when the title alone doesn't say what the settings affect. The Structure section below covers when to use one. Cap form cards at `--wpds-dimension-surface-width-xl` so fields stay a readable length, and give tables of records `--wpds-dimension-surface-width-2xl` so their columns fit. +- **`DataForm`** from `@wordpress/dataviews` renders the fields, so labels, descriptions, validation and spacing stay consistent. +- **`DataViews`** from `@wordpress/dataviews` lists records people can add and edit. +- **`Dialog`**, **`Drawer`** and **`AlertDialog`** from `@wordpress/ui` hold record editors and confirmations. +- **Snackbars** confirm saves that have no other visible effect. `SnackbarList` comes from `@wordpress/components`, since `@wordpress/ui` doesn't offer an equivalent yet. + +Each example's code shows its template. The helpers it imports, such as the manual-save draft, the sample fields and the in-canvas router, live alongside it in `storybook/stories/design-system/patterns/settings-page/`. + +## Structure + +Plan a settings page like a document's outline before choosing how it looks. The headings decide how assistive technology reads the page and lets people jump through it, and the same kind of content should get the same treatment wherever it appears. + +- **Put each group of related fields in a card.** A card bounds a group and separates it from the groups around it. Keep the card even when a page has a single group, so every settings page reads the same way. +- **Title each card after its group of fields.** The page title is the `h1`, and on a page without sections the card titles are `h2`s. +- **Add sections when cards form larger groups.** A section heading sits on the canvas above its cards, as an `h2` with an optional description, and the cards inside it take `h3` titles. Use `Text` with `variant="heading-lg"` for the section heading. Each section gets its own heading, and a page with only a few cards needs none. +- **Don't skip heading levels**, and don't choose a level for its size. The level follows the structure, so a card title looks the same whether it's an `h2` or an `h3`. + +## Saving + +These templates use the manual save model from [Save & Submit](?path=/docs/design-system-patterns-save-submit--docs): edits are held in a draft until the user clicks “Save changes”. Manual save is the usual choice for settings, because their fields often depend on each other and should apply together. Autosave suits a page of independent preferences that each take effect on their own, such as the block editor’s Preferences modal. Choose one model for the whole page and don't mix the two: if you choose autosave, remove the Save button. [Choose one save model per surface](?path=/docs/design-system-patterns-save-submit--docs#choose-one-save-model-per-surface) explains how to decide. + +- **One “Save changes” button per page**, in the `Page` header actions. It covers every field on that page and nothing else. +- **Disabled only when there is nothing to save**, and busy while saving. Don't explain the disabled state with a tooltip: tooltips aren't available to screen readers or on touch devices. +- **Invalid fields don't disable Save.** The fields sit in a `