Components
Chip
Chip are small, interactive components that allow users to control how they want to see content. For example, they can be used to filter categories in a search result and show which filters are active.
React
const PreviewEn = () => { return ( <> <Chip.Radio name='my-radio' value='english' defaultChecked> English </Chip.Radio> <Chip.Radio name='my-radio' value='norwegian'> Norwegian </Chip.Radio> </> ); }; render(<PreviewEn />)
- asChild
- Description
Change the default rendered element for the one passed as a child, merging their props and behavior.
- Type
boolean- Default
false
| Name | Type | Default | Description |
|---|---|---|---|
| asChild | boolean | false | Change the default rendered element for the one passed as a child, merging their props and behavior. |
ChipRemovable
- asChild
- Description
Change the default rendered element for the one passed as a child, merging their props and behavior.
- Type
boolean- Default
false
| Name | Type | Default | Description |
|---|---|---|---|
| asChild | boolean | false | Change the default rendered element for the one passed as a child, merging their props and behavior. |
ChipCheckbox
- asChild
- Description
Change the default rendered element for the one passed as a child, merging their props and behavior.
- Type
boolean- Default
false
| Name | Type | Default | Description |
|---|---|---|---|
| asChild | boolean | false | Change the default rendered element for the one passed as a child, merging their props and behavior. |
ChipRadio
- asChild
- Description
Change the default rendered element for the one passed as a child, merging their props and behavior.
- Type
boolean- Default
false
| Name | Type | Default | Description |
|---|---|---|---|
| asChild | boolean | false | Change the default rendered element for the one passed as a child, merging their props and behavior. |
Usage
Examples
Chip.Checkbox
React
const CheckboxVariantEn = () => { return <Chip.Checkbox>English</Chip.Checkbox>; }; render(<CheckboxVariantEn />)
Chip.Removable
Remember aria-label if the contents of Chip do not explain that it can be removed.
React
const RemovableEn = () => { return <Chip.Removable aria-label='Delete Norway'>Norway</Chip.Removable>; }; render(<RemovableEn />)
Chip.Button
React
const AsButtonEn = () => { return <Chip.Button>Clear all filters</Chip.Button>; }; render(<AsButtonEn />)
HTML
Chip uses two different HTML structures, but both have the class name ds-chip.
Like radio or checkbox
Notice that we put <input> inside <label>, this means you don't need to connect them with for and id.
As removable or button
A removable Chip uses a <button> element, but data-removable="true" has been added to indicate that it is a removable Chip.
Then a cross will appear to the right of Chip, this is drawn with CSS.
CSS variables and data attributes
Chip also uses ds-input internally when it is a radio or checkbox.
| Name | Value |
|---|---|
| --dsc-chip-background | var(--ds-color-surface-tinted) |
| --dsc-chip-background--hover | var(--ds-color-surface-hover) |
| --dsc-chip-background--active | var(--ds-color-surface-active) |
| --dsc-chip-background--checked | var(--ds-color-base-default) |
| --dsc-chip-background--checked--hover | var(--ds-color-base-hover) |
| --dsc-chip-background--checked--active | var(--ds-color-base-active) |
| --dsc-chip-border-width | var(--ds-border-width-default) |
| --dsc-chip-border-style | solid |
| --dsc-chip-border-color | var(--ds-color-border-subtle) |
| --dsc-chip-border-color--checked | transparent |
| --dsc-chip-color | var(--ds-color-text-default) |
| --dsc-chip-input-accent-color | var(--ds-color-base-contrast-default) |
| --dsc-chip-input-color | var(--ds-color-text-subtle) |
| --dsc-chip-input-stroke-color | var(--ds-color-base-default) |
| --dsc-chip-border-radius | var(--ds-border-radius-full) |
| --dsc-chip-border-radius--checkbox | var(--ds-border-radius-md) |
| --dsc-chip-border-radius--checkbox-input | var(--ds-border-radius-sm) |
| --dsc-chip-height | var(--ds-size-8) |
| --dsc-chip-icon-size | var(--ds-size-7) |
| --dsc-chip-icon-url | url("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-size | var(--ds-size-5) |
| --dsc-chip-spacing | calc((var(--dsc-chip-height) - var(--dsc-chip-input-size))/2) |
| --dsc-input-background | transparent |
| --dsc-input-border-color | var(--dsc-chip-input-color) |
| --dsc-input-accent-color | var(--dsc-chip-input-accent-color) |
| --dsc-input-stroke-color | var(--dsc-chip-input-stroke-color) |
| --dsc-input-size--toggle | var(--dsc-chip-input-size) |
| --dsc-input-outline-width--hover | 0 |
| Name | Value |
|---|---|
| data-removable |