# Card

import { Callout } from "fumadocs-ui/components/callout";
import { Accordion, Accordions } from "fumadocs-ui/components/accordion";
import { Step, Steps } from "fumadocs-ui/components/steps";
import { Tabs, Tab } from "fumadocs-ui/components/tabs";
import {
  Badge,
  Button,
  Card,
  CardContent,
  CardDescription,
  CardFooter,
  CardHeader,
  CardTitle,
} from "@pycolors/ui";
import {
  Accessibility,
  ArrowRight,
  CheckCircle,
  CreditCard,
  FileText,
  Heading1,
  Layers3,
  LayoutDashboard,
  MousePointerClick,
  Palette,
  PanelsTopLeft,
  Radius,
  Settings,
  SquareStack,
  XCircle,
} from "lucide-react";
import { PreferAvoid } from '@/components/docs/prefer-avoid';
import { DocsLinks } from "@/components/docs/docs-links";
import { DocsFeatureGrid } from "@/components/docs/docs-feature-grid";
import { DocsConceptTabs } from "@/components/docs/docs-concept-tabs";

<div className="flex flex-wrap items-center gap-2">
  <Badge variant="outline">
    UI
  </Badge>

  <Badge>
    Card
  </Badge>
</div>

## Structured surfaces for product UI

The **Card** component is a foundational surface used to group related content, actions, and metadata.

Use it for:

* dashboard tiles
* pricing blocks
* settings panels
* billing summaries
* feature cards
* list items
* empty states
* account sections
* product surfaces

Card is built on semantic tokens such as `bg-card`, `border-border`, and `text-card-foreground`, so it stays consistent across light and dark themes.

<Callout title="Core idea">
  Card creates structure. Use it to group meaningful content, not as decoration.
</Callout>

### Import

```tsx title="card-import.tsx"
import { Card } from "@pycolors/ui";
```

### Basic usage

Use Card to group a title, description, content, and optional footer actions.

<Tabs items={["Preview", "Code"]}>
  <Tab value="Preview">
    <Preview>
      <Card className="max-w-sm">
        <CardHeader>
          <CardTitle>
            Account
          </CardTitle>

          <CardDescription>
            Manage your profile settings.
          </CardDescription>
        </CardHeader>

        <CardContent>
          <div className="text-sm text-muted-foreground">
            Update personal details, security preferences, and integrations.
          </div>
        </CardContent>

        <CardFooter className="justify-end gap-2">
          <Button variant="outline">
            Cancel
          </Button>

          <Button>
            Save
          </Button>
        </CardFooter>
      </Card>
    </Preview>
  </Tab>

  <Tab value="Code">
    ```tsx title="account-card.tsx"
    import {
      Button,
      Card,
      CardHeader,
      CardTitle,
      CardDescription,
      CardContent,
      CardFooter,
    } from "@pycolors/ui";

    export function AccountCard() {
      return (
        <Card className="max-w-sm">
          <CardHeader>
            <CardTitle>Account</CardTitle>
            <CardDescription>
              Manage your profile settings.
            </CardDescription>
          </CardHeader>

          <CardContent>
            <div className="text-sm text-muted-foreground">
              Update personal details, security preferences, and integrations.
            </div>
          </CardContent>

          <CardFooter className="justify-end gap-2">
            <Button variant="secondary">Cancel</Button>
            <Button>Save</Button>
          </CardFooter>
        </Card>
      );
    }
    ```
  </Tab>
</Tabs>

## When to use Card

Use Card when content needs a clear surface, boundary, or grouping.

<DocsFeatureGrid
  columns={3}
  tone="platform"
  items={[
  {
    title: 'Dashboards',
    description:
      'Use for KPI tiles, analytics summaries, and grouped dashboard sections.',
    icon: LayoutDashboard,
  },
  {
    title: 'Settings',
    description:
      'Use for profile, organization, security, and billing settings panels.',
    icon: Settings,
  },
  {
    title: 'Billing',
    description:
      'Use for plan summaries, invoice blocks, and payment method surfaces.',
    icon: CreditCard,
  },
]}
/>

### Variants

Cards support semantic surface variants.

Use variants to adjust contrast without changing layout.

