# Card
A bordered surface grouping a heading, content and actions.
Source page: https://dinachi.dev/docs/components/card

## Installation
```bash
npx @dinachi/cli@latest add card
```
Adds to your project:
- `components/ui/card/card.tsx`
- `components/ui/card/index.ts`

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

export function UsageCard() {
  return (
    <Card className="max-w-sm">
      <CardHeader>
        <CardTitle>Usage</CardTitle>
        <CardDescription>Requests this billing period.</CardDescription>
      </CardHeader>
      <CardContent>
        <p className="text-3xl font-semibold">12,480</p>
      </CardContent>
      <CardFooter>
        <Button variant="outline">View details</Button>
      </CardFooter>
    </Card>
  )
}
```

## Anatomy
```tsx
<Card>
  <CardHeader>
    <CardTitle />
    <CardDescription />
  </CardHeader>
  <CardContent />
  <CardFooter />
</Card>
```
- `Card`: The bordered, rounded surface.
- `CardHeader`: Stacks title and description, padded.
- `CardTitle`: The heading, rendered as an `h3`.
- `CardDescription`: Muted text under the title.
- `CardContent`: The body, without top padding.
- `CardFooter`: A vertically centred flex row for actions.

## Examples

### With footer
A form card with actions in the footer.
```tsx
import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter } from '@/components/ui/card';
import { Button } from '@/components/ui/button';

export function Example() {
  return (
    <Card className="w-full max-w-sm">
      <CardHeader>
        <CardTitle>Create Account</CardTitle>
        <CardDescription>Enter your details to create a new account.</CardDescription>
      </CardHeader>
      <CardContent className="space-y-4">
        <div className="space-y-2">
          <label htmlFor="name" className="text-sm font-medium">Name</label>
          <input id="name" placeholder="John Doe" className="w-full rounded-md border border-input bg-background px-3 py-2 text-sm" />
        </div>
        <div className="space-y-2">
          <label htmlFor="email" className="text-sm font-medium">Email</label>
          <input id="email" type="email" placeholder="john@example.com" className="w-full rounded-md border border-input bg-background px-3 py-2 text-sm" />
        </div>
      </CardContent>
      <CardFooter className="flex justify-between">
        <Button variant="outline">Cancel</Button>
        <Button>Create</Button>
      </CardFooter>
    </Card>
  );
}
```

### Default
A header with a title and description, then content.
```tsx
import { Card, CardHeader, CardTitle, CardDescription, CardContent } from '@/components/ui/card';

export function Example() {
  return (
    <Card className="w-full max-w-sm">
      <CardHeader>
        <CardTitle>Card Title</CardTitle>
        <CardDescription>Card description goes here.</CardDescription>
      </CardHeader>
      <CardContent>
        <p className="text-sm text-muted-foreground">
          This is the main content area of the card.
        </p>
      </CardContent>
    </Card>
  );
}
```

### Pricing
Two cards side by side for comparing plans.
```tsx
import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter } from '@/components/ui/card';
import { Button } from '@/components/ui/button';

export function Example() {
  return (
    <div className="grid gap-4 md:grid-cols-2 w-full max-w-2xl">
      <Card>
        <CardHeader>
          <CardTitle>Free Plan</CardTitle>
          <CardDescription>For personal use</CardDescription>
        </CardHeader>
        <CardContent>
          <p className="text-3xl font-bold">$0</p>
          <p className="text-sm text-muted-foreground">per month</p>
        </CardContent>
        <CardFooter>
          <Button className="w-full" variant="outline">Get Started</Button>
        </CardFooter>
      </Card>
      <Card className="border-primary">
        <CardHeader>
          <CardTitle>Pro Plan</CardTitle>
          <CardDescription>For teams and businesses</CardDescription>
        </CardHeader>
        <CardContent>
          <p className="text-3xl font-bold">$29</p>
          <p className="text-sm text-muted-foreground">per month</p>
        </CardContent>
        <CardFooter>
          <Button className="w-full">Subscribe</Button>
        </CardFooter>
      </Card>
    </div>
  );
}
```

### Interactive
A card with a hover shadow and a progress bar.
```tsx
import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter } from '@/components/ui/card';
import { Button } from '@/components/ui/button';

