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
REQUIREDnode | Content to render inside the card. |
string | Appends class names to the component.Should be used only for positioning and spacing purposes. |
boolean | Set this prop to control the collapsed state of the component.If defined, it turns the component into a controlled component. |
boolean | Set this prop to make the component collapsible. |
boolean | If |
boolean | Expands the card to occupy all available height. |
boolean | Expands the card to occupy all available width. |
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 function ( |
enum[] | Spacing property. Spacing is defined as a tuple of zero to four values, which follow the same conventions as CSS properties like <Array of |
object | Should be used only for positioning and spacing purposes. |
string | Adds a Note: You might not see |