constDefault=()=><NavigatorinitialPath="/">(<><Navigator.Screenpath="/"><h2>This is the home screen.</h2><VStackalignment="left"><Navigator.Buttonvariant="primary"path="/child"> Go to child screen.
</Navigator.Button><Navigator.Buttonvariant="primary"path="/product/1"> Go to dynamic path screen with id 1.
</Navigator.Button><Navigator.Buttonvariant="primary"path="/product/2"> Go to dynamic path screen with id 2.
</Navigator.Button></VStack></Navigator.Screen><Navigator.Screenpath="/child"><h2>This is the child screen.</h2><HStackspacing={2}alignment="left"><Navigator.BackButtonvariant="secondary"> Go back
</Navigator.BackButton><Navigator.Buttonvariant="primary"path="/child/grandchild"> Go to grand child screen.
</Navigator.Button></HStack></Navigator.Screen><Navigator.Screenpath="/child/grandchild"><h2>This is the grand child screen.</h2><Navigator.BackButtonvariant="secondary"> Go back
</Navigator.BackButton></Navigator.Screen><Navigator.Screenpath="/product/:id"><DynamicScreen/></Navigator.Screen></>)</Navigator>;
constSkipFocus=()=><NavigatorinitialPath="/">(<><divstyle={{height:150,outline:'1px solid black',outlineOffset:'-1px',marginBlockEnd:'1rem',display:'contents',}}><Navigator.Screenpath="/"><h2>Home screen</h2><Navigator.Buttonvariant="primary"path="/child"> Go to child screen.
</Navigator.Button></Navigator.Screen><Navigator.Screenpath="/child"><h2>Child screen</h2><Navigator.BackButtonvariant="secondary"> Go back to home screen
</Navigator.BackButton></Navigator.Screen></div><NavigatorButtonWithSkipFocuspath="/child"> Go to child screen, but keep focus on this button
</NavigatorButtonWithSkipFocus></>)</Navigator>;
The displayed message of a notice. Also used as the spoken message for
assistive technology, unless spokenMessage is provided as an alternative message.
spokenMessage
ReactNode
children
Used to provide a custom spoken message in place of the children default.
@default children
status
'warning' | 'success' | 'error' | 'info'
'info'
Determines the color of the notice: warning (yellow),
success (green), error (red), or 'info'.
By default 'info' will be blue, but if there is a parent Theme component
with an accent color prop, the notice will take on that color instead.
@default ‘info’
onRemove
() => void
() => {}
Function called when dismissing the notice
@default noop
politeness
'polite' | 'assertive'
getDefaultPoliteness( status )
A politeness level for the notice’s spoken message. Should be provided as
one of the valid options for an aria-live attribute value.
A value of 'assertive' is to be used for important, and usually
time-sensitive, information. It will interrupt anything else the screen
reader is announcing in that moment.
A value of 'polite' is to be used for advisory information. It should
not interrupt what the screen reader is announcing in that moment
(the “speech queue”) or interrupt the current task.
Note that this value should be considered a suggestion; assistive
technologies may override it based on internal heuristics.
@default ‘assertive’ for ‘error’ status, ‘polite’ for all other statuses
isDismissible
boolean
true
Whether the notice should be dismissible or not
@default true
onDismiss
() => void
() => {}
A deprecated alternative to onRemove. This prop is kept for
compatibility reasons but should be avoided.
@default noop
actions
Array< NoticeAction >
[]
An array of action objects. Each member object should contain:
label: string containing the text of the button/link
url: string OR onClick: ( event: SyntheticEvent ) => void to specify
what the action does.
className: string (optional) to add custom classes to the button styles.
noDefaultClasses: boolean (optional) A value of true will remove all
default styling.
variant: 'primary' | 'secondary' | 'link' (optional) You can denote a
primary button action for a notice by passing a value of primary.
The default appearance of an action button is inferred based on whether
url or onClick are provided, rendering the button as a link if
appropriate. If both props are provided, url takes precedence, and the
action button will render as an anchor tag.
@default []
__unstableHTML
boolean
Determines whether or not the message should be parsed as custom HTML
instead of a string.
constNoticeListSubcomponent=()=>{constexampleNotices: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);constremoveNotice=(id:NoticeListProps['notices'][number]['id'])=>{setNotices(notices.filter((notice)=>notice.id!==id));};constresetNotices=()=>{setNotices(exampleNotices);};return(<><NoticeListnotices={notices}onRemove={removeNotice}/><Button__next40pxDefaultSizevariant="primary"onClick={resetNotices}> Reset Notices
</Button></>);};
The typographic variant to apply, controlling font family, size,
line height, and weight.
@default “body-md”
children
React.ReactNode
The content to be rendered inside the component.
Examples
Default
constDefault=()=><Textvariant="body-md">The quick brown fox jumps over the lazy dog.</Text>;
All Variants
Important: Setting the variant prop to a heading variant will not automatically render a heading element. Use the render prop to render a heading element with the appropriate level.
constAllVariants=()=>(<Stackdirection="column"gap="lg"style={{color:'var(--wpds-color-fg-content-neutral)'}}>{(['heading-2xl','heading-xl','heading-lg','heading-md','heading-sm','body-xl','body-lg','body-md','body-sm',]asconst).map((variant)=>(<Stackkey={variant}direction="column"gap="xs"><Textvariant="heading-sm">{variant}</Text><Textvariant={variant}> The quick brown fox jumps over the lazy dog.
</Text></Stack>))}</Stack>);
With Render Prop
constWithRenderProp=()=>(<Stackdirection="column"gap="md"><Textvariant="heading-2xl"render={<h1/>}> Page Title
</Text><Textvariant="heading-xl"render={<h2/>}> Section Heading
</Text><Textvariant="body-md"render={<p/>}> A paragraph of body text rendered as a semantic paragraph
element.
</Text></Stack>);
TextareaControls are TextControls that allow for multiple lines of text, and
wrap overflow text onto a new line. They are a fixed height and scroll
vertically when the cursor reaches the bottom of the field.
constDefault=()=>{const[value,setValue]=useState('');return(<TextareaControllabel="Text"help="Enter some text"placeholder="Placeholder"value={value}onChange={(v)=>{setValue(v);onChange(v);}}/>);};
The name of the Slot in which the popover should be rendered. It should
be also passed to the corresponding PopoverSlot component.
@default ‘Popover’
Examples
Default
constDefault=()=><Popover>(<divstyle={{width:'280px',whiteSpace:'normal'}}>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat.
</div>)</Popover>;
Unstyled
constUnstyled=()=><Popovervariant="unstyled"/>;
All Placements
constAllPlacements=({children,...args})=>(<divstyle={{minWidth:'600px',marginLeft:'auto',marginRight:'auto',}}><h2> Resize / scroll the viewport to test the behavior of the
popovers when they reach the viewport boundaries.
</h2><div>{AVAILABLE_PLACEMENTS.map((p)=>(<PopoverWithAnchorkey={p}placement={p}{...args}resize={p==='overlay'?true:args.resize}>{children}<div><small>(placement: {p})</small></div></PopoverWithAnchor>))}</div></div>);
Dynamic Height
constDynamicHeight=()=><Popover>(<divstyle={{height:'var(--dynamic-height)',background:'#eee',padding:'20px',}}>Content with dynamic height
</div>)</Popover>;
constWithLabelAndHelpText=()=>{const[value,setValue]=useState('');return(<TextControl__next40pxDefaultSizelabel="Label Text"help="Help text to explain the input."value={value}onChange={(v)=>{setValue(v);onChange(v);}}/>);};