<Tabs items={["Preview", "Code"]}>
  <Tab value="Preview">
    <Preview>
      <div className="grid gap-4 sm:grid-cols-3">
        <Card>
          <CardHeader>
            <CardTitle>
              Default
            </CardTitle>

            <CardDescription>
              Standard surface.
            </CardDescription>
          </CardHeader>
        </Card>

        <Card variant="muted">
          <CardHeader>
            <CardTitle>
              Muted
            </CardTitle>

            <CardDescription>
              Subtle secondary surface.
            </CardDescription>
          </CardHeader>
        </Card>

        <Card variant="transparent" className="border-dashed">
          <CardHeader>
            <CardTitle>
              Transparent
            </CardTitle>

            <CardDescription>
              Layout-only surface.
            </CardDescription>
          </CardHeader>
        </Card>
      </div>
    </Preview>
  </Tab>

  <Tab value="Code">
    ```tsx title="card-variants.tsx"
    import {
      Card,
      CardHeader,
      CardTitle,
      CardDescription,
    } from "@pycolors/ui";

    export function CardVariants() {
      return (
        <div className="grid gap-4 sm:grid-cols-3">
          <Card>
            <CardHeader>
              <CardTitle>Default</CardTitle>
              <CardDescription>Standard surface.</CardDescription>
            </CardHeader>
          </Card>

          <Card variant="muted">
            <CardHeader>
              <CardTitle>Muted</CardTitle>
              <CardDescription>Subtle secondary surface.</CardDescription>
            </CardHeader>
          </Card>

          <Card variant="transparent" className="border-dashed">
            <CardHeader>
              <CardTitle>Transparent</CardTitle>
              <CardDescription>Layout-only surface.</CardDescription>
            </CardHeader>
          </Card>
        </div>
      );
    }
    ```
  </Tab>
</Tabs>

### Available variants

| Variant       | Purpose                                         |
| ------------- | ----------------------------------------------- |
| `default`     | Main surface using `bg-card`                    |
| `muted`       | Secondary surface using a softer background     |
| `transparent` | Layout-only container with no filled background |

<Callout type="info" title="Variant rule">
  Use `default` for primary surfaces, `muted` for secondary groups, and `transparent` when you only need structure.
</Callout>

### Interactive cards

`interactive` adds visual affordances only — cursor, hover background, and a focus-visible ring. Card never attaches its own click or keyboard handling, so an interactive card must compose `asChild` with a real `<button>` for an action or a real `<a>`/`Link` for navigation. Those elements provide correct keyboard, focus, and click semantics natively — Card does not need to (and must not) recreate them.

<Tabs items={["Preview", "Code"]}>
  <Tab value="Preview">
    <Preview>
      <div className="grid gap-4 sm:grid-cols-2">
        <Card asChild interactive>
          <button type="button" className="block w-full text-left">
            <CardHeader>
              <CardTitle>
                Select a plan
              </CardTitle>

              <CardDescription>
                A real button gives native click and keyboard behavior for free.
              </CardDescription>
            </CardHeader>
          </button>
        </Card>

        <Card asChild interactive variant="muted">
          <a href="/pricing" className="block">
            <CardHeader>
              <CardTitle>
                View pricing
              </CardTitle>

              <CardDescription>
                A real link gives native navigation and open-in-new-tab behavior.
              </CardDescription>
            </CardHeader>
          </a>
        </Card>
      </div>
    </Preview>
  </Tab>

  <Tab value="Code">
    ```tsx title="interactive-cards.tsx"
    import {
      Card,
      CardHeader,
      CardTitle,
      CardDescription,
    } from "@pycolors/ui";

    export function InteractiveCards() {
      return (
        <div className="grid gap-4 sm:grid-cols-2">
          <Card asChild interactive>
            <button
              type="button"
              className="block w-full text-left"
              onClick={() => selectPlan("pro")}
            >
              <CardHeader>
                <CardTitle>Select a plan</CardTitle>
                <CardDescription>
                  A real button gives native click and keyboard behavior for free.
                </CardDescription>
              </CardHeader>
            </button>
          </Card>

          <Card asChild interactive variant="muted">
            <a href="/pricing" className="block">
              <CardHeader>
                <CardTitle>View pricing</CardTitle>
                <CardDescription>
                  A real link gives native navigation and open-in-new-tab behavior.
                </CardDescription>
              </CardHeader>
            </a>
          </Card>
        </div>
      );
    }
    ```
  </Tab>
</Tabs>

<Callout type="info" title="Keyboard support">
  `interactive` never adds `role`, `tabIndex`, or keyboard handling — it is visual only. A bare `Card interactive` with no `asChild` target is not keyboard or screen-reader accessible. Always compose `asChild` with a real `button` for actions or a real `a`/`Link` for navigation.
