# Text

## Usage

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

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

<template>
  <Text type="body">
    Body content
  </Text>
  <Text type="supporting">
    Supporting details
  </Text>
</template>
```

### Anatomy

- **Text**: Polymorphic text element that renders the supplied content with themed typography.
- **Heading**: Referenced Heading member that renders the supplied content as a semantic h1–h6 element.
- **Truncation tooltip**: Tooltip-owned surface available only when Text or Heading is measured as truncated and truncation tooltips are enabled.

## Best practices

| Guidance | Practice |
| --- | --- |
| Recommended | Use `type` for semantic hierarchy: `large` for emphasis, `supporting` for hints, `label` for form labels. |
| Recommended | Set `as="p"` or `display="block"` when you need block-level layout. |
| Recommended | Use `maxLines` to clamp long text to a fixed number of lines. |
| Don't | Use `Text` in place of `Heading`. Headings should use the `Heading` component for correct semantics. |
| Don't | Mix too many `type` and `size` combinations in the same short passage. |

## Examples

### Colors

Primary, secondary, accent, disabled, and placeholder colors, each used for the kind of text it names.

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

const colors: { color: TextColor, description: string }[] = [
  { color: 'primary', description: 'Primary — Default for headings and body text' },
  { color: 'secondary', description: 'Secondary — Supporting details and metadata' },
  { color: 'accent', description: 'Accent — Links, emphasis, and accent-colored text' },
  { color: 'disabled', description: 'Disabled — Unavailable or inactive content' },
  { color: 'placeholder', description: 'Placeholder — Empty field hints' },
]
</script>

<template>
  <VStack :gap="3">
    <Text v-for="item in colors" :key="item.color" type="body" :color="item.color">
      {{ item.description }}
    </Text>
  </VStack>
</template>
```

### Heading levels

Heading levels 1 through 6, with the type scale stepping down at each level.

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

const levels: HeadingLevel[] = [1, 2, 3, 4, 5, 6]
</script>

<template>
  <VStack :gap="3">
    <Heading v-for="level in levels" :key="level" :level="level">
      Heading {{ level }}
    </Heading>
  </VStack>
</template>
```

### Inline

Text is inline by default, so body copy and a code span can share one line.

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

<template>
  <Text type="body" display="block">
    Design tokens are <Text type="code">
      themeable
    </Text> and shared across every surface.
  </Text>
</template>
```

### Truncation

maxLines clamps a paragraph to one, two, or three lines and ends the overflow with an ellipsis.

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

const longText = 'The design system provides a consistent set of typography tokens, spacing scales, and color palettes that ensure every surface in the product feels cohesive regardless of which team built it.'
const lines = [
  { maxLines: 1, label: '1 line' },
  { maxLines: 2, label: '2 lines' },
  { maxLines: 3, label: '3 lines' },
]
</script>

<template>
  <div class="text-preview__clamp">
    <div v-for="item in lines" :key="item.maxLines">
      <Text type="supporting" color="secondary" display="block">
        {{ item.label }}
      </Text>
      <div class="text-preview__box">
        <Text type="body" :max-lines="item.maxLines">
          {{ longText }}
        </Text>
      </div>
    </div>
  </div>
</template>
```

### Types

The body, large, label, supporting, and code types, plus strikethrough and tabular figures.

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

const types: {
  type: TextType
  label: string
  sample: string
  hasStrikethrough?: boolean
  hasTabularNumbers?: boolean
}[] = [
  { type: 'body', label: 'Body text', sample: 'Body text for paragraphs and general content' },
  { type: 'large', label: 'Large text', sample: 'Large text for introductions and callouts' },
  { type: 'label', label: 'Label text', sample: 'Label text for form fields and section titles' },
  { type: 'supporting', label: 'Supporting text', sample: 'Supporting text for captions and metadata' },
  { type: 'code', label: 'Code text', sample: 'const theme = defineTheme({})' },
  { type: 'body', label: 'Strikethrough', sample: 'Body text with strikethrough decoration', hasStrikethrough: true },
  { type: 'body', label: 'Tabular numbers', sample: '1,234.56  78.90  100,000.00', hasTabularNumbers: true },
]
</script>

<template>
  <VStack :gap="3">
    <VStack v-for="item in types" :key="item.label" :gap="0">
      <Text type="supporting" color="secondary">
        {{ item.label }}
      </Text>
      <Text
        :type="item.type"
        display="block"
        :has-strikethrough="item.hasStrikethrough"
        :has-tabular-numbers="item.hasTabularNumbers"
      >
        {{ item.sample }}
      </Text>
    </VStack>
  </VStack>
</template>
```

