Skip to main content

Card

The Card component is a flexible container for displaying content and actions in a single topic. It supports various visual styles, loading states, and interactive behaviors.

Import

import { Card } from '@lazy-panda-ui/lazy-panda-ui';

Usage

Basic Card

import { Card } from '@lazy-panda-ui/lazy-panda-ui';

function Example() {
return (
<Card>
<Text>Basic card content</Text>
</Card>
);
}

Different Variants

import { Card } from '@lazy-panda-ui/lazy-panda-ui';

function Example() {
return (
<>
<Card variant="elevated">
<Text>Elevated card with shadow</Text>
</Card>

<Card variant="outlined">
<Text>Outlined card with border</Text>
</Card>

<Card variant="filled">
<Text>Filled card with background</Text>
</Card>

<Card variant="tonal">
<Text>Tonal card with themed background</Text>
</Card>
</>
);
}

Interactive Card

import { Card } from '@lazy-panda-ui/lazy-panda-ui';

function Example() {
const handlePress = () => {
console.log('Card pressed');
};

return (
<Card
onPress={handlePress}
variant="elevated"
elevation={3}
>
<Text>Press me!</Text>
</Card>
);
}

Loading State

import { Card } from '@lazy-panda-ui/lazy-panda-ui';

function Example() {
return (
<Card loading>
<Text>This content is loading...</Text>
</Card>
);
}

Different Sizes

import { Card } from '@lazy-panda-ui/lazy-panda-ui';

function Example() {
return (
<>
<Card size="small">
<Text>Small card</Text>
</Card>

<Card size="medium">
<Text>Medium card</Text>
</Card>

<Card size="large">
<Text>Large card</Text>
</Card>
</>
);
}

Custom Loading Component

import { Card } from '@lazy-panda-ui/lazy-panda-ui';

function Example() {
return (
<Card
loading
LoadingComponent={<CustomSpinner />}
>
<Text>Content with custom loader</Text>
</Card>
);
}

Props

Main Props

PropTypeDefaultDescription
childrenReact.ReactNodeRequiredContent to be rendered inside the card
variant'elevated' | 'outlined' | 'filled' | 'tonal''elevated'Visual variant of the card
size'small' | 'medium' | 'large''medium'Size of the card that determines padding
elevationnumber2Elevation level for shadow (only applies to 'elevated' variant)
disabledbooleanfalseWhether the card is disabled
loadingbooleanfalseWhether to show a loading indicator
onPress() => void-Called when the card is pressed

Style Props

PropTypeDescription
containerStyleViewStyleAdditional styles for the container
contentStyleViewStyleAdditional styles for the content wrapper
loadingOverlayStyleViewStyleAdditional styles for the loading overlay

Custom Components

PropTypeDescription
LoadingComponentReact.ReactNodeCustom loading indicator component

Accessibility Props

PropTypeDescription
accessibilityRoleAccessibilityRoleRole for screen readers
accessibilityLabelstringAccessibility label
accessibilityHintstringAdditional description for screen readers
testIDstringTest ID for testing

Theme Customization

Customize Card via theme.card tokens using ThemeProvider:

import { ThemeProvider, createTheme, defaultTheme } from '@lazy-panda-ui/lazy-panda-ui/theme';

const theme = createTheme(defaultTheme, {
card: {
sizes: { medium: { padding: 20 } },
borderRadius: 10,
disabledOpacity: 0.5,
variants: {
elevated: {
backgroundColor: defaultTheme.colors.surface,
shadow: { ...defaultTheme.card.variants.elevated.shadow, elevation: 4, radius: 6 },
},
outlined: { backgroundColor: '#fff', borderWidth: 1, borderColor: '#E5E5EA' },
filled: { backgroundColor: defaultTheme.colors.surfaceVariant },
tonal: { backgroundColor: defaultTheme.colors.primaryContainer },
},
loadingOverlay: { opacity: 0.75, backgroundColor: defaultTheme.colors.surface },
ripple: { color: defaultTheme.colors.onSurface },
},
});

export function App() {
return (
<ThemeProvider theme={theme}>
{/* your app */}
</ThemeProvider>
);
}