# Link

## Usage

`Link` navigates inside the app or out of it. With `href` it renders an anchor. Pass `as` to use a router link or another component; that component receives both `href` and `to`. Without `href` it renders a button. A disabled link stays a plain anchor and does not use the custom root. `size` and `weight` follow the same steps as body text, and `maxLines` limits how many lines stay visible.

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

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

<template>
  <Link href="/docs">
    Documentation
  </Link>
  <Link href="https://github.com" is-external-link>
    GitHub
  </Link>
</template>
```

### Anatomy

- **Label**: The visible text of the link.
- **Right icon**: Icon placed after the label to indicate an action affordance.
- **Left icon**: Icon placed before the label to represent meaning.

## Best practices

| Guidance | Practice |
| --- | --- |
| Recommended | Use link text that describes the destination, e.g. "View docs" or "Contact us". Avoid "click here". |
| Recommended | Use `isExternalLink` for off-site links to add `target="_blank"` and `rel="noopener noreferrer"`. |
| Recommended | Use `color="secondary"` to reduce visual weight in groups of links or paragraphs. |
| Recommended | Put a Link inside a `Text` with `maxLines` to truncate it with the surrounding text; inside a clamped `Text` the link flows in the text's lines. |
| Don't | Make every piece of text a link; it weakens link discoverability. |
| Don't | Expect a clamped `Text` to cut a Link that sets its own `maxLines` or renders as a button (no `href`); that Link keeps its own box. |
| Don't | Make a critical action only a link. Important actions should use Button. |

## Examples

### External links

A vertical list of external links that open in a new tab with an indicator icon.

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

<template>
  <VStack :gap="2">
    <Link href="https://github.com" is-external-link is-standalone>
      GitHub
    </Link>
    <Link href="https://developer.mozilla.org" is-external-link is-standalone>
      MDN Web Docs
    </Link>
    <Link href="https://react.dev" is-external-link has-underline is-standalone>
      React Documentation
    </Link>
  </VStack>
</template>
```

### Inline text

A link embedded within a paragraph of body text.

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

<template>
  <Text type="body">
    Read the <Link href="#">
      documentation
    </Link> for more information about using Astryx components.
  </Text>
</template>
```

### With tooltips

Horizontal row of standalone links with descriptive hover tooltips.

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

<template>
  <HStack align="center" :gap="4">
    <Link href="#" tooltip="Configure your account settings" is-standalone>
      Settings
    </Link>
    <Link href="#" tooltip="View and edit your profile" is-standalone>
      Profile
    </Link>
    <Link href="#" tooltip="Get help and support" color="secondary" is-standalone>
      Help
    </Link>
  </HStack>
</template>
```

### Line limit

In a narrow box the link shows at most two lines, in a smaller size and a heavier weight.

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

<template>
  <div class="link-preview" style="width: 16rem">
    <Link href="#notes" :max-lines="2" size="sm" weight="semibold">
      Field notes from the harbor survey, including the tide table and the list of boats still in the channel.
    </Link>
  </div>
</template>
```

## Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `href` | `string` | - | Link URL. When omitted, the component renders as a `<button>`. |
| `as` | `LinkRoot` | - | Root used instead of `<a>` when the link has an address and is enabled. It receives `href` and `to`. |
| `label` | `string` | - | Accessible name. Use it when the visible content is not the name, such as an icon-only link. It replaces the link text for assistive technology. |
| `newTabLabel` | `string` | Localized “(opens in new tab)” | Screen-reader text after an external link. |
| `size` | `LinkSize` | - | Font size, the same steps as body text: sm, md, lg, xl. |
| `weight` | `LinkWeight` | - | Font weight. normal is the same as regular. |
| `maxLines` | `number` | `0` | Maximum visible lines. 0 does not truncate. |
| `isExternalLink` | `boolean` | `false` | Whether the link opens in a new tab and shows an external indicator. |
| `hasUnderline` | `boolean` | `false` | Whether the underline is always visible. |
| `color` | `LinkColor` | `'accent'` | Link color. Optional: primary, secondary, accent, inherit. |
| `isDisabled` | `boolean` | `false` | Whether the link is disabled. It cannot navigate or emit `click`, keeps its Tab stop, and is announced as disabled. A caller `role` or `aria-disabled` does not replace that; a caller `tabindex` still applies. |
| `target` | `string` | - | HTML target attribute. |
| `rel` | `string` | - | HTML rel attribute. External links automatically add noopener noreferrer. |
| `download` | `string \| boolean` | - | Triggers a download of the linked URL. A string is the suggested filename. `true` renders a bare `download` attribute, `false` renders no attribute at all. |
| `referrerPolicy` | `string` | - | Referrer policy for the link, forwarded as the `referrerpolicy` attribute. |

## Events

| Name | Description |
| --- | --- |
| `click` | Emitted on click. Not emitted when disabled. |

## Slots

| Name | Description |
| --- | --- |
| `default` | Link text content. |

## Native attributes

The root element is an `<a>`, a `<button>`, or the component passed to `as`. A disabled link is always an `<a>` without an address.

The following are passed to the root element:

- HTML attributes.
- `aria-*` attributes.
- `data-*` attributes. `data-color` always reflects `color`, so a caller value does not replace it.
- `class`.
- `style`.

## Accessibility

### Link text

- Criterion: 1.4.3 Contrast (Minimum)
- Check: 4.5:1
- States: Rest, Hover, Pointer down

Link text must have at least 4.5:1 contrast with the background behind it. For Pointer down, measure against the pressed overlay the link paints behind its text.