### Weight

Normal, medium, semibold, and bold. Normal is the same weight as regular.

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

const weights: { weight: TextWeight, label: string }[] = [
  { weight: 'normal', label: 'Normal' },
  { weight: 'medium', label: 'Medium' },
  { weight: 'semibold', label: 'Semibold' },
  { weight: 'bold', label: 'Bold' },
]
</script>

<template>
  <VStack :gap="3">
    <Text
      v-for="item in weights"
      :key="item.weight"
      type="body"
      :weight="item.weight"
      display="block"
    >
      {{ item.label }}
    </Text>
  </VStack>
</template>
```

### Word break

break-word keeps a long token together when it can; break-all splits it at any character.

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

<template>
  <div class="text-preview__clamp">
    <div>
      <Text type="label" display="block">
        Break-word (default for multi-line)
      </Text>
      <div class="text-preview__box">
        <Text type="body" :max-lines="2" word-break="break-word">
          This is a verylongunbreakableword for a break-word example
        </Text>
      </div>
    </div>
    <div>
      <Text type="label" display="block">
        Break-all (default for single-line)
      </Text>
      <div class="text-preview__box">
        <Text type="body" :max-lines="2" word-break="break-all">
          Breaks anywhere: abcdefghijklmnopqrstuvwxyz0123456789
        </Text>
      </div>
    </div>
  </div>
</template>
```

### Wrap

Wrap, nowrap, balance, and pretty, each in a box of the same width.

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

<template>
  <div class="text-preview__clamp">
    <div>
      <Text type="label" display="block">
        Wrap (default)
      </Text>
      <div class="text-preview__box">
        <Text type="body" text-wrap="wrap">
          This text wraps normally at word boundaries when it reaches the edge.
        </Text>
      </div>
    </div>
    <div>
      <Text type="label" display="block">
        Nowrap
      </Text>
      <div class="text-preview__box text-preview__box--clip">
        <Text type="body" text-wrap="nowrap">
          This text does not wrap and will overflow its container.
        </Text>
      </div>
    </div>
    <div>
      <Text type="label" display="block">
        Balance
      </Text>
      <div class="text-preview__box">
        <Text type="body" text-wrap="balance">
          This text is balanced for better visual appearance across lines.
        </Text>
      </div>
    </div>
    <div>
      <Text type="label" display="block">
        Pretty
      </Text>
      <div class="text-preview__box">
        <Text type="body" text-wrap="pretty">
          This text uses pretty wrap to avoid orphans at the end of paragraphs.
        </Text>
      </div>
    </div>
  </div>
</template>
```

## Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `type` | `TextType` | `'body'` | Semantic text type. Determines default size, weight, and line-height. Optional: body, large, label, supporting, code, display-1, display-2, display-3. |
| `size` | `TextSize` | - | Explicit font size override. Optional: sm, md, lg, xl. |
| `color` | `TextColor` | `'primary'` | Text color. Optional: primary, secondary, accent, disabled, placeholder, inherit. |
| `weight` | `TextWeight` | - | Font weight override. Optional: regular, normal, medium, semibold, bold. normal is the same weight as regular. |
| `textWrap` | `TextWrap` | - | Wrapping behavior: wrap, nowrap, balance, or pretty. |
| `wordBreak` | `TextWordBreak` | - | How a long unbroken string breaks when truncating: normal, break-word, or break-all. 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. |
| `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. |
| `hasTabularNumbers` | `boolean` | `false` | Uses tabular figures so digits line up across rows. |
| `display` | `TextDisplay` | `'inline'` | Display type: `inline` or `block`. |
| `as` | `TextAs` | `'span'` | HTML element to render. Optional: span, p, div, label, h1, h2, h3, h4, h5, h6. Heading tags render a real heading element but keep `Text` typography; use `Heading` for heading sizing. |
| `justify` | `'start' \| 'center' \| 'end'` | `'start'` | Text alignment. `start` and `end` follow the writing direction. |
| `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. A positive value forces block layout so the ellipsis has a width. |

## Native attributes

The root element is determined by `as`, defaulting to `<span>`.

The following are passed to the root element:

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