Components
Details
Details is a collapsible component that allows the user to show or hide content.
React
const PreviewEn = () => { return ( <Details> <Details.Summary> Who can register in the Volunteer Register? </Details.Summary> <Details.Content> To be registered in the Volunteer Register, the organization must conduct voluntary activities. Only associations, foundations, and limited companies can be registered. The business cannot distribute funds to individuals. The business must have a board. </Details.Content> </Details> ); }; render(<PreviewEn />)
- variant
- Description
Change the background color of the details.
- Type
"default" | "tinted"- Default
default
- open
- Description
Controls open-state. Using this removes automatic control of open-state
- Type
boolean- Default
undefined
- defaultOpen
- Description
Defaults the details to open if not controlled
- Type
boolean- Default
false
- onToggle
- Description
Callback function when Details toggles due to click on summary or find in page-search
- Type
(((event: Event) => void) & ((event: Event) => void)) | (((event: Event) => void) & ((event: Event) => void))
- children
- Description
Content should be one `<Details.Summary>` and `<Details.Content>`
- Type
any
| Name | Type | Default | Description |
|---|---|---|---|
| variant | "default" | "tinted" | default | Change the background color of the details. |
| open | boolean | undefined | Controls open-state. Using this removes automatic control of open-state |
| defaultOpen | boolean | false | Defaults the details to open if not controlled |
| onToggle | (((event: Event) => void) & ((event: Event) => void)) | (((event: Event) => void) & ((event: Event) => void)) | - | Callback function when Details toggles due to click on summary or find in page-search |
| children | any | - | Content should be one `<Details.Summary>` and `<Details.Content>` |
DetailsSummary
- children
- Description
Heading text
- Type
any
| Name | Type | Default | Description |
|---|---|---|---|
| children | any | - | Heading text |
Usage
Examples
Frame and variant
If you put Details as the only child of Card, you get a frame around the whole Details.
You can also use variant="tinted" on either Details or Card to get a lighter background.
React
const InCardWithColorEn = () => { return ( <> <Card data-color='brand3' data-variant='tinted'> <Details> <Details.Summary> How do I get assigned a hunter number? </Details.Summary> <Details.Content> You will automatically be assigned a hunter number and registered in the Hunter Register when you have passed the hunter's exam. </Details.Content> </Details> <Details> <Details.Summary> I have forgotten my hunter number. Where can I find it? </Details.Summary> <Details.Content> <Paragraph> You can find this by logging in to{' '} <Link href='https://minjegerside.brreg.no/'>My Page</Link> </Paragraph> </Details.Content> </Details> </Card> <br /> <Card data-color='brand1'> <Details> <Details.Summary>Attachments</Details.Summary> <Details.Content> Attachment 1, attachment 2, attachment 3 </Details.Content> </Details> </Card> </> ); }; render(<InCardWithColorEn />)
Controlled
Details keeps track of whether it is open or closed, but this can also be controlled externally.
React
const Controlled = () => { const [open1, setOpen1] = useState(false); const [open2, setOpen2] = useState(false); const isOpen = [open1, open2].every(Boolean); const toggleOpen = () => { setOpen1(!isOpen); setOpen2(!isOpen); }; return ( <> <Button variant='tertiary' onClick={toggleOpen} data-size='sm'> {isOpen ? ( <> <ChevronDownUpIcon aria-hidden /> Close both </> ) : ( <> <ChevronUpDownIcon aria-hidden /> Open both </> )} </Button> <br /> <Details open={open1} onToggle={() => setOpen1(!open1)}> <Details.Summary>Enkeltpersonforetak</Details.Summary> <Details.Content> Skal du starte for deg selv? Enkeltpersonforetak er ofte den enkleste måten å etablere bedrift på. Denne organisasjonsformen har både fordeler og ulemper. Det gir deg stor grad av frihet, men kan også gi betydelig risiko fordi du har personlig ansvar for økonomien. </Details.Content> </Details> <Details open={open2} onToggle={() => setOpen2(!open2)}> <Details.Summary>Aksjeselskap (AS)</Details.Summary> <Details.Content> Planlegger du å starte næringsvirksomhet alene eller sammen med andre? Innebærer næringsvirksomheten en økonomisk risiko? Vil du ha rettigheter som arbeidstaker og muligheten til at andre kan investere i selskapet ditt? Da kan aksjeselskap være en hensiktsmessig organisasjonsform. </Details.Content> </Details> </> ); }; render(<Controlled />)
HTML
Details is built on the web component u-details (github.io), which you can use.
It is built functionally similar to the native element <details>, but with better accessibility.
You use the class name .ds-details on the main element.
You can choose not to have a nested <div> around the main content, but if you have this, it gets margin.
If you want to use tinted variant, add the attribute data-variant="tinted" to the main element or .ds-card.
CSS variables and data attributes
| Name | Value |
|---|---|
| --dsc-details-border-block-wdith | var( --ds-border-width-default ) |
| --dsc-details-border-block-width | var(--dsc-details-border-block-wdith) |
| --dsc-details-border-block-style | solid |
| --dsc-details-border-color | var(--ds-color-border-subtle) |
| --dsc-details-icon-gap | var(--ds-size-2) |
| --dsc-details-icon-size | var(--ds-size-6) |
| --dsc-details-icon-url | url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5.97 9.47a.75.75 0 0 1 1.06 0L12 14.44l4.97-4.97a.75.75 0 1 1 1.06 1.06l-5.5 5.5a.75.75 0 0 1-1.06 0l-5.5-5.5a.75.75 0 0 1 0-1.06'/%3E%3C/svg%3E") |
| --dsc-details-padding | var(--ds-size-2) var(--ds-size-4) |
| --dsc-details-size | var(--ds-size-14) |
| --dsc-details-background | var(--ds-color-surface-default) |
| --dsc-details-summary-color | var(--ds-color-text-default) |
| --dsc-details-summary-background--hover | var(--ds-color-surface-tinted) |
| --dsc-details-summary-background--open | var(--ds-color-surface-tinted) |
| --dsc-details-summary-background | var(--ds-color-surface-default) |
| Name | Value |
|---|---|
| data-variant | default, tinted |