</Callout>

### With icon

Use `asChild` to render Card as another element while preserving Card styling.

This is useful for link cards.

<Tabs items={["Preview", "Code"]}>
  <Tab value="Preview">
    <Preview>
      <Card asChild interactive className="max-w-sm">
        <a href="/docs" className="block">
          <CardHeader>
            <CardTitle>
              Read the docs
            </CardTitle>

            <CardDescription>
              Go to documentation →
            </CardDescription>
          </CardHeader>
        </a>
      </Card>
    </Preview>
  </Tab>

  <Tab value="Code">
    ```tsx title="card-as-link.tsx"
    import {
      Card,
      CardHeader,
      CardTitle,
      CardDescription,
    } from "@pycolors/ui";

    export function CardAsLink() {
      return (
        <Card asChild interactive className="max-w-sm">
          <a href="/docs" className="block">
            <CardHeader>
              <CardTitle>Read the docs</CardTitle>
              <CardDescription>Go to documentation →</CardDescription>
            </CardHeader>
          </a>
        </Card>
      );
    }
    ```
  </Tab>
</Tabs>

### Composition

A Card usually follows this structure:

```tsx title="card-anatomy.tsx"
<Card>
  <CardHeader>
    <CardTitle>Title</CardTitle>
    <CardDescription>Description</CardDescription>
  </CardHeader>

  <CardContent>
    Content
  </CardContent>

  <CardFooter>
    Actions
  </CardFooter>
</Card>
```

Use each slot intentionally:

| Slot              | Purpose                              |
| ----------------- | ------------------------------------ |
| `CardHeader`      | Introduces the surface               |
| `CardTitle`       | Names the grouped content            |
| `CardDescription` | Adds short context                   |
| `CardContent`     | Holds the main body                  |
| `CardFooter`      | Holds actions or supporting metadata |

### Usage patterns

<Steps>
  <Step>
    #### Start with the content group

    Use Card only when the content belongs together.
  </Step>

  <Step>
    #### Add a clear title

    Most cards should have a title that explains the purpose of the surface.
  </Step>

  <Step>
    #### Keep actions in the footer

    Footer actions make the card easier to scan and keep layout predictable.
  </Step>

  <Step>
    #### Use interactivity deliberately

    Interactive cards should be clickable or selectable. Static cards should not have hover affordances.
  </Step>

  <Step>
    #### Preserve semantic behavior

    Use `asChild` with a real link for navigational cards.
  </Step>
</Steps>

## Card vs section vs list item

| Situation                              | Use                      |
| -------------------------------------- | ------------------------ |
| Grouped content with a visible surface | Card                     |
| Large page section with headings       | Section                  |
| Repeated compact rows                  | List item                |
| Navigation tile                        | Card with `asChild` link |
| KPI or metric                          | Card                     |
| Table data                             | Table                    |
| Temporary status or error              | Alert or EmptyState      |

<Callout title="Decision rule">
  Use Card when the surface helps users understand grouping, priority, or interaction.
</Callout>

## API

#### Components

| Component         | Description                |
| ----------------- | -------------------------- |
| `Card`            | Root surface               |
| `CardHeader`      | Header area                |
| `CardTitle`       | Card heading               |
| `CardDescription` | Supporting text            |
| `CardContent`     | Main content area          |
| `CardFooter`      | Footer actions or metadata |

#### Card props

| Prop          | Type          | Default     | Description                           |
| ------------- | ------------- | ----------- | ------------------------------------- |
| `variant`     | `CardVariant` | `"default"` | Surface style                         |
| `interactive` | `boolean`     | `false`     | Adds hover and focus-visible feedback |
| `asChild`     | `boolean`     | `false`     | Render via Radix Slot                 |
| `className`   | `string`      | —           | Additional Tailwind classes           |

Card extends standard HTML `div` props.

```ts title="card-props.ts"
React.HTMLAttributes<HTMLDivElement>
```

### TypeScript types

```ts title="card-types.ts"
export type CardVariant =
  | "default"
  | "muted"
  | "transparent";

export type CardInteractive = boolean;
```

### Accessibility

Guidelines:

