• /
  • EnglishEspañol日本語한국어Português
  • Log inStart now

Card

Draws a flexible and extensible content container.

Usage

import { Card } from 'nr1'

Examples

Basic

<Card>
<CardHeader title="Card title" subtitle="This is a subtitle" />
<CardBody>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</CardBody>
</Card>

Collapsible - Uncontrolled

<Card collapsible>
<CardHeader
title="Card title"
subtitle="This is a subtitle"
additionalInfoLink={{
label: 'See more',
onClick: console.log,
to: '#',
}}
/>
<CardBody>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</CardBody>
</Card>

Collapsible - Controlled

class MyComponent extends React.PureComponent {
constructor(...args) {
super(...args);
this.state = {
collapsed: false,
};
}
render() {
const { collapsed } = this.state;
return (
<Card
collapsible
collapsed={collapsed}
onChange={(evt, collapsed) => this.setState({ collapsed })}
>
<CardHeader
title="Card title"
subtitle="This is a subtitle"
additionalInfoLink={{
label: 'See more',
onClick: console.log,
to: '#',
}}
/>
<CardBody>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
</CardBody>
</Card>
);
}
}

Multiple collapsible cards

<Grid>
{[
{
title: 'Services - APM',
count: 11746,
},
{
title: 'Services - Open Telemetry',
count: 2845,
},
{
title: 'Hosts',
count: 1845,
},
{
title: 'Containers',
count: 394,
},
].map((section) => (
<GridItem columnSpan={12}>
<Card collapsible>
<CardHeader
title={section.title}
additionalInfoLink={{
label: `View all (${section.count})`,
onClick: console.log,
to: '#',
}}
/>
<CardBody>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.
</CardBody>
</Card>
</GridItem>
))}
</Grid>

Custom header

class MyComponent extends React.PureComponent {
constructor(...args) {
super(...args);
this.state = {
collapsed: false,
};
}
render() {
const { collapsed } = this.state;
return (
<Card
collapsible
collapsed={collapsed}
onChange={(evt, collapsed) => this.setState({ collapsed })}
>
<CardHeader>
<HeadingText>Custom header</HeadingText>
</CardHeader>
<CardBody>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
</CardBody>
</Card>
);
}
}

Sectioned card

class SectionedCard extends React.Component {
renderForm() {
return (
<Form
layoutType={Form.LAYOUT_TYPE.SPLIT}
splitSizeType={Form.SPLIT_SIZE_TYPE.SMALL}
>
<Switch label="Fit to data" />
<TextField label="Custom min" placeholder="0" />
<TextField label="Custom max" placeholder="Auto" />
<MultilineTextField
label="Config"
type={MultilineTextField.TYPE.PREFORMATTED}
placeholder={`{ showLabels: "true" }`}
/>
</Form>
);
}
render() {
return (
<Card>
<CardBody>
<CardSection collapsible>
<CardSectionHeader title="Y axis"></CardSectionHeader>
<CardSectionBody>{this.renderForm()}</CardSectionBody>
</CardSection>
<CardSection collapsible>
<CardSectionHeader title="X axis"></CardSectionHeader>
<CardSectionBody>{this.renderForm()}</CardSectionBody>
</CardSection>
</CardBody>
</Card>
);
}
}

Props

children

REQUIRED
node

Content to render inside the card.

className

string

Appends class names to the component.Should be used only for positioning and spacing purposes.

collapsed

boolean

Set this prop to control the collapsed state of the component.If defined, it turns the component into a controlled component.

collapsible

boolean

Set this prop to make the component collapsible.

defaultCollapsed

boolean

If true, the initial collapsed state of the card is collapsed.Useful when you don't want to use a controlled component.

fullHeight

boolean

Expands the card to occupy all available height.

fullWidth

boolean

Expands the card to occupy all available width.

onChange

function

This function will be called whenever the user clicks the header to collapse or expand the component. If you are controlling the state of the component, use this to set the value of the collapsed prop.

function (
event: React.MouseEvent,
collapsed: boolean
)

spacingType

enum[]

Spacing property. Spacing is defined as a tuple of zero to four values, which follow the same conventions as CSS properties like margin or padding. To omit a value, use SPACING_TYPE.OMIT.

<Array of
<One of

Card.SPACING_TYPE.EXTRA_LARGE, Card.SPACING_TYPE.LARGE, Card.SPACING_TYPE.MEDIUM, Card.SPACING_TYPE.NONE, Card.SPACING_TYPE.OMIT, Card.SPACING_TYPE.SMALL,

>
>

style

object

Should be used only for positioning and spacing purposes.

testId

string

Adds a data-test-id attribute. Use it to target the component in unit and E2E tests.For a test id to be valid, prefix it with your nerdpack id, followed up by a dot.For example, my-nerdpack.some-element.

Note: You might not see data-test-id attributes as they are removed from the DOM, to debug them pass a e2e-test query parameter to the URL.

Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.