# Card

A bordered surface that groups related content and actions, such as a summary, a settings section or an item in a grid. It has an optional header and footer and can be raised or made clickable as a whole.

- Package: [@vigdx/ui](https://www.npmjs.com/package/@vigdx/ui)
- Selectors: `vig-card`, `[vigCardHeader]`, `[vigCardFooter]`
- Source: [libs/ui/src/lib/molecules/card/card.ts](https://github.com/bakyurekk/vigdx/blob/main/libs/ui/src/lib/molecules/card/card.ts)

```typescript title="Import"
import { Card, CardHeader, CardFooter } from '@vigdx/ui/card';
```

## Basic

`heading` renders a title above the projected body. Without it the card is a plain bordered surface.

```typescript title="card-basic.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Card } from '@vigdx/ui/card';

@Component({
  selector: 'app-card-basic',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Card],
  template: `
    <div class="grid gap-4 sm:grid-cols-2">
      <vig-card heading="Opening hours">
        Monday to Friday, 9:00 to 18:00. Closed on public holidays.
      </vig-card>
      <vig-card> A card without a header is a plain bordered surface for any content. </vig-card>
    </div>
  `,
})
export class CardBasicDemo {}
```

## Header and footer

Mark an element `vigCardHeader` for a richer header row (bring your own heading) and one `vigCardFooter` for an action row, separated by a rule and aligned to the end.

```typescript title="card-header-footer.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Badge } from '@vigdx/ui/badge';
import { Button } from '@vigdx/ui/button';
import { Card, CardFooter, CardHeader } from '@vigdx/ui/card';

@Component({
  selector: 'app-card-header-footer',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Badge, Button, Card, CardFooter, CardHeader],
  template: `
    <vig-card class="max-w-sm">
      <div vigCardHeader class="flex w-full items-center justify-between gap-2">
        <h3 class="text-h4 text-foreground">Ticket prices</h3>
        <vig-badge label="Draft" variant="warning" />
      </div>
      Adult €42, child €36, under-fours free. Prices apply from 1 April.
      <div vigCardFooter>
        <vig-button label="Discard" variant="secondary" size="sm" />
        <vig-button label="Publish" size="sm" />
      </div>
    </vig-card>
  `,
})
export class CardHeaderFooterDemo {}
```

## Elevated

`elevated` adds the small shadow token to lift a card off the page, e.g. for dashboard tiles. `headingLevel` picks the `h2`–`h6` element of the `header` title (3 by default) to fit the page outline.

```typescript title="card-elevated.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Card } from '@vigdx/ui/card';

@Component({
  selector: 'app-card-elevated',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Card],
  template: `
    <div class="grid gap-4 sm:grid-cols-3">
      <vig-card heading="Revenue" [elevated]="true">
        <p class="text-h2 tabular-nums">€48,210</p>
        <p class="text-xs text-success">+12% vs. last month</p>
      </vig-card>
      <vig-card heading="Orders" [elevated]="true">
        <p class="text-h2 tabular-nums">1,284</p>
        <p class="text-xs text-muted-foreground">Same as last month</p>
      </vig-card>
      <vig-card heading="Refunds" [elevated]="true">
        <p class="text-h2 tabular-nums">23</p>
        <p class="text-xs text-error">+4 vs. last month</p>
      </vig-card>
    </div>
  `,
})
export class CardElevatedDemo {}
```

## Interactive

`interactive` makes the whole card clickable through its title, a real button whose overlay covers the card: click, Enter and Space emit `activated`. Footer actions such as Compare stay above the overlay and work on their own. For picking one of several cards, use radios (`vig-radio-group`) instead.

```typescript title="card-interactive.ts"
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { Button } from '@vigdx/ui/button';
import { Card, CardFooter } from '@vigdx/ui/card';

@Component({
  selector: 'app-card-interactive',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Button, Card, CardFooter],
  template: `
    <div class="grid gap-4 sm:grid-cols-3">
      @for (plan of plans; track plan.name) {
        <vig-card [heading]="plan.name" [interactive]="true" (activated)="opened.set(plan.name)">
          {{ plan.price }}
          <div vigCardFooter>
            <vig-button
              [label]="'Compare ' + plan.name"
              variant="ghost"
              size="sm"
              (click)="compared.set(plan.name)"
            />
          </div>
        </vig-card>
      }
    </div>
    <p class="text-sm text-muted-foreground" role="status">
      Opened: {{ opened() }} · Compared: {{ compared() }}
    </p>
  `,
})
export class CardInteractiveDemo {
  protected readonly plans = [
    { name: 'Starter', price: 'Free for up to 3 users' },
    { name: 'Team', price: '€8 per user and month' },
    { name: 'Business', price: '€16 per user and month' },
  ];
  protected readonly opened = signal('—');
  protected readonly compared = signal('—');
}
```

## Padding

`padding` sets the inner spacing of header, body and footer: `sm`, `md` (default), `lg` or `none` for edge-to-edge media. The corner radius follows `--radius-card`.

```typescript title="card-padding.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Card } from '@vigdx/ui/card';

@Component({
  selector: 'app-card-padding',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Card],
  template: `
    <div class="flex flex-wrap items-start gap-4">
      <vig-card padding="sm" heading="Small">Compact lists and sidebars.</vig-card>
      <vig-card heading="Medium">The default.</vig-card>
      <vig-card padding="lg" heading="Large">Roomy feature panels.</vig-card>
      <vig-card padding="none" class="w-56 overflow-hidden">
        <div class="h-24 bg-primary/15" aria-hidden="true"></div>
        <p class="p-4">
          <code>padding="none"</code> lets media run edge to edge; pad the text yourself.
        </p>
      </vig-card>
    </div>
  `,
})
export class CardPaddingDemo {}
```

## Styling hooks

Internal elements carry a stable `data-part` and the component's `data-scope`; both are public API, so removing one is a breaking change. Select a part by both, e.g. `[data-scope="card"][data-part="header"] { … }`: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through `aria-*` and, where listed, a `data-state`; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other `data-*` attributes listed below (such as `data-opening` while an overlay animates) are API too. See [Customizing](https://vigdx.com/docs/theming.md#customizing).

Scope: `[data-scope="card"]`

| Part | Element | data-state |
| --- | --- | --- |
| `header` | The header row: heading and `[vigCardHeader]`. |   |
| `heading` | The `h2`–`h6` of `heading`. |   |
| `body` | The body. |   |
| `footer` | The `[vigCardFooter]` row. |   |
| `action` | The button that makes an `interactive` card clickable. |   |

## Accessibility

- The card itself has no role; its `heading` renders as a real `h2`–`h6` (`headingLevel`). Pick the level that fits the page's outline. In a custom `vigCardHeader`, provide the heading element yourself.
- An `interactive` card uses the stretched-button pattern: its title is a real `<button>` (Enter and Space activate it) whose overlay makes the whole card clickable. Without a `heading`, a covering button is named by the card's text, so keep that short.
- Links, buttons and form fields inside an interactive card sit above the overlay and work on their own, so independent footer actions are fine; they are not nested in the card's button.
- Interactive cards draw the `--shadow-focus-ring` on the card when its button has keyboard focus; the hover lift is disabled with `prefers-reduced-motion`.

## API

### Card

Selector: `vig-card` · Kind: component

Bordered surface grouping related content. A `heading` string (or a `[vigCardHeader]` element) sits above the projected body and a `[vigCardFooter]` element below it. The `heading` renders as a real `h2`–`h6` (`headingLevel`).

`interactive` makes the whole card clickable through one real `<button>` (the stretched-control pattern): with a `heading` the title itself is the button, otherwise an unlabelled-looking button covers the card, named by the card's text. Its `::after` overlay stretches the pointer target across the card while links, buttons and form controls inside the card stay on top and keep working on their own. Click, Enter or Space on the card's button emit `activated`; focus is drawn on the card.

**Example :**

```html
<vig-card heading="Season" [elevated]="true">
  Body copy
  <div vigCardFooter><vig-button label="Edit" /></div>
</vig-card>
```

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `elevated` | `boolean` | `false` | Raises the surface with the small elevation token. |
| `header` | `string \| undefined` | `undefined` | **Deprecated**: Use `heading`; still honored when `heading` is unset. |
| `heading` | `string \| undefined` | `undefined` | Title text; use a `[vigCardHeader]` element for richer headers. |
| `headingLevel` | `CardHeadingLevel` | `3` | Heading level (`h2`–`h6`) of the `heading` title. |
| `interactive` | `boolean` | `false` | Makes the whole card clickable through one real button that emits `activated`. |
| `padding` | `CardPadding` | `'md'` | Inner spacing of header, body and footer. `none` for edge-to-edge media. |

#### Outputs

| Name | Payload | Description |
| --- | --- | --- |
| `activated` | `Event` | Click, Enter or Space on an interactive card's button. |

### Templates and directives

| Selector | Export | Description |
| --- | --- | --- |
| `[vigCardHeader]` | `CardHeader` | Marks projected content as the card's header row (title, actions…). |
| `[vigCardFooter]` | `CardFooter` | Marks projected content as the card's footer (action row). |
