A badge component for displaying labels with semantic intent.
import { Badge } from '@wordpress/ui';
LinksPermalink to this section
PropsPermalink to this section
| Name | Default | Description |
|---|---|---|
children Required |
The text to display in the badge. | |
intent | 'none' |
The semantic intent of the badge, communicating its meaning through color. |
className |
CSS class name to apply to the element. | |
style |
CSS style to apply to the element. | |
render |
Replaces the component’s default HTML element using a given React element, or a function that returns a React element. |
ExamplesPermalink to this section
DefaultPermalink to this section
const Default = () => <Badge>Badge</Badge>;
HighPermalink to this section
const High = () => <Badge intent="high" />;
MediumPermalink to this section
const Medium = () => <Badge intent="medium" />;
LowPermalink to this section
const Low = () => <Badge intent="low" />;
StablePermalink to this section
const Stable = () => <Badge intent="stable" />;
InformationalPermalink to this section
const Informational = () => <Badge intent="informational" />;
DraftPermalink to this section
const Draft = () => <Badge intent="draft" />;
NonePermalink to this section
const None = () => <Badge intent="none" />;
All IntentsPermalink to this section
const AllIntents = ( args ) => (
<div
style={ {
display: 'grid',
gridTemplateColumns: 'max-content min-content',
gap: '1rem',
color: 'var(--wpds-color-foreground-content-neutral)',
} }
>
{ (
[
'high',
'medium',
'low',
'stable',
'informational',
'draft',
'none',
] as const
).map( ( intent ) => (
<Fragment key={ intent }>
<div
style={ {
paddingInlineEnd: '1rem',
display: 'flex',
alignItems: 'center',
} }
>
{ intent }
</div>
<div
style={ {
padding: '0.5rem 1rem',
display: 'flex',
alignItems: 'center',
} }
>
<Badge { ...args } intent={ intent } />
</div>
</Fragment>
) ) }
</div>
);