Import
import { Badge } from '@contentful/f36-components';// orimport { Badge } from '@contentful/f36-badge';
Examples
Primary
Used for the entity that has been changed
Primary filled
Used to highlight a new functionality or to indicate changes in the interface.
Positive
Used for the entity that has been published
Negative
Used for the entity that has been deleted.
Warning
Used for the entity that has been deleted.
Secondary
Used for all the secondary elements, for example in the list of versions:
Featured
Used for featured entities that should be highlighted.
Badge sizes
Default
Small
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
Props (API reference)
Open in StorybookName | Type | Default |
---|---|---|
children required | ReactNode | |
className | string CSS class to be appended to the root element | |
css | string number false true ComponentSelector Keyframes SerializedStyles ArrayInterpolation<undefined> ObjectInterpolation<undefined> (theme: any) => Interpolation<undefined> | |
endIcon | string number false true {} ReactElement<any, string | JSXElementConstructor<any>> ReactNodeArray ReactPortal 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 false true {} ReactElement<any, string | JSXElementConstructor<any>> ReactNodeArray ReactPortal 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.