Notice is a component used to communicate feedback to the user.
import { Notice } from '@wordpress/components';
Links
Props
| Name | Default | Description |
|---|---|---|
className |
A CSS | |
children Required |
The displayed message of a notice. Also used as the spoken message for
assistive technology, unless | |
spokenMessage | children |
Used to provide a custom spoken message in place of the |
status | 'info' |
Determines the color of the notice: |
onRemove | () => {} |
Function called when dismissing the notice |
politeness | getDefaultPoliteness( status ) |
A politeness level for the notice’s spoken message. Should be provided as
one of the valid options for an A value of Note that this value should be considered a suggestion; assistive technologies may override it based on internal heuristics. |
isDismissible | true |
Whether the notice should be dismissible or not |
onDismiss | () => {} |
A deprecated alternative to |
actions | [] |
An array of action objects. Each member object should contain:
The default appearance of an action button is inferred based on whether
|
__unstableHTML |
Determines whether or not the message should be parsed as custom HTML instead of a string. |
Examples
Default
const Default = ( props ) => {
return <Notice { ...props } />;
};
With Custom Spoken Message
const WithCustomSpokenMessage = ( props ) => {
return <Notice { ...props } />;
};
With JSX Children
const WithJSXChildren = ( props ) => {
return <Notice { ...props } />;
};
With Actions
const WithActions = ( props ) => {
return <Notice { ...props } />;
};
NoticeList Subcomponent
const NoticeListSubcomponent = () => {
const exampleNotices: NoticeListProps[ 'notices' ] = [
{
id: 'second-notice',
content: 'second notice content',
},
{
id: 'first-notice',
content: 'first notice content',
actions: [
{
label: 'Click me!',
onClick: () => {},
variant: 'primary',
},
{
label: 'Or click me instead!',
onClick: () => {},
},
{
label: 'Or visit a link for more info',
url: 'https://wordpress.org',
variant: 'link',
},
],
},
];
const [ notices, setNotices ] = useState( exampleNotices );
const removeNotice = (
id: NoticeListProps[ 'notices' ][ number ][ 'id' ]
) => {
setNotices( notices.filter( ( notice ) => notice.id !== id ) );
};
const resetNotices = () => {
setNotices( exampleNotices );
};
return (
<>
<NoticeList notices={ notices } onRemove={ removeNotice } />
<Button
__next40pxDefaultSize
variant="primary"
onClick={ resetNotices }
>
Reset Notices
</Button>
</>
);
};
With Disabled Action
Action buttons can be disabled.
const WithDisabledAction = ( props ) => {
return <Notice { ...props } />;
};





