Card Component
Light | Dark |
---|---|
![]() |
![]() |
The Card component is a flexible and versatile UI element designed using a compound component pattern. It supports both vertical and horizontal layouts, optional images or icons, and structured content sections. The component provides a clean, modern interface for displaying organized information.
Pre-requisite
-
Ensure you have the
@neo4j-ndl
library installed in your project to use thisCard
component.
Usage
To use the Card component in your application, follow these steps:
-
Import the component and required assets:
import Card from './path/to/Card'; import testImg from './assets/cardImg.png'; import { Button, Typography } from '@neo4j-ndl/react'; import { AcademicCapIconOutline, RocketLaunchIconOutline } from '@neo4j-ndl/react/icons';
-
Use the compound component pattern to build your card:
// Vertical card with image and full content <Card layout='vertical' imageSrc={testImg} imageSize='full' className='h-auto w-96'> <Card.Header>Header text</Card.Header> <Card.Subheader>Subtitle or description</Card.Subheader> <Card.Content> <p>Some description about relatively important things.</p> <ul className='list-disc list-inside'> <li>Key information item 1</li> <li>Key information item 2</li> <li>Key information item 3</li> </ul> <div className='flex flex-row min-w-full justify-between'> <Button size='small' color='danger' className='w-2/5 mx-2.5'> <Typography variant='body-small'>Cancel</Typography> </Button> <Button size='small' color='primary' className='w-2/5 mx-2.5'> <Typography variant='body-small'>Confirm</Typography> </Button> </div> </Card.Content> </Card> // Horizontal card with icon <Card layout='horizontal' iconSystem={AcademicCapIconOutline}> <Card.Header>Header text</Card.Header> <Card.Content> <p>Content for horizontal layout card.</p> </Card.Content> </Card>
Component Props
The main Card component accepts the following props:
Name | Description | Required |
---|---|---|
|
Layout orientation: |
Yes |
|
Path to the image to display in the card |
No |
|
Size of the image: |
No |
|
React component for an icon from |
No |
|
Child components (Card.Header, Card.Subheader, Card.Content) |
Yes |
|
Additional CSS classes for styling |
No |
Compound Components
The Card component uses a compound component pattern with three sub-components:
Card.Header
Displays the main title of the card using Typography variant='h5'
.
<Card.Header>Your Card Title</Card.Header>
Key components
Layout System
The Card component supports two layout orientations that automatically adjust the content flow:
Vertical Layout: Content stacks vertically with image/icon at the top
<Card layout='vertical' imageSrc={testImg} imageSize='full'>
{/* Content flows vertically */}
</Card>
Horizontal Layout: Content flows horizontally with image/icon on the left
<Card layout='horizontal' imageSrc={testImg} imageSize='full' className='h-72'>
{/* Content flows horizontally */}
</Card>
Image and Icon Support
The component supports either images or system icons, but not both simultaneously:
Image Support:
- imageSize='full'
: Full-width/height image that adapts to layout
- imageSize='small'
: Small 16x16 image for minimal presence
// Full-size image
<Card layout='vertical' imageSrc={testImg} imageSize='full'>
{/* Content */}
</Card>
// Small image
<Card layout='horizontal' imageSrc={testImg} imageSize='small'>
{/* Content */}
</Card>
Icon Support: Uses Neo4j Design Language icons
<Card layout='vertical' iconSystem={RocketLaunchIconOutline}>
{/* Content */}
</Card>
Compound Component Architecture
The Card uses React’s compound component pattern, allowing flexible content composition:
const Card: React.FC<CardProps> & {
Header: React.FC<CardHeaderProps>;
Subheader: React.FC<CardSubheaderProps>;
Content: React.FC<CardContentProps>;
} = ({ layout, imageSrc, imageSize, iconSystem, children, className }) => {
// Component implementation
};
Card.Header = Header;
Card.Subheader = Subheader;
Card.Content = Content;
Responsive Design
The component automatically adapts to different layouts:
-
Horizontal layout: Image takes 1/3 width, content takes 2/3 width
-
Vertical layout: Image takes full width, content stacks below
-
Flexible styling: Supports custom className for additional styling
// Grid layout for multiple cards
<div className='grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8'>
{cards.map((card, index) => (
<Card key={index} layout='vertical' className='h-auto w-96'>
{/* Card content */}
</Card>
))}
</div>
Content Flexibility
Each compound component provides semantic structure:
-
Header: Main title with
h5
typography -
Subheader: Secondary information with
subheading-large
typography -
Content: Flexible container supporting any React content (text, lists, buttons, etc.)
<Card.Content>
<p>Text content</p>
<ul className='list-disc list-inside'>
<li>List items</li>
</ul>
<div className='flex justify-between'>
<Button>Action 1</Button>
<Button>Action 2</Button>
</div>
</Card.Content>