diff --git a/packages/eslint-plugin/CHANGELOG.md b/packages/eslint-plugin/CHANGELOG.md index 4a8faf8f40a39c..aca712fd5112ae 100644 --- a/packages/eslint-plugin/CHANGELOG.md +++ b/packages/eslint-plugin/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### New Features + +- `use-recommended-components`: Add an `allowUseWithCaution` option that allows `@wordpress/ui` components marked "Use with caution" ([#83536](https://github.com/WordPress/gutenberg/pull/83536)). + ## 27.0.0 (2026-09-23) ### Breaking Changes diff --git a/packages/eslint-plugin/docs/rules/use-recommended-components.md b/packages/eslint-plugin/docs/rules/use-recommended-components.md index 14709ce61d6908..18eec0b081af07 100644 --- a/packages/eslint-plugin/docs/rules/use-recommended-components.md +++ b/packages/eslint-plugin/docs/rules/use-recommended-components.md @@ -41,3 +41,16 @@ import { unlock } from '../../lock-unlock'; const { SomethingElse } = unlock( componentsPrivateApis ); ``` + +## Options + +This rule has an object option: + +- `allowUseWithCaution` (default: `false`): allow `@wordpress/ui` components that are marked "Use with caution" in Storybook. These components are ready for use, but their APIs or behavior may still change. Opt in only if you can follow those changes. They are also not advised to be mixed with existing components from `@wordpress/components` in the same interface, because their visual design and behavior can differ. + +Examples of **correct** code for this rule with the `{ "allowUseWithCaution": true }` option: + +```js +/* eslint @wordpress/use-recommended-components: ["error", { "allowUseWithCaution": true }] */ +import { Button, Dialog } from '@wordpress/ui'; +``` diff --git a/packages/eslint-plugin/rules/__tests__/use-recommended-components.js b/packages/eslint-plugin/rules/__tests__/use-recommended-components.js index c6a8797df01bb8..90f61ea8027734 100644 --- a/packages/eslint-plugin/rules/__tests__/use-recommended-components.js +++ b/packages/eslint-plugin/rules/__tests__/use-recommended-components.js @@ -24,6 +24,12 @@ ruleTester.run( 'use-recommended-components', rule, { // Allowed @wordpress/ui components. "import { Badge } from '@wordpress/ui';", + // "Use with caution" components are allowed when opted in. + { + code: "import { Button, Dialog } from '@wordpress/ui';", + options: [ { allowUseWithCaution: true } ], + }, + // Unlocked private APIs are only checked for denied names. "import { privateApis } from '@wordpress/components'; import { unlock } from '../../lock-unlock'; const { SomethingElse } = unlock( privateApis );", ` @@ -66,6 +72,37 @@ ruleTester.run( 'use-recommended-components', rule, { }, ], }, + // "Use with caution" components are flagged unless opted in. + { + code: "import { Button } from '@wordpress/ui';", + errors: [ + { + message: + '`Button` from `@wordpress/ui` is not yet recommended for use in a WordPress environment.', + }, + ], + }, + { + code: "import { Button } from '@wordpress/ui';", + options: [ { allowUseWithCaution: false } ], + errors: [ + { + message: + '`Button` from `@wordpress/ui` is not yet recommended for use in a WordPress environment.', + }, + ], + }, + // Opting in to "Use with caution" does not allow other components. + { + code: "import { Button, SomeComponent } from '@wordpress/ui';", + options: [ { allowUseWithCaution: true } ], + errors: [ + { + message: + '`SomeComponent` from `@wordpress/ui` is not yet recommended for use in a WordPress environment.', + }, + ], + }, // Denylist: denied components are flagged with their message. { code: "import { __experimentalZStack } from '@wordpress/components';", @@ -111,4 +148,12 @@ describe( 'ALLOWLIST and DENYLIST', () => { ); expect( overlap ).toEqual( [] ); } ); + + it( 'should not list a component as both allowed and "Use with caution"', () => { + Object.values( ALLOWLIST ).forEach( ( { allowed, caution = [] } ) => { + expect( + caution.filter( ( name ) => allowed.includes( name ) ) + ).toEqual( [] ); + } ); + } ); } ); diff --git a/packages/eslint-plugin/rules/use-recommended-components.js b/packages/eslint-plugin/rules/use-recommended-components.js index 579303d7ff9314..2980e23b0489bf 100644 --- a/packages/eslint-plugin/rules/use-recommended-components.js +++ b/packages/eslint-plugin/rules/use-recommended-components.js @@ -9,9 +9,12 @@ const { * Allowlist: only the listed components are permitted from these packages. * Any other named import will be flagged with the package's message. * + * Components in `caution` are marked "Use with caution". They are flagged + * unless the `allowUseWithCaution` option is enabled. + * * `message` supports `{{ name }}` and `{{ source }}` placeholders. * - * @type {Record} + * @type {Record} */ const ALLOWLIST = { '@wordpress/ui': { @@ -52,6 +55,27 @@ const ALLOWLIST = { 'VisuallyHidden', 'useKeyboardShortcutProps', ], + caution: [ + 'AlertDialog', + 'Breadcrumb', + 'Button', + 'Checkbox', + 'CheckboxGroup', + 'Combobox', + 'Dialog', + 'Drawer', + 'IconButton', + 'LinkButton', + 'Menu', + 'Notice', + 'Popover', + 'Radio', + 'RadioGroup', + 'SearchableSelect', + 'SearchableSelectControl', + 'Switch', + 'SwitchControl', + ], message: '`{{ name }}` from `{{ source }}` is not yet recommended for use in a WordPress environment.', }, @@ -125,9 +149,20 @@ const rule = { 'Encourage the use of recommended UI components in a WordPress environment.', url: 'https://github.com/WordPress/gutenberg/blob/HEAD/packages/eslint-plugin/docs/rules/use-recommended-components.md', }, - schema: [], + schema: [ + { + type: 'object', + properties: { + allowUseWithCaution: { + type: 'boolean', + }, + }, + additionalProperties: false, + }, + ], }, create( context ) { + const { allowUseWithCaution = false } = context.options[ 0 ] ?? {}; const privateApisState = createPrivateApisState(); return { @@ -161,7 +196,11 @@ const rule = { if ( allowlistEntry && - ! allowlistEntry.allowed.includes( name ) + ! allowlistEntry.allowed.includes( name ) && + ! ( + allowUseWithCaution && + allowlistEntry.caution?.includes( name ) + ) ) { context.report( { node: specifier, diff --git a/packages/ui/CHANGELOG.md b/packages/ui/CHANGELOG.md index bb7b2b6ec17275..5ee434fdf5b2ed 100644 --- a/packages/ui/CHANGELOG.md +++ b/packages/ui/CHANGELOG.md @@ -16,6 +16,10 @@ - `Popover`: Close non-modal popovers when the user presses inside a same-origin iframe. ([#83509](https://github.com/WordPress/gutenberg/pull/83509)) - `CollapsibleCard`: Only show the header's focus ring when its own trigger is keyboard-focused ([#81314](https://github.com/WordPress/gutenberg/pull/81314)). +### Internal + +- Document component status in `CONTRIBUTING.md` ([#83536](https://github.com/WordPress/gutenberg/pull/83536)). + ## 0.23.0 (2026-09-23) ### Breaking Changes diff --git a/packages/ui/CONTRIBUTING.md b/packages/ui/CONTRIBUTING.md index 136a5733a64084..d2bd8130410113 100644 --- a/packages/ui/CONTRIBUTING.md +++ b/packages/ui/CONTRIBUTING.md @@ -81,6 +81,10 @@ When designing props for a new component: - Provide a `@default` JSDoc tag for the uncontrolled prop when there is a sensible default. +### Component status + +When you change a component's Storybook `parameters.componentStatus.status` or its public export, check the `@wordpress/ui` entry in the [`use-recommended-components`](../eslint-plugin/docs/rules/use-recommended-components.md) ESLint rule. `recommended` components belong in `allowed`, `use-with-caution` components in `caution`, and other statuses in neither. + ## Compound Components This package follows the [compound component approach outlined in the `@wordpress/components` contributing guidelines](https://github.com/WordPress/gutenberg/blob/trunk/packages/components/CONTRIBUTING.md#compound-components).