# Card

## Usage

`Card` is a bordered surface with a background and rounded corners, and it turns a group of content into one thing you can treat on its own. Its job is appearance and space only: the background, the border, the corner radius, the padding, and passing that padding on to children that need to bleed past it.

A card is not the default layout tool. Most content groups on a page need no container at all; spacing and alignment already read as grouping. Reach for a card when an item needs a clear interaction boundary, or when it has to be compared side by side with its siblings in a row or a grid. A useful test is to ask: "could I reorder, remove, or take this away on its own?" If yes, it is a card. If no, it is just a region of the page, and a heading plus a `Stack` is the right answer.

```vue
<script setup lang="ts">
import { Card } from '@astryx-vue/core/Card'
import { Heading } from '@astryx-vue/core/Heading'
import { VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
</script>

<template>
  <Card>
    <VStack :gap="2">
      <Heading :level="3">
        Weekly report
      </Heading>
      <Text color="secondary">
        Your team closed 24 issues this week.
      </Text>
    </VStack>
  </Card>
</template>
```

`padding` takes a step from the spacing scale (0, 0.5, 1, 1.5, 2, 3, 4, 5, 6, 8, 10) and applies it to all four sides. Leave it out and the card keeps the theme's card padding rather than one fixed step, so passing a step is a decision to override the theme instead of a way to restate its default.

`variant` picks the background. `default` is the standard card surface with a visible border, `transparent` has neither a background nor a border and only groups content, and `muted` uses the muted surface. The other ten names are the categorisation hues: `blue`, `cyan`, `gray`, `green`, `orange`, `pink`, `purple`, `red`, `teal`, and `yellow`. Only `default` draws a border, and it draws it inside the padding: the border width is subtracted from each side, so the total inset (border plus padding) still equals the padding step and content sits at the same coordinates in a bordered card as in a borderless one.

`elevation` is the shadow the card rests at, and it can be `none`, `low`, `med`, or `high`. Raise a card only when it has to float above the content around it; a list where every card carries a shadow has no depth left to show.

`width`, `height`, `maxWidth`, and `minHeight` size the card, with numbers read as pixels and strings used as they are. In a flex row or a grid track the card yields to the track: it has a minimum width of zero, so a long value inside cannot widen a row or a `1fr` track. The card also clips content it cannot fit rather than turning into a scroll container, which would capture sticky descendants and make an overflowing card an unnamed keyboard tab stop. Truncate long values that cannot wrap — an ID, a hash, a URL — with `Text`'s `maxLines`, and give wide content such as a table or code its own scroll region. A fixed `height` changes that: the card becomes a viewport for its content, and the content scrolls inside it.

The card also publishes `--container-padding-inline-start`, `--container-padding-inline-end`, `--container-padding-block-start`, and `--container-padding-block-end` on its root. Children that need to extend to the card's edge — a `Divider` with `isFullBleed`, for example — read those variables to cancel the padding, so they never need to know how much padding the card used.

### Anatomy

- **Container**: The outer box with border, background, border-radius, and padding.
- **Content**: Anything rendered in the default slot inside the card. Often a stack of heading, text, and actions.

## Best practices

| Guidance | Practices |
| --- | --- |
| Do | Ask first: "could I reorder or remove this on its own?" If yes, it is a card; if no, it is a page region, so use a heading plus a `Stack` or a `Section`. |
| Do | Use cards for discrete items: one user, one notification, one metric, one product in a grid. Each card is one thing. |
| Do | Keep `padding` the same across sibling cards so they line up in a grid or a list. |
| Do | Truncate long IDs, hashes, and URLs with `Text`'s `maxLines="1"`, and put wide content such as tables and code in its own scroll region. |
| Do | Set `elevation` only when the card has to float above the content around it. |
| Don't | Default to cards for visual grouping. A heading plus a `Stack` with proper spacing builds hierarchy without covering the page in borders. |
| Don't | Wrap page regions in cards. Form groups such as "General settings" or "Notification preferences" are page regions, not cards. |
| Don't | Nest cards inside other cards. Flatten the hierarchy with spacing and dividers instead. |
| Don't | Use the colour variants to carry status. Use `Banner` or `Badge` for that; a coloured card is for categorisation. |

