Import
import { Card } from '@dnb/eufemia'
Description
Card
is a block section element showing the white box with rounded gray borders, adding spacing automatically.
It uses Flex.Item under the hood. When one of these properties were given, stack
, direction
or spacing
– the Flex.Container will be used.
import { Card } from '@dnb/eufemia'import { Form, Field } from '@dnb/eufemia/extensions/forms'render(<Form.Handler data={existingData} onSubmit={submitHandler}><Card><Field.Email path="/dataPath" /><Form.ButtonRow><Form.SubmitButton /></Form.ButtonRow></Card></Form.Handler>,)
Accessibility
It uses a section
element. Which allows you to add an aria-label
or aria-labelledby
to provide screen readers with landmarks.
<Card aria-labelledby="unique-id"> <Form.SubHeading id="unique-id" space={0}> Heading </Form.SubHeading> <P>Content inside a landmark ...</P> </Card>
Demo
Default border
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi cursus pharetra elit in bibendum.
Praesent nunc ipsum, convallis eget convallis gravida, vehicula vitae metus.
<Card> <P> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi cursus pharetra elit in bibendum. </P> <P> Praesent nunc ipsum, convallis eget convallis gravida, vehicula vitae metus. </P> </Card>
Vertical fields
<Card> <Flex.Vertical> <Field.String label="Label" value="Value" /> <Field.String label="Label" value="Value" /> </Flex.Vertical> </Card>
Horizontal fields
<Card> <Flex.Horizontal> <Field.String label="Label" value="Value" width="small" /> <Field.String label="Label" value="Value" width="stretch" /> </Flex.Horizontal> </Card>
Stack
The Card components needs to have stack={true}
or align="stretch"
in order to stretch its children components.
For form components, you should use stack={true}
to get the correct spacing.
<Card stack> <Field.String label="Label" value="Value" /> <Field.String label="Label" value="Value" /> <Hr /> <Form.SubmitButton /> </Card>
Nested Cards
Nested cards have responsive={false}
by default and will not behave responsive.
First Card
Second Card
Third Card (for edge cases only)
<Card> <P>First Card</P> <Card top> <P>Second Card</P> <Card top> <P>Third Card (for edge cases only)</P> </Card> </Card> </Card>
Without padding
no inner space
<Card innerSpace={false} align="stretch"> <P>no inner space</P> </Card>
With nested Section
The Card components needs to have stack={true}
or align="stretch"
in order to stretch its children components.
Card with a nested Section
no inner space
no inner space
<Flex.Stack> <Card gap="x-small" align="stretch"> <Form.SubHeading>Card with a nested Section</Form.SubHeading> <Section variant="info" innerSpace={{ top: 'small', bottom: 'medium', }} > <Field.String width="medium" label="In nested Section" /> </Section> </Card> <Card innerSpace="x-large" stack> <Section variant="info" innerSpace={{ top: 'small', bottom: 'medium', }} > <Field.String width="medium" label="Card with a 'x-large' inner space" /> </Section> </Card> <Card innerSpace={false} align="stretch"> <P>no inner space</P> <Section innerSpace backgroundColor="var(--card-outline-color)"> <Field.String width="medium" label="Card with no inner space" /> </Section> <P>no inner space</P> </Card> </Flex.Stack>
With Table
Column 1 | Column 2 | Column 3 |
---|---|---|
Row 1 | Row 1 | Row 1 |