# Card

> Groups related content on its own surface.

A card groups related content, such as one release or one document, on its own surface.

## When to use

- Use it for a self-contained item with a title and, often, actions.
- Use plain sections, not cards, to split one long form or page.
- Don't nest cards inside cards.

_Live preview of the React and Vue versions: https://design.sosialoka.tech/components/card/_

### Do and don't

- **Do:** Separate cards from the page with a border.
- **Don't:** Don't lift every card with a shadow; save shadows for what floats over the page.

## Anatomy

1. Header: title and description
2. Content
3. Footer with actions

Header (title, description, optional action), content, then footer with actions. The card sits on `card` with a `border` and `radius-lg` (12px). It has no shadow by default: a border separates it from the page. Add `shadow-md` only for a card that floats, such as the header card of the dashboard.

## Variants

There is one style. Pass `shadow-md` for a floating card.

## Props

| React | Vue | Flutter | Type | Default | Use |
| --- | --- | --- | --- | --- | --- |
| `CardHeader`, `CardTitle`, `CardDescription` | same names | `title`, `description` | element | none | The heading area. |
| `CardContent` | `CardContent` | `child` | element | none | The body. |
| `CardFooter` | `CardFooter` | `footer` | element | none | Actions. |
| `className` | `class` | `width`, `padding` | string | none | Size and floating shadow. |

## Code

**React**
```tsx
import { Button } from "@/components/ui/button"
import {
  Card,
  CardContent,
  CardDescription,
  CardFooter,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"

export default function CardDemo() {
  return (
    <Card className="w-full max-w-sm">
      <CardHeader>
        <CardTitle>Rilis baru</CardTitle>
        <CardDescription>Single "Senja di Kota" siap dikirim ke semua platform.</CardDescription>
      </CardHeader>
      <CardContent>
        <p className="text-sm text-muted-foreground">Periksa metadata dan artwork sebelum kamu kirim.</p>
      </CardContent>
      <CardFooter className="gap-2">
        <Button>Kirim</Button>
        <Button variant="outline">Periksa dulu</Button>
      </CardFooter>
    </Card>
  )
}
```

**Vue**
```vue
<script setup lang="ts">
import { Button } from "@/components/ui/button"
import {
  Card,
  CardContent,
  CardDescription,
  CardFooter,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
</script>

<template>
  <Card class="w-full max-w-sm">
    <CardHeader>
      <CardTitle>Rilis baru</CardTitle>
      <CardDescription>Single "Senja di Kota" siap dikirim ke semua platform.</CardDescription>
    </CardHeader>
    <CardContent>
      <p class="text-sm text-muted-foreground">Periksa metadata dan artwork sebelum kamu kirim.</p>
    </CardContent>
    <CardFooter class="gap-2">
      <Button>Kirim</Button>
      <Button variant="outline">Periksa dulu</Button>
    </CardFooter>
  </Card>
</template>
```

**Flutter**
```dart
import 'package:flutter/widgets.dart';
import 'package:shadcn_ui/shadcn_ui.dart';

class CardDemo extends StatelessWidget {
  const CardDemo({super.key});

  @override
  Widget build(BuildContext context) {
    final theme = ShadTheme.of(context);
    return ShadCard(
      width: 384,
      title: Text('Rilis baru', style: theme.textTheme.h4),
      description: const Text('Single "Senja di Kota" siap dikirim ke semua platform.'),
      footer: Row(
        children: [
          ShadButton(onPressed: () {}, child: const Text('Kirim')),
          const SizedBox(width: 8),
          ShadButton.outline(onPressed: () {}, child: const Text('Periksa dulu')),
        ],
      ),
      child: const Padding(
        padding: EdgeInsets.symmetric(vertical: 16),
        child: Text('Periksa metadata dan artwork sebelum kamu kirim.'),
      ),
    );
  }
}
```

## Install

**React**
```bash
npx shadcn@latest add https://design.sosialoka.tech/r/react/card.json
```

**Vue**
```bash
npx shadcn-vue@latest add https://design.sosialoka.tech/r/vue/card.json
```

## Accessibility

- A card is a plain container; give its title a real heading level in your page when it starts a section.
- Keep one main action per card, so the footer reads clearly.