export function Example() {
  return (
    <Card className="w-full max-w-sm hover:shadow-md transition-shadow cursor-pointer">
      <CardHeader>
        <div className="flex items-center justify-between">
          <CardTitle>Project Status</CardTitle>
          <span className="text-xs bg-green-100 text-green-800 px-2 py-1 rounded-full">Active</span>
        </div>
        <CardDescription>Last updated 2 hours ago</CardDescription>
      </CardHeader>
      <CardContent>
        <div className="space-y-2">
          <div className="flex justify-between text-sm">
            <span>Progress</span>
            <span className="font-medium">75%</span>
          </div>
          <div className="w-full h-2 bg-secondary rounded-full overflow-hidden">
            <div className="h-full bg-primary rounded-full" style={{ width: '75%' }} />
          </div>
        </div>
      </CardContent>
      <CardFooter>
        <Button variant="ghost" size="sm" className="ml-auto">View Details →</Button>
      </CardFooter>
    </Card>
  );
}
```

## Notes

### Heading level
`CardTitle` is always an `h3`. To change it, edit the copied file or put your own heading in `CardHeader`.

### Spacing
Every part is a padded div and any can be left out. `CardContent` and `CardFooter` have no top padding; add `pt-6` when one comes first.

### Agents
- Not registered with the agent bridge.
- Inside an [`AgentProvider`](/docs/components/agent), `data-agent-in="Billing"` on a Card names the container its controls are listed `in`.
- An action attached to a card through `useAgentAction` is listed as a `region`, named by its `aria-label` or else its first heading, the `CardTitle`.

## API reference

### Card
The bordered, rounded surface.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` | - | Merged over the card classes. |

### CardHeader
Stacks title and description, padded.

Takes the props of the element it renders.

### CardTitle
The heading, rendered as an `h3`.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` | - | The title text. |

### CardDescription
Muted text under the title.

Takes the props of the element it renders.

### CardContent
The body, without top padding.

Takes the props of the element it renders.

### CardFooter
A vertically centred flex row for actions.

Takes the props of the element it renders.

## Accessibility
- Card has no role; its `CardTitle` heading gives it structure.
- For a clickable card, put the link or button on the title.

## Source
`components/ui/card/card.tsx`
```tsx
import * as React from "react"
import { cn } from "@/lib/utils"

const Card = React.forwardRef<
  HTMLDivElement,
  React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
  <div
    data-slot="card"
    ref={ref}
    className={cn(
      "rounded-lg border bg-card text-card-foreground shadow-sm",
      className
    )}
    {...props}
  />
))
Card.displayName = "Card"

const CardHeader = React.forwardRef<
  HTMLDivElement,
  React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
  <div
    data-slot="card-header"
    ref={ref}
    className={cn("flex flex-col space-y-1.5 p-6", className)}
    {...props}
  />
))
CardHeader.displayName = "CardHeader"

const CardTitle = React.forwardRef<
  HTMLParagraphElement,
  React.HTMLAttributes<HTMLHeadingElement>
>(({ className, ...props }, ref) => (
  <h3
    data-slot="card-title"
    ref={ref}
    className={cn(
      "text-2xl font-medium leading-none tracking-tight",
      className
    )}
    {...props}
  />
))
CardTitle.displayName = "CardTitle"

const CardDescription = React.forwardRef<
  HTMLParagraphElement,
  React.HTMLAttributes<HTMLParagraphElement>
>(({ className, ...props }, ref) => (
  <p
    data-slot="card-description"
    ref={ref}
    className={cn("text-sm text-muted-foreground", className)}
    {...props}
  />
))
CardDescription.displayName = "CardDescription"

const CardContent = React.forwardRef<
  HTMLDivElement,
  React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
  <div data-slot="card-content" ref={ref} className={cn("p-6 pt-0", className)} {...props} />
))
CardContent.displayName = "CardContent"

const CardFooter = React.forwardRef<
  HTMLDivElement,
  React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
  <div
    data-slot="card-footer"
    ref={ref}
    className={cn("flex items-center p-6 pt-0", className)}
    {...props}
  />
))
CardFooter.displayName = "CardFooter"

export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent }
```
