Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
Copy Markdown
Member

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:

componentStatus: {
status: 'not-recommended',
whereUsed: 'global',
notes: 'Use `Stack` from `@wordpress/ui` instead.',
},

componentStatus: {
status: 'stable',
whereUsed: 'global',
notes: 'Will be superseded by `Button` in `@wordpress/ui`, but continue using for now.',
},

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.

Copy link
Copy Markdown
Member

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/components components in the design system MCP responses if they're stable, i.e. there's not an equivalent in @wordpress/ui or it's not ready to be used.

- **`@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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like something we're actively trying to avoid (i.e. @wordpress/components and @wordpress/ui should be expected to coexist without perceivable visual differences), so I'd be hesitant to document that this is expected, or that the components shouldn't be used together.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 @wordpress/ui component to the list of recommended components.

- **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

Expand Down
Loading