# Card

A contained surface for grouped content, with an optional cover, header and footer.

## Content

Children render straight into the card's padded body. A `Separator` splits that content into parts.

## Header, body and footer

The `header`, `body` and `footer` snippets lay out three bands; the footer holds the actions. `header` also takes a string, which Card wraps in a heading: for a node spec that carries a title and nothing more.

## Cover

`cover` takes an image URL, drawn 16:9 above the header, or a snippet for anything more than an image.

## Clickable and selected

With `onclick` the card is a button: it takes focus, and Enter or Space clicks it. `aria-checked` marks the chosen card in a set.

## Examples

```svelte
<script lang="ts">
  import Button from '@qualia-studios/design-ui/components/Button.svelte';
  import Card from '@qualia-studios/design-ui/components/Card.svelte';
  import Separator from '@qualia-studios/design-ui/components/Separator.svelte';

  let clicks = $state(0);
</script>
```

### Example 1: Children only

```svelte
<div class="slot">
  <Card>
    <h1>Project Atlas</h1>
    <p>A short description of what this project is about.</p>
    <strong>Active</strong>
  </Card>
</div>
```

### Example 2: Header, body and footer

```svelte
<div class="slot">
  <Card>
    {#snippet header()}
      <div>
        <h1>Training run #142</h1>
        <span>Started 2 hours ago</span>
      </div>
      <div>
        <strong>Running</strong>
      </div>
    {/snippet}
    {#snippet body()}
      <p>Fine-tuning Pi0 on robot-arm-v2 dataset.</p>
      <p>Estimated completion: 4 hours</p>
    {/snippet}
    {#snippet footer()}
      <span>3 epochs / 12</span>
      <Button class="small primary">View details</Button>
    {/snippet}
  </Card>
</div>
```

### Example 3: A header from a string

```svelte
<div class="slot">
  <Card header="Quick title">
    {#snippet body()}
      <p>The header above came from a string.</p>
    {/snippet}
  </Card>
</div>
```

### Example 4: A cover image

```svelte
<div class="slot">
  <Card cover="https://picsum.photos/seed/atlas/640/360">
    {#snippet header()}
      <div><h1>With cover image</h1></div>
    {/snippet}
    {#snippet body()}
      <p>The cover area is 16:9 by default.</p>
    {/snippet}
  </Card>
</div>
```

### Example 5: A cover snippet

```svelte
<div class="slot">
  <Card>
    {#snippet cover()}
      <div class="custom-cover">Custom cover content</div>
    {/snippet}
    {#snippet header()}
      <div><h1>Custom cover</h1></div>
    {/snippet}
    {#snippet body()}
      <p>Use the cover snippet when you need more than an image.</p>
    {/snippet}
  </Card>
</div>
```

### Example 6: A clickable card

Click it, or focus it and press Enter.

```svelte
<div class="slot">
  <Card onclick={() => clicks++}>
    <h1>Click me</h1>
    <p>Clicked {clicks} times.</p>
  </Card>
</div>
```

### Example 7: A selected card

```svelte
<div class="slot">
  <Card aria-checked="true">
    <h1>Selected</h1>
    <p>Tone shifts to success.</p>
  </Card>
</div>
```

### Example 8: Split by a separator

```svelte
<div class="slot">
  <Card>
    <h1>Section A</h1>
    <p>Some content.</p>
    <Separator />
    <h1>Section B</h1>
    <p>More content.</p>
  </Card>
</div>
```

---

From the Qualia design guide: https://q-core-3b2732.gitlab.io/components/card. Every page as markdown: https://q-core-3b2732.gitlab.io/llms.txt
