Hopp til hovedinnhold

Hva leter du etter?

Prøv å søke etter…

Komponenter

Chip

Chip er små, interaktive komponenter som lar brukerne styre hvordan de vil se innhold. For eksempel kan de brukes til å filtrere kategorier i et søkeresultat og vise hvilke filter som er aktive.

Trykk Enter for å redigere
Unable to parse html
const Preview = () => {
  return (
    <>
      <Chip.Radio name='my-radio' value='nynorsk' defaultChecked>
        Nynorsk
      </Chip.Radio>
      <Chip.Radio name='my-radio' value='bokmål'>
        Bokmål
      </Chip.Radio>
    </>
  );
};

render(<Preview />)

Bruk

Chip bruker to forskjellige HTML-strukturer, men begge har klassenavnet ds-chip.

Som radio eller checkbox

Legg merke til at vi legger <input> inni <label>, dette betyr at du ikke trenger å koble de sammen med for og id.

Som removable eller button

En removable chip bruker et <button> element, men det er lagt til data-removable="true" for å indikere at det er en removable chip. Da vil et kryss vises til høyre i chip, dette tegnes med CSS.

Med tekst over flere linjer

Chips tvinger som standard tekst til en enkelt linje, og forkorter teksten med tre punktum hvis teksten er for lang. Bruk data-wrap="wrap" dersom du ønsker å tillate tekst over flere linjer inne i chip.

CSS variablar og data-attributter

Chip bruker også ds-input internt når det er radio eller checkbox.

Størrelser styres med data-size og farger med data-color. Komponenten vil arve nærmeste forelder med disse satt.

CSS-variabler
NavnVerdi
--dsc-chip-background--activevar(--ds-color-surface-active)
--dsc-chip-background--checked--activevar(--ds-color-base-active)
--dsc-chip-background--checked--hovervar(--ds-color-base-hover)
--dsc-chip-background--checkedvar(--ds-color-base-default)
--dsc-chip-background--hovervar(--ds-color-surface-hover)
--dsc-chip-backgroundvar(--ds-color-surface-tinted)
--dsc-chip-border-color--checkedtransparent
--dsc-chip-border-colorvar(--ds-color-border-subtle)
--dsc-chip-border-radius--checkbox-inputvar(--ds-border-radius-sm)
--dsc-chip-border-radius--checkboxvar(--ds-border-radius-md)
--dsc-chip-border-radiuscalc(var(--dsc-chip-height)/2)
--dsc-chip-border-stylesolid
--dsc-chip-border-widthvar(--ds-border-width-default)
--dsc-chip-colorvar(--ds-color-text-default)
--dsc-chip-heightvar(--ds-size-8)
--dsc-chip-icon-sizevar(--ds-icon-size)
--dsc-chip-icon-urlurl("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1em' height='1em' fill='none' viewBox='0 0 24 24'%3E%3Cpath fill='currentColor' d='M6.53 5.47a.75.75 0 0 0-1.06 1.06L10.94 12l-5.47 5.47a.75.75 0 1 0 1.06 1.06L12 13.06l5.47 5.47a.75.75 0 1 0 1.06-1.06L13.06 12l5.47-5.47a.75.75 0 0 0-1.06-1.06L12 10.94z'/%3E%3C/svg%3E")
--dsc-chip-input-accent-colorvar(--ds-color-base-contrast-default)
--dsc-chip-input-colorvar(--ds-color-text-subtle)
--dsc-chip-input-sizevar(--ds-size-5)
--dsc-chip-input-stroke-colorvar(--ds-color-base-default)
--dsc-chip-padding-inlinevar(--ds-size-3)
--dsc-chip-spacingcalc((var(--dsc-chip-height) - var(--dsc-chip-input-size))/2)
--dsc-input-backgroundtransparent
--dsc-input-border-colorvar(--dsc-chip-input-color)
--dsc-input-accent-colorvar(--dsc-chip-input-accent-color)
--dsc-input-stroke-colorvar(--dsc-chip-input-stroke-color)
--dsc-input-size--togglevar(--dsc-chip-input-size)
--dsc-input-outline-width--hover0
Data-attributter
NavnVerdi
data-wrapwrap
data-removable

React

command
Type
string
commandfor
Type
string
asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior.

Type
boolean
Default
false
data-wrap
Description

Change the text wrapping behavior of the chip. Use `wrap` to allow the chip to wrap text, and `nowrap` to prevent it from wrapping.

Type
"nowrap" | "wrap"
Default
'nowrap'
NameTypeDefaultDescription
commandstring-

-

commandforstring-

-

asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

data-wrap"nowrap" | "wrap"'nowrap'

Change the text wrapping behavior of the chip. Use `wrap` to allow the chip to wrap text, and `nowrap` to prevent it from wrapping.

ChipRemovable

command
Type
string
commandfor
Type
string
asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior.

Type
boolean
Default
false
data-wrap
Description

Change the text wrapping behavior of the chip. Use `wrap` to allow the chip to wrap text, and `nowrap` to prevent it from wrapping.

Type
"nowrap" | "wrap"
Default
'nowrap'
NameTypeDefaultDescription
commandstring-

-

commandforstring-

-

asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

data-wrap"nowrap" | "wrap"'nowrap'

Change the text wrapping behavior of the chip. Use `wrap` to allow the chip to wrap text, and `nowrap` to prevent it from wrapping.

ChipCheckbox

asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior.

Type
boolean
Default
false
data-wrap
Description

Change the text wrapping behavior of the chip. Use `wrap` to allow the chip to wrap text, and `nowrap` to prevent it from wrapping.

Type
"nowrap" | "wrap"
Default
'nowrap'
NameTypeDefaultDescription
asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

data-wrap"nowrap" | "wrap"'nowrap'

Change the text wrapping behavior of the chip. Use `wrap` to allow the chip to wrap text, and `nowrap` to prevent it from wrapping.

ChipRadio

asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior.

Type
boolean
Default
false
data-wrap
Description

Change the text wrapping behavior of the chip. Use `wrap` to allow the chip to wrap text, and `nowrap` to prevent it from wrapping.

Type
"nowrap" | "wrap"
Default
'nowrap'
NameTypeDefaultDescription
asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

data-wrap"nowrap" | "wrap"'nowrap'

Change the text wrapping behavior of the chip. Use `wrap` to allow the chip to wrap text, and `nowrap` to prevent it from wrapping.

Rediger denne siden på github.com (åpnes i ny fane)