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.
HTML
Unable to parse html
const Preview = () => { return <Badge count={15} maxCount={9} />; }; render(<Preview />)
Usage
Badge renders its text with CSS in a :before pseudo-element on a span tag.
You use the class name ds-badge, in conjunction with the data attribute data-count.
CSS variables and data attributes
Sizes are controlled with data-size and colors with data-color. The component will inherit from the nearest parent with these set.
| Name | Value |
|---|---|
| data-variant | base, tinted |
| data-placement | top-right, top-left, bottom-right, bottom-left |
| data-overlap | circle |
| Name | Value |
|---|---|
| --dsc-badge-background | var(--ds-color-base-default) |
| --dsc-badge-color | var(--ds-color-base-contrast-default) |
| --dsc-badge-padding | 0 calc(var(--ds-size-1) + var(--ds-size-1)/2) |
| --dsc-badge-size | calc(var(--ds-size-3) + var(--ds-size-1)/2) |
| --dsc-badge-top | inherit |
| --dsc-badge-bottom | inherit |
| --dsc-badge-left | inherit |
| --dsc-badge-right | inherit |
Examples
Floating
Not all icons have the same shape, and you may have to change where the badge should be placed.
If you want it to be floating, the class ds-badge--position must be used on a wrapper around the element that the badge is to be placed over.
data-placement is used on the wrapper to determine the placement. See the “CSS variables and data attributes” section above for supported placements.
If you are placing the badge on a circular element, you can use data-overlap="circle" to get circular overlap.
HTML
Unable to parse html
const Floating = () => ( <> <Badge.Position placement='top-right'> <Badge data-color='danger' count={2}></Badge> <EnvelopeClosedFillIcon title='Meldinger' style={{ height: '2rem', width: 'auto' }} /> </Badge.Position> </> ); render(<Floating />)
Custom placement
If you can't get the badge to be where you want it, you can use the variables --dsc-badge-top|right|bottom|left to override the placement.
This also works when using data-overlap="circle".
HTML
Unable to parse html
const CustomPlacement = () => ( <> <Badge.Position placement='top-right' style={ { '--dsc-badge-top': '16%', '--dsc-badge-right': '10%', } as CSSProperties } > <Badge data-color='accent'></Badge> <EnvelopeClosedFillIcon title='Meldinger' /> </Badge.Position> </> ); render(<CustomPlacement />)
React
- count
- Description
The number to display in the badge
- Type
number
- maxCount
- Description
The maximum number to display in the badge, when the count exceeds this number, the badge will display `{max}+`
- Type
number
- variant
- Description
Change the background color of the badge.
- Type
"base" | "tinted"- Default
base
| Name | Type | Default | Description |
|---|---|---|---|
| count | number | - | The number to display in the badge |
| maxCount | number | - | The maximum number to display in the badge, when the count exceeds this number, the badge will display `{max}+` |
| variant | "base" | "tinted" | base | Change the background color of the badge. |
BadgePosition
- placement
- Description
The placement of the badge
- Type
"top-right" | "top-left" | "bottom-right" | "bottom-left"- Default
top-right
- overlap
- Description
Use when badge is floating to change the position of the badge
- Type
"circle" | "rectangle"- Default
rectangle
| Name | Type | Default | Description |
|---|---|---|---|
| placement | "top-right" | "top-left" | "bottom-right" | "bottom-left" | top-right | The placement of the badge |
| overlap | "circle" | "rectangle" | rectangle | Use when badge is floating to change the position of the badge |