Import
import { Badge } from '@contentful/f36-components';// orimport { 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>;}
Featured
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 StorybookName | Type | Default |
|---|---|---|
| children required | ReactNode | |
| as | "a" "abbr" "address" "animate" "animateMotion" "animateTransform" "area" "article" "aside" "audio" "b" "base" "bdi" "bdo" "big" "blockquote" "body" "br" "button" "canvas" "caption" "center" "circle" "cite" "clipPath" "code" "col" "colgroup" "data" "datalist" "dd" "defs" "del" "desc" "details" "dfn" "dialog" "div" "dl" "dt" "ellipse" "em" "embed" "feBlend" "feColorMatrix" "feComponentTransfer" "feComposite" "feConvolveMatrix" "feDiffuseLighting" "feDisplacementMap" "feDistantLight" "feDropShadow" "feFlood" "feFuncA" "feFuncB" "feFuncG" "feFuncR" "feGaussianBlur" "feImage" "feMerge" "feMergeNode" "feMorphology" "feOffset" "fePointLight" "feSpecularLighting" "feSpotLight" "feTile" "feTurbulence" "fieldset" "figcaption" "figure" "filter" "footer" "foreignObject" "form" "g" "h1" "h2" "h3" "h4" "h5" "h6" "head" "header" "hgroup" "hr" "html" "i" "iframe" "image" "img" "input" "ins" "kbd" "keygen" "label" "legend" "li" "line" "linearGradient" "link" "main" "map" "mark" "marker" "mask" "menu" "menuitem" "meta" "metadata" "meter" "mpath" "nav" "noindex" "noscript" "object" "ol" "optgroup" "option" "output" "p" "param" "path" "pattern" "picture" "polygon" "polyline" "pre" "progress" "q" "radialGradient" "rect" "rp" "rt" "ruby" "s" "samp" "script" "search" "section" "select" "set" "slot" "small" "source" "span" "stop" "strong" "style" "sub" "summary" "sup" "svg" "switch" "symbol" "table" "tbody" "td" "template" "text" "textarea" "textPath" "tfoot" "th" "thead" "time" "title" "tr" "track" "tspan" "u" "ul" "use" "var" "video" "view" "wbr" "webview" ComponentClass<any, any> FunctionComponent<any> HTML element used to wrap the target of the tooltip | 'div' |
| 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.