* use meaningful headings inside cards when they introduce a section
* `interactive` only adds visual affordances (cursor, hover, focus-visible ring) — it never adds `role`, `tabIndex`, or keyboard handling
* a bare `Card interactive` with no `asChild` target is not keyboard or screen-reader accessible — it is styling only
* use `asChild` with a real `a`/`Link` for navigation cards
* use `asChild` with a real `button` for action cards
* `asChild interactive` wrapping a non-focusable element (for example a plain `div`) is invalid — the slotted child must be a real interactive element
* avoid nested interactive controls inside a clickable card
* keep focus states visible for interactive cards
* do not make a card interactive only for visual decoration

<Callout title="Accessibility rule">
  Card never synthesizes keyboard or focus behavior. An interactive card is only truly accessible when `asChild` wraps a real `a`/`Link` (navigation) or `button` (action) — those elements provide correct keyboard, focus, and click semantics natively.
</Callout>

## Prefer / avoid

<PreferAvoid
  prefer={[
  'clear grouping',
  'consistent card rhythm',
  'semantic headings',
  'footer actions for card-level actions',
  'real link semantics for navigation cards',
]}
  avoid={[
  'cards used only for decoration',
  'too many nested cards',
  'interactive styling on static content',
  'clickable cards without link or button semantics',
  'multiple competing actions inside one clickable card',
]}
/>

### Product copy guidelines

Card copy should make the grouped content easy to understand.

<DocsConceptTabs
  items={[
  {
    value: 'Title',
    title: 'Strong title examples',
    icon: Heading1,
    description: (
      <>
        <p>
          Titles should describe the surface immediately without extra wording.
        </p>

        <div className="mt-3 flex flex-wrap gap-2">
          <Badge variant="outline">Account</Badge>
          <Badge variant="outline">Current plan</Badge>
          <Badge variant="outline">Recent invoices</Badge>
          <Badge variant="outline">Project activity</Badge>
          <Badge variant="outline">Team members</Badge>
        </div>
      </>
    ),
  },
  {
    value: 'Description',
    title: 'Description examples',
    icon: FileText,
    description: (
      <>
        <p>
          Descriptions should provide context, not repeat the title.
        </p>

        <div className="mt-3 space-y-2">
          <div className="rounded-[5px] border border-border-subtle bg-muted/30 px-3 py-2 text-sm text-muted-foreground">
            Manage profile details and account preferences.
          </div>

          <div className="rounded-[5px] border border-border-subtle bg-muted/30 px-3 py-2 text-sm text-muted-foreground">
            Review recent billing activity.
          </div>
        </div>
      </>
    ),
  },
  {
    value: 'Footer',
    title: 'Footer action examples',
    icon: MousePointerClick,
    description: (
      <>
        <p>
          Footer actions should stay clear, actionable, and easy to scan.
        </p>

        <div className="mt-3 flex flex-wrap gap-2">
          <Badge variant="outline">Save changes</Badge>
          <Badge variant="outline">Manage billing</Badge>
          <Badge variant="outline">Invite member</Badge>
          <Badge variant="outline">View all invoices</Badge>
        </div>
      </>
    ),
  },
]}
/>

## Common questions

<Accordions type="single">
  <Accordion title="Should every content group be a Card?">
    No. Use Card when the surface improves grouping, hierarchy, or interaction. Simple sections do not always need a bordered surface.
  </Accordion>

  <Accordion title="Can a Card be clickable?">
    Yes. Use `asChild` with a semantic link or button and enable `interactive` for visual feedback.
  </Accordion>

  <Accordion title="When should I use the muted variant?">
    Use `muted` for secondary surfaces, dense layouts, or supporting panels where the default card is too visually strong.
  </Accordion>

  <Accordion title="Can cards contain forms?">
    Yes. Cards work well for settings forms. Keep labels, validation, and actions clear.
  </Accordion>
</Accordions>

## Related

<DocsLinks
  variant="list"
  tone="platform"
  items={[
  {
    title: 'Colors',
    href: '/docs/design-system/colors',
    description:
      'Semantic surface roles used by cards.',
    icon: Palette,
  },
  {
    title: 'Radius',
    href: '/docs/design-system/tokens/radius',
    description:
      'Corner radius tokens used for card surfaces.',
    icon: Radius,
  },
  {
    title: 'Shadows',
    href: '/docs/design-system/tokens/shadows',
    description:
      'Elevation scale for cards and floating surfaces.',
    icon: Layers3,
  },
  {
    title: 'Accessibility',
    href: '/docs/ui/accessibility',
    description:
      'Build accessible surfaces with headings, semantics, and focus states.',
    icon: Accessibility,
  },
]}
/>