## Examples

### Callout

Muted-variant cards for tips, notes, or supplementary information. Use when content should be visually distinct but not prominent.

```vue
<script setup lang="ts">
import { Card } from '@astryx-vue/core/Card'
import { Heading } from '@astryx-vue/core/Heading'
import { HStack, VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
</script>

<template>
  <HStack :gap="4" wrap="wrap">
    <Card :width="270" variant="muted">
      <VStack :gap="2">
        <Heading :level="3">
          Tip
        </Heading>
        <Text type="body" color="secondary">
          Use the muted variant for callouts or supplementary information.
        </Text>
      </VStack>
    </Card>
    <Card :width="270" variant="muted">
      <VStack :gap="2">
        <Heading :level="3">
          Note
        </Heading>
        <Text type="body" color="secondary">
          Muted cards work well in sidebars or help panels.
        </Text>
      </VStack>
    </Card>
  </HStack>
</template>
```

### Elevations

The four elevation levels side by side. Cards are flat by default; raise a card with elevation only when it needs to float above surrounding content.

```vue
<script setup lang="ts">
import { Card } from '@astryx-vue/core/Card'
import { Grid } from '@astryx-vue/core/Grid'
import { Heading } from '@astryx-vue/core/Heading'
import { Stack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'

const levels = [
  { elevation: 'none' as const, caption: 'Flat — sits on the page (default)' },
  { elevation: 'low' as const, caption: 'Low — lifts off slightly' },
  { elevation: 'med' as const, caption: 'Med — clearly raised' },
  { elevation: 'high' as const, caption: 'High — floats well above' },
]
</script>

<template>
  <Grid :columns="2" :gap="4" :width="520">
    <Card v-for="level in levels" :key="level.elevation" :elevation="level.elevation">
      <Stack direction="vertical" :gap="1">
        <Heading :level="4">
          elevation="{{ level.elevation }}"
        </Heading>
        <Text type="supporting" color="secondary">
          {{ level.caption }}
        </Text>
      </Stack>
    </Card>
  </Grid>
</template>
```

### Variants

Default, muted, and color variants side by side. Use color variants to categorize cards visually, like team colors, project tags, or content types.

```vue
<script setup lang="ts">
import type { CardVariant } from '@astryx-vue/core/Card'
import { Card } from '@astryx-vue/core/Card'
import { HStack, VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'

const variants: { variant: CardVariant, label: string, note: string }[] = [
  { variant: 'default', label: 'General', note: '4 tasks due today' },
  { variant: 'muted', label: 'Archived', note: 'No activity in 30 days' },
  { variant: 'blue', label: 'Engineering', note: '12 open issues' },
  { variant: 'green', label: 'Marketing', note: '3 campaigns active' },
  { variant: 'orange', label: 'Urgent', note: '2 items need review' },
  { variant: 'purple', label: 'Design', note: '5 drafts in progress' },
]
</script>

<template>
  <HStack :gap="3" wrap="wrap">
    <Card v-for="item in variants" :key="item.variant" :variant="item.variant" :width="160">
      <VStack :gap="1">
        <Text type="body" weight="bold">
          {{ item.label }}
        </Text>
        <Text type="supporting" color="secondary">
          {{ item.note }}
        </Text>
      </VStack>
    </Card>
  </HStack>
</template>
```

### Layout

A card with a structured header, content area, and footer with action buttons. Use for forms, dialogs, or settings panels that need clear sections.

```vue
<script setup lang="ts">
import { Button } from '@astryx-vue/core/Button'
import { Card } from '@astryx-vue/core/Card'
import { Heading } from '@astryx-vue/core/Heading'
import { Layout, LayoutFooter, LayoutHeader } from '@astryx-vue/core/Layout'
import { HStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
</script>

<template>
  <Card :width="380">
    <Layout height="auto">
      <template #header>
        <LayoutHeader has-divider>
          <Heading :level="3">
            Edit Profile
          </Heading>
        </LayoutHeader>
      </template>
      <Text type="body" color="secondary">
        Update your display name, bio, and profile photo. Changes are saved immediately.
      </Text>
      <template #footer>
        <LayoutFooter has-divider>
          <HStack :gap="2" h-align="end">
            <Button label="Cancel" variant="ghost" />
            <Button label="Save changes" variant="primary" />
          </HStack>
        </LayoutFooter>
      </template>
    </Layout>
  </Card>
</template>
```

