Card
Container with header, content and footer sections.
Installation
Terminal
npx magic-native-ui@latest add cardUsage
The example running in the preview above. Imports use the default aliases from components.json.
card-demo.tsx
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
import { Text } from '@/components/ui/text'
export function CardDemo() {
return (
<Card className="w-full">
<CardHeader>
<CardTitle>Project settings</CardTitle>
<CardDescription>Manage how this project behaves.</CardDescription>
</CardHeader>
<CardContent>
<Text>Card content sits here.</Text>
</CardContent>
</Card>
)
}Component source
What the CLI copies into your project. Once it is there, the code is yours to edit.
registry/ui/card.tsx
import * as React from 'react'
import { View, type ViewProps } from 'react-native'
import { Text, TextClassContext } from '@/registry/ui/text'
import { cn } from '@/registry/lib/utils'
function Card({ className, ...props }: ViewProps) {
return (
<TextClassContext.Provider value="text-card-foreground">
<View
className={cn('rounded-lg border border-border bg-card shadow-sm', className)}
{...props}
/>
</TextClassContext.Provider>
)
}
function CardHeader({ className, ...props }: ViewProps) {
return <View className={cn('gap-1.5 p-6', className)} {...props} />
}
function CardTitle({ className, ...props }: React.ComponentProps<typeof Text>) {
return (
<Text
role="heading"
aria-level={3}
className={cn('text-2xl font-semibold leading-none tracking-tight', className)}
{...props}
/>
)
}
function CardDescription({ className, ...props }: React.ComponentProps<typeof Text>) {
return <Text className={cn('text-sm text-muted-foreground', className)} {...props} />
}
function CardContent({ className, ...props }: ViewProps) {
return <View className={cn('p-6 pt-0', className)} {...props} />
}
function CardFooter({ className, ...props }: ViewProps) {
return <View className={cn('flex-row items-center p-6 pt-0', className)} {...props} />
}
export { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle }