diff --git a/projects/plugins/protect/changelog/update-protect-notice-wpds b/projects/plugins/protect/changelog/update-protect-notice-wpds new file mode 100644 index 000000000000..ad5ddf81027c --- /dev/null +++ b/projects/plugins/protect/changelog/update-protect-notice-wpds @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +Notices: Restyle to match the WordPress design system. diff --git a/projects/plugins/protect/src/js/components/notice/README.md b/projects/plugins/protect/src/js/components/notice/README.md index dcb3c4935936..60e3f8582494 100644 --- a/projects/plugins/protect/src/js/components/notice/README.md +++ b/projects/plugins/protect/src/js/components/notice/README.md @@ -13,4 +13,4 @@ A simple notice component for displaying alerts and messages to the user. ## Props -Supported `type` values are `info`, `success`, and `error`. \ No newline at end of file +Supported `type` values are `info`, `success`, `warning`, and `error`. \ No newline at end of file diff --git a/projects/plugins/protect/src/js/components/notice/index.jsx b/projects/plugins/protect/src/js/components/notice/index.jsx index 176c4d04e16c..0e60c7e57330 100644 --- a/projects/plugins/protect/src/js/components/notice/index.jsx +++ b/projects/plugins/protect/src/js/components/notice/index.jsx @@ -1,9 +1,17 @@ import { __ } from '@wordpress/i18n'; -import { check, close, info, cautionFilled as warning, Icon } from '@wordpress/icons'; +import { Notice as WPNotice } from '@wordpress/ui'; +import clsx from 'clsx'; import { useCallback, useEffect } from 'react'; import useNotices from '../../hooks/use-notices'; import styles from './styles.module.scss'; +const INTENTS = { + success: 'success', + error: 'error', + info: 'info', + warning: 'warning', +}; + const Notice = ( { dismissable = false, duration = null, @@ -13,19 +21,6 @@ const Notice = ( { } ) => { const { clearNotice } = useNotices(); - let icon; - switch ( type ) { - case 'success': - icon = check; - break; - case 'error': - icon = warning; - break; - case 'info': - default: - icon = info; - } - const onClose = useCallback( () => { clearNotice(); }, [ clearNotice ] ); @@ -44,25 +39,25 @@ const Notice = ( { }, [ clearNotice, duration, message ] ); return ( -
-
- -
-
{ message }
+ { message } { dismissable && ( - + /> ) } -
+ ); }; diff --git a/projects/plugins/protect/src/js/components/notice/styles.module.scss b/projects/plugins/protect/src/js/components/notice/styles.module.scss index ec6f6909c2d6..0971d9360a7f 100644 --- a/projects/plugins/protect/src/js/components/notice/styles.module.scss +++ b/projects/plugins/protect/src/js/components/notice/styles.module.scss @@ -1,13 +1,7 @@ .notice { - background-color: var(--jp-gray-90); - color: var(--jp-white); - display: flex; - border-radius: var(--jp-border-radius); // 4px - overflow: hidden; z-index: 1; &.notice--info { - border-left: 4px solid var(--jp-yellow-20); margin-bottom: calc(var(--spacing-base) * 3); // 24px } @@ -17,59 +11,12 @@ right: calc(var(--spacing-base) * 3); // 24px margin-left: calc(var(--spacing-base) * 3); // 24px + // The notice sets `container-type: inline-size`, so it reports no width to + // this shrink-to-fit fixed box and collapses to a sliver. + container-type: normal; + @media ( max-width: 782px ) { top: calc(var(--spacing-base) * 8); // 72px } } - - a, - a:link, - a:hover, - a:visited, - a:active { - color: var(--jp-white); - } -} - -.notice__icon { - background-color: var(--jp-yellow-30); - fill: var(--jp-white); - display: flex; - align-items: center; - justify-content: center; - padding: calc(var(--spacing-base) * 1.5); // 12px - - .notice--success & { - background-color: var(--jp-green-50); - } - - .notice--error & { - background-color: var(--jp-red); - } - - .notice--info & { - fill: var(--jp-yellow-50); - background-color: var(--jp-yellow-5); - } -} - -.notice__message { - font-size: 14px; - padding: calc(var(--spacing-base) * 1.75); // 14px - - .notice--info & { - color: var(--jp-gray-90); - background-color: var(--jp-yellow-5); - } -} - -.notice__close { - fill: var(--jp-gray); - cursor: pointer; - display: flex; - align-items: center; - justify-content: center; - padding: calc(var(--spacing-base) * 1.5); // 12px - background: transparent; - border: none; } diff --git a/projects/plugins/protect/src/js/hooks/use-notices.tsx b/projects/plugins/protect/src/js/hooks/use-notices.tsx index 28dbed49ba10..e37304239106 100644 --- a/projects/plugins/protect/src/js/hooks/use-notices.tsx +++ b/projects/plugins/protect/src/js/hooks/use-notices.tsx @@ -10,7 +10,7 @@ interface NoticeState { message?: string | JSX.Element; dismissable?: boolean; duration?: number; - type?: 'success' | 'info' | 'error'; + type?: 'success' | 'info' | 'warning' | 'error'; } interface NoticeContextValue { diff --git a/projects/plugins/protect/tests/e2e/specs/start.test.ts b/projects/plugins/protect/tests/e2e/specs/start.test.ts index 5a4317daa130..1587f5af5150 100644 --- a/projects/plugins/protect/tests/e2e/specs/start.test.ts +++ b/projects/plugins/protect/tests/e2e/specs/start.test.ts @@ -7,7 +7,11 @@ import type { Locator, Page } from '@playwright/test'; * @param {Page} page - Playwright page object */ async function closeChangesSavedNotice( page: Page ) { - await expect( page.getByText( 'Changes saved' ) ).toBeVisible(); + // Scoped to the app root: the toast announces, and `speak()` leaves its text in + // `#a11y-speak-polite` after the notice goes, which would match on later calls. + await expect( + page.locator( '#jetpack-protect-root' ).getByText( 'Changes saved' ) + ).toBeVisible(); await page.getByRole( 'button', { name: 'Dismiss notice.' } ).click(); } @@ -69,8 +73,8 @@ test.describe( 'Jetpack Protect Plugin', () => { // react-router , the matched FirewallRoute can appear in two panels at // once. Scoping to the Firewall panel keeps each locator matching a single // element instead of tripping Playwright strict mode. `exact` avoids matching the - // "Automatic firewall is on" heading variant. The "Changes saved" notice is left - // page-scoped on purpose: it renders at the app level, outside the tab panels. + // "Automatic firewall is on" heading variant. The "Changes saved" notice renders + // at the app level, so its helper scopes to the app root rather than a panel. const firewallPanel = page.getByRole( 'tabpanel', { name: 'Firewall', exact: true } ); await test.step( 'Navigate to firewall page', async () => { diff --git a/projects/plugins/protect/webpack.config.js b/projects/plugins/protect/webpack.config.js index 24741223ddd2..e236cfe34c7e 100644 --- a/projects/plugins/protect/webpack.config.js +++ b/projects/plugins/protect/webpack.config.js @@ -19,7 +19,17 @@ module.exports = [ ...jetpackWebpackConfig.resolve, }, node: false, - plugins: [ ...jetpackWebpackConfig.StandardPlugins() ], + plugins: [ + ...jetpackWebpackConfig.StandardPlugins( { + DependencyExtractionPlugin: { + // Bundled, never one without the other — see #48173. + requestMap: { + '@wordpress/theme': { external: false }, + '@wordpress/private-apis': { external: false }, + }, + }, + } ), + ], module: { strictExportPresence: true, rules: [