### Simple

A card with a heading and body text. Use for summaries, descriptions, or any grouped content that needs visual separation from the page.

```vue
<script setup lang="ts">
import { Card } from '@astryx-vue/core/Card'
import { Heading } from '@astryx-vue/core/Heading'
import { VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
</script>

<template>
  <Card :width="360">
    <VStack :gap="2">
      <Heading :level="3">
        Project Overview
      </Heading>
      <Text type="body" color="secondary">
        This project tracks the redesign of the onboarding flow. The goal is to reduce drop-off by 15% in Q2.
      </Text>
      <Text type="supporting" color="secondary">
        Last updated 2 hours ago
      </Text>
    </VStack>
  </Card>
</template>
```

## Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `width` | `number \| string` | - | Width of the card. Numbers are read as pixels and strings are used as they are. In a flex row or a grid track this is the preferred width: the card still yields when the row is narrower. |
| `height` | `number \| string` | - | Height of the card. Numbers are read as pixels and strings are used as they are. A fixed height makes the card scroll its own content; `auto` and an omitted height leave the height to the content. |
| `maxWidth` | `number \| string` | - | Maximum width of the card. |
| `minHeight` | `number \| string` | - | Minimum height of the card. |
| `padding` | `SpacingStep` | - | Padding on all four sides, as one step of the spacing scale: 0, 0.5, 1, 1.5, 2, 3, 4, 5, 6, 8, 10. Omit it and the card uses the theme's card padding — spacing step 4 with no theme — so passing a step overrides the theme instead of restating the default. |
| `variant` | `CardVariant` | `'default'` | Background variant. `default` uses the standard card surface and draws the border, `transparent` drops the background and the border, and `muted` uses the muted surface. The non-semantic hues are blue, cyan, gray, green, orange, pink, purple, red, teal, and yellow. |
| `elevation` | `CardElevation` | `'none'` | Resting shadow depth: none, low, med, or high. Raise a card only when it has to float above the content around it. |

## Slots

| Name | Description |
| --- | --- |
| `default` | The card's content, usually a `Stack` holding a heading, text, and actions. |

## Theme variables

| Name | Default | Description |
| --- | --- | --- |
| `--astryx-card-padding` | `--astryx-spacing-4` | The theme's card padding. The `padding` prop bypasses it when it is set. `--astryx-card-padding-inline`, `--astryx-card-padding-inline-start`, `--astryx-card-padding-inline-end`, `--astryx-card-padding-block-start`, and `--astryx-card-padding-block-end` refine it per axis. |
| `--astryx-card-background` | - | Background of the `default` variant. |
| `--astryx-card-muted-background` | - | Background of the `muted` variant. |
| `--astryx-card-border` | - | Border colour of the `default` variant. Its width comes from `--astryx-border-width`. |
| `--astryx-card-<hue>-background` | - | Background of each hue variant, for example `--astryx-card-blue-background`. |
| `--astryx-card-shadow-low`, `-med`, `-high` | built-in shadow | The three elevation shadows, used by `elevation` low, med, and high. A built-in shadow is used when the theme defines none. |
| `--_card-radius` | `--astryx-radius-container` | The card's corner radius. Private, and a theme may override it. |
| `--_card-elevation` | `0 0 transparent` | The resting shadow, written from `elevation`. It composes with `--_card-ring` inside the card's `box-shadow`, so a ring and an elevation can coexist. |
| `--_card-ring` | `0 0 transparent` | An inset ring drawn in the card's shadow list, for a composing component that shows selection. |

## Native attributes

The root element is a `<div>`.

The following go to the root element:

- HTML attributes.
- `aria-*` attributes.
- `data-*` attributes.
- `class`.
- `style`.

`variant`, `elevation`, and `padding` are also reflected as `data-variant`, `data-elevation`, and `data-padding` on the root, and a fixed `height` adds `data-scrollable="true"`.
