Komponenter
Badge
Badge er ein ikkje-interaktiv komponent som viser status med eller utan tal. Bruk tag dersom du skal ha tekst i staden for tal.
HTML
Unable to parse html
const Preview = () => { return <Badge count={15} maxCount={9} />; }; render(<Preview />)
Bruk
Badge rendrar teksten sin med CSS i eit :before-pseudoelement på ein span-tagg.
Du brukar klassenavnet ds-badge, i saman med data-attributt data-count.
CSS variabler og data-attributter
Størrelsar styrast med data-size og fargar med data-color. Komponenten vil arve næraste forelder med desse satt.
| Navn | Verdi |
|---|---|
| data-variant | base, tinted |
| data-placement | top-right, top-left, bottom-right, bottom-left |
| data-overlap | circle |
| Navn | Verdi |
|---|---|
| --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 |
Eksempel
Flytande
Dersom du vil ha den flytande, så må ds-badge--position klassen nyttast på ein wrapper rundt elementet som badge skal plasserast over.
Bruk data-placement på wrapperen for å bestemme plasseringa. Sjå seksjonen «CSS variabler og data-attributter» under for støtta verdiar.
Ska badge plasserast på et sirkulært element kan du også setje data-overlap="circle" for å få sirkulær 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 />)
Egendefinert plassering
Dersom du ikkje får badge til å liggje der du ynskjer, kan du bruke variablene --dsc-badge-top|right|bottom|left for å overstyre plasseringa.
Dette fungerer også når du bruker 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 |