Badge

Label or highlight items.

For Contentful entity statuses, use EntityStatusBadge instead.

Import

import { Badge } from '@contentful/f36-components';
// or
import { Badge } from '@contentful/f36-badge';

Examples

Primary

Used for the entity that has been changed

function PrimaryBadgeExample() {
return <Badge variant="primary">Changed</Badge>;
}

Primary filled

Used to highlight a new functionality or to indicate changes in the interface.

function PrimaryFilledBadgeExample() {
return <Badge variant="primary-filled">New</Badge>;
}

Positive

Used for the entity that has been published

function PositiveBadgeExample() {
return <Badge variant="positive">Published</Badge>;
}

Negative

Used for the entity that has been deleted.

function NegativeBadgeExample() {
return <Badge variant="negative">Deleted</Badge>;
}

Warning

Used for the entity that has been deleted.

function WarningBadgeExample() {
return <Badge variant="warning">Draft</Badge>;
}

Secondary

Used for all the secondary elements, for example in the list of versions:

function SecondaryBadgeExample() {
return <Badge variant="secondary">Current</Badge>;
}

Used for featured entities that should be highlighted.

function FeaturedBadgeExample() {
return <Badge variant="featured">Trial</Badge>;
}

Badge sizes

Default

function DefaultSizeExample() {
return <Badge variant="positive">Published</Badge>;
}

Small

function SmallSizeExample() {
return (
<Badge variant="primary-filled" size="small">
New
</Badge>
);
}

Icons

You can add an icon by providing the following props:

  • startIcon – adds icon to the left side of the badge
  • endIcon – adds icon to the right side of the badge
function StartIconExample() {
return (
<Stack>
<Badge startIcon={<EnvironmentAliasIcon />}>Main</Badge>
<Badge endIcon={<ClockIcon />}>Scheduled</Badge>
</Stack>
);
}

Props (API reference)

Open in Storybook

Name

Type

Default

children
required
ReactNode

className
string

CSS class to be appended to the root element

endIcon
string
number
bigint
false
true
ReactElement<unknown, string | JSXElementConstructor<any>>
Iterable<ReactNode>
ReactPortal
Promise<AwaitedReactNode>

Expects any of the icon components. Renders the icon aligned to the end

size
"small"
"default"

Sets the size of the component

default
startIcon
string
number
bigint
false
true
ReactElement<unknown, string | JSXElementConstructor<any>>
Iterable<ReactNode>
ReactPortal
Promise<AwaitedReactNode>

Expects any of the icon components. Renders the icon aligned to the start

testId
string

A [data-test-id] attribute used for testing purposes

textTransform
"none"

By default the Badge uses CSS to capitalize only the first letter of the badge text. This CSS is hit by a bug in Firefox that results in the badge being rendered slightly too wide. To avoid the bug, set this property to `none` to disable the text transformation. Please be sure the initial letter of the badge text is already capitalized!

variant
"negative"
"positive"
"primary"
"secondary"
"warning"
"primary-filled"
"featured"

Determines the variation of the component

primary

Badge also accepts all HTML attributes (as React properties) that are applicable to the usual div tag.

Content guidelines

  • badges are used to inform users of the status of an element in the interface
  • keep in mind the recommended color coding for each of variant
  • try to use labels with short, scannable text
  • try to use a single word to describe the status of an element
  • try to describe the status in the past tense, like changed or archived

Accessibility

  • text must be clear enough for color-blind users to be able to understand immediately without needing to rely only on the color.