Components
Badge
Badge is a non-interactive component that displays status with or without a number. Use Tag if you want text instead of a number.
React
Press Enter to start editing
const Preview = () => { return <Badge count={15} maxCount={9} />; }; render(<Preview />)
Use Badge when
- displaying numbers that show the count of new messages, notifications or tasks
- indicating status using a circular marker, such as showing whether a person is busy, away or active
Avoid Badge when
Examples
Colours and variants
All colours in your theme can be used with Badge. The component comes in two variants: base and tinted.
React
Press Enter to start editing
const Variants = () => { const VariantsMap: { [key: string]: { [key: string]: string }; } = { neutralBase: { 'data-color': 'neutral', }, neutralTinted: { 'data-color': 'neutral', variant: 'tinted', }, dangerBase: { 'data-color': 'danger', }, dangerTinted: { 'data-color': 'danger', variant: 'tinted', }, infoBase: { 'data-color': 'info', }, infoTinted: { 'data-color': 'info', variant: 'tinted', }, warningBase: { 'data-color': 'warning', }, warningTinted: { 'data-color': 'warning', variant: 'tinted', }, }; return ( <> {Object.entries(VariantsMap).map(([key, value]) => ( <Badge key={key} {...value} count={15} maxCount={9} /> ))} </> ); }; render(<Variants />)
Next to text
Badge can be placed next to other text or components.
React
Press Enter to start editing
const InTabs = () => ( <Tabs defaultValue='value1'> <Tabs.List> <Tabs.Tab value='value1'> Favoritter <Badge count={64} maxCount={10} data-color='neutral' /> </Tabs.Tab> <Tabs.Tab value='value2'>Arkiv</Tabs.Tab> <Tabs.Tab value='value3'> Nylige <Badge count={2} data-color='neutral' /> </Tabs.Tab> </Tabs.List> <Tabs.Panel value='value1'>content 1</Tabs.Panel> <Tabs.Panel value='value2'>content 2</Tabs.Panel> <Tabs.Panel value='value3'>content 3</Tabs.Panel> </Tabs> ); render(<InTabs />)
Floating
Badge can be placed floating above other elements.
React
Press Enter to start editing
const Floating = () => ( <> <Badge.Position placement='top-right'> <Badge data-color='danger' count={2}></Badge> <EnvelopeClosedFillIcon title='Meldinger' style={{ fontSize: '2rem' }} /> </Badge.Position> </> ); render(<Floating />)
Without text
Badge can be used without text inside it, but it must then have accompanying text next to it. Information should not be communicated through colour or shape alone.1
React
Press Enter to start editing
const Bullet = () => ( <div style={{ display: 'inline-flex', alignItems: 'center', gap: '0.5rem' }}> <Badge data-color='success' style={{ display: 'inline-flex' }} /> Aktiv </div> ); render(<Bullet />)
Guidelines
Use Badge to draw attention to statuses, notifications or numbers.
Text
This component is not intended for text. If you need to display words or short phrases, use Tag instead.