# Heading

## Usage

Import the component from its dedicated entry. Structural styles are loaded automatically.

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

<template>
  <Heading :level="1">
    Page title
  </Heading>
  <Heading :level="2" type="display-2">
    Overview
  </Heading>
</template>
```

## Best practices

| Guidance | Practice |
| --- | --- |
| Recommended | Choose `level` to match the document outline; avoid skipping levels. |
| Recommended | Use `type="display-*"` for marketing or large callouts while keeping the semantic `level`. |
| Recommended | Use `color="secondary"` for lower-emphasis headings. |
| Don't | Pick a `level` purely for visual size. Use `type` for visuals and `level` for semantics. |
| Don't | Put long paragraphs inside headings. Keep headings short. |

## Examples

### Card grid

Responsive card grid with truncated headings and descriptions for uniform layout.

```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="300">
    <VStack :gap="2">
      <Heading :level="3">
        Card Title
      </Heading>
      <Text type="body" display="block" :max-lines="2">
        This is a card description that might be quite long and needs to be truncated after two lines to keep the card compact and uniform.
      </Text>
      <Text type="supporting" display="block">
        Updated 1 hour ago
      </Text>
    </VStack>
  </Card>
</template>
```

### Page hierarchy

Real-world page layout demonstrating heading levels h1 through h3 with supporting text.

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

<template>
  <VStack :gap="6" width="100%" style="max-width: 400px">
    <VStack>
      <Heading :level="1">
        Dashboard Overview
      </Heading>
      <Text type="supporting" display="block">
        Last updated 5 minutes ago
      </Text>
    </VStack>
    <VStack>
      <Heading :level="2">
        Recent Activity
      </Heading>
      <Text type="body" display="block">
        Here's what's been happening in your workspace.
      </Text>
    </VStack>
    <VStack>
      <Heading :level="3">
        Today
      </Heading>
      <Text type="body" display="block">
        • Project Alpha updated<br>
        • 3 new comments<br>
        • Task completed
      </Text>
    </VStack>
  </VStack>
</template>
```

### Truncation

Single-line and multi-line heading truncation with ellipsis for constrained layouts. Hover reads the full text once it is cut off.

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

<template>
  <div class="heading-preview__clamp">
    <div class="heading-preview__box">
      <Heading :level="2" :max-lines="1">
        Very Long Heading That Will Be Truncated To One Line With Ellipsis
      </Heading>
    </div>
    <div class="heading-preview__box">
      <Heading :level="2" :max-lines="2">
        Very Long Heading That Will Be Truncated To Two Lines To Keep Card Layout Compact
      </Heading>
    </div>
  </div>
</template>
```

### Outline and alignment

The visual level and the outline level can differ. Strikethrough and alignment stay on the heading.

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

<template>
  <VStack :gap="2" style="width: 100%; max-width: 360px">
    <Heading :level="2" :accessibility-level="1" justify="center">
      Quarterly review
    </Heading>
    <Heading :level="3" has-strikethrough justify="start">
      Draft agenda
    </Heading>
    <Text as="p" justify="center" text-wrap="balance">
      The visual size stays on the page. The outline level is what assistive technology reads.
    </Text>
  </VStack>
</template>
```

## Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `level` | `HeadingLevel` | - | Heading level (1–6). Determines the semantic element (h1–h6). A numeric string reads as its number; a missing level, or one outside 1–6, renders level 2 and warns in development. |
| `type` | `HeadingType` | - | Visual type variant that overrides the default level styling. Optional: `display-1`, `display-2`, `display-3`, `body`, `large`, `label`, `supporting`. |
| `color` | `HeadingColor` | `'primary'` | Text color. Optional: `primary`, `secondary`, `accent`, `inherit`. |
| `weight` | `HeadingWeight` | - | Font weight override. Optional: `regular`, `medium`, `semibold`, `bold`. |
| `display` | `HeadingDisplay` | `'block'` | Display type: `block` or `inline`. |
| `accessibilityLevel` | `1 \| 2 \| 3 \| 4 \| 5 \| 6` | - | Outline level for assistive technology when it should differ from the visual `level`. The element stays `h{level}`. |
| `textWrap` | `'wrap' \| 'nowrap' \| 'balance' \| 'pretty'` | - | CSS `text-wrap`. |
| `wordBreak` | `'break-word' \| 'break-all'` | `break-all` for one line, `break-word` for more | How long unbroken strings break when truncating. Without truncation, a token longer than its line (a URL, an ID) wraps (`overflow-wrap: break-word`), so in ordinary flow the text does not make the page scroll sideways. Inside a flex row, give the flex child `min-width: 0` so it can shrink. A container you style with `overflow-wrap: anywhere` does not reach this text; Astryx's own containers pass their wrap through. |
| `justify` | `'start' \| 'center' \| 'end'` | `'start'` | Text alignment. `start` and `end` follow the writing direction. |
| `hasCapsize` | `boolean` | `false` | Trims the leading above the cap height and below the baseline with `text-box-trim`, so glyphs sit flush with the box edges. Forces block layout. |
| `hasStrikethrough` | `boolean` | `false` | Draws a line through the text. |
| `hasTruncateTooltip` | `boolean \| 'above' \| 'below' \| 'start' \| 'end'` | `true` | Puts the full text in a tooltip after truncation. `false` turns it off and skips the measurement. It stays closed when the text fits. The tooltip mounts on the first hover, tap or keyboard focus; until then the element has no tooltip layer and no `aria-describedby`. |
| `maxLines` | `number` | `0` | Maximum lines before truncation. 0 means no truncation. |

## Native attributes

The root element is `<h1>` through `<h6>`.

The following are passed to the root element:

- HTML attributes.
- `aria-*` attributes. Your own `aria-level` wins over the one `accessibilityLevel` derives.
- `data-*` attributes.
- `class`.
- `style`. When `maxLines` is above 1, its line clamp replaces any `-webkit-line-clamp` in `style`.
