Repository navigation
AGENTS.md: Add design system package guide #77264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,12 +67,34 @@ vendor/bin/phpcbf <path_to_php_file.php> | |
|
|
||
| For full architecture details, see `docs/explanations/architecture/`. | ||
|
|
||
| ## Design system package guide | ||
|
|
||
| The WordPress Design System spans several packages. When building or modifying UI, use the most specific package available: | ||
|
|
||
| | Package | Role | Use for | | ||
| |---|---|---| | ||
| | `@wordpress/theme` | Design tokens | Colors, spacing, typography, radii, shadows, elevation via `--wpds-*` CSS custom properties. Source of truth for every visual value. | | ||
| | `@wordpress/ui` | UI primitives | The preferred component library (e.g., AlertDialog, Badge, Button, Card, Dialog, EmptyState, Form, Icon, IconButton, Link, Notice, Popover, Stack, Tabs, Text, Tooltip). | | ||
| | `@wordpress/icons` | Iconography | SVG icons consumed via `<Icon icon={iconName} />`. | | ||
| | `@wordpress/admin-ui` | Page chrome | High-level layout (e.g., Page, Breadcrumbs, NavigableRegion). | | ||
| | `@wordpress/dataviews` | Data UI | DataViews (tables, grids, lists with filtering, sorting, bulk actions) and DataForm (structured form rendering from field definitions). | | ||
| | `@wordpress/components` | Legacy components | Only use when the component you need is not yet in `@wordpress/ui` (e.g., CheckboxControl, RadioControl, ToggleControl, ColorPicker, DatePicker). Prefer `@wordpress/ui` when both packages offer the same component. | | ||
|
|
||
| Key rules: | ||
|
|
||
| - **Never hardcode colors, spacing, or typography values.** Always reference `--wpds-*` tokens from `@wordpress/theme`. If a token doesn't exist for your use case, that's a gap worth reporting — not a reason to use a raw value. | ||
| - **Prefer `@wordpress/ui` over `@wordpress/components`.** The `/ui` package is the design system implementation; `/components` is a legacy collection being incrementally replaced. When both packages export a component with the same purpose, use the `/ui` version. | ||
| - **`@wordpress/components` uses a different styling system.** It consumes Sass variables from `@wordpress/base-styles`, not `--wpds-*` tokens. Mixing `/ui` and `/components` on the same page may produce minor visual inconsistencies. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels like something we're actively trying to avoid (i.e.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, and "can they coexist visually" is part of the criteria for adding a new |
||
| - **Two CSS custom property namespaces coexist in Gutenberg.** `--wp--preset--*` properties (from `theme.json`) are for block rendering and front-end styles. `--wpds-*` properties (from `@wordpress/theme`) are for admin UI and design system components. Use `--wp--preset--*` when working on blocks and the editor canvas; use `--wpds-*` when working on admin chrome, settings pages, and design system components. | ||
|
|
||
| ## Common pitfalls | ||
|
|
||
| - PHP features in `lib/compat/` MUST target a specific `wordpress-X.Y/` subdirectory. | ||
| - Avoid using private APIs in bundled packages (packages without `wpScript` or `wpModuleExports`). Private APIs are intended for Core usage; bundled packages may also be imported via npm into plugin scripts, causing incompatibilities. | ||
| - `block-editor` is a WordPress-agnostic package. NEVER add `core-data` dependencies or direct REST API calls to it. | ||
| - `@wordpress/build` (`packages/wp-build`) is a generic build tool used both in Gutenberg and by plugins targeting WordPress Core directly. Avoid Gutenberg-specific changes in it. | ||
| - Importing `@wordpress/dataviews` registers a `@wordpress/data` store at import time. Removing a `<DataViews>` usage without removing the `import` still ships the store registry. Be intentional about adding and removing DataViews imports. | ||
| - `@wordpress/ui` uses CSS Modules with `--wpds-*` tokens. `@wordpress/components` uses Emotion (CSS-in-JS) with Sass variables from `@wordpress/base-styles`. When modifying components, use the styling approach of the package you're working in — don't introduce Emotion into `/ui` or CSS Modules into `/components`. | ||
|
|
||
| ## PR instructions | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's been some work to try to document status on a component-by-component basis.
Examples:
gutenberg/packages/components/src/h-stack/stories/index.story.tsx
Lines 77 to 81 in d5be89a
gutenberg/packages/components/src/button/stories/index.story.tsx
Lines 54 to 58 in d5be89a
I don't think we're at a point where we'd want to make a blanket statement to always prefer
@wordpress/ui(related: #76135), but ideally we could and should be pointing towards these component-specific statuses if they're known.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good reminder that we should ideally be considering these component statuses as part of an MCP offering; for example, maybe we should include some
@wordpress/componentscomponents in the design system MCP responses if they're stable, i.e. there's not an equivalent in@wordpress/uior it's not ready to be used.