# Link

Text that goes to another page, inline in running text or as a standalone subtle link.

- Family: action
- Import: `import { Link } from "@senvenli/react/action";`
- Page: https://design.senvenli.com/docs/components/link
- JSON: https://design.senvenli.com/docs/components/link.json

## Example: A link to a page

The text names the destination and makes sense on its own.

```tsx
import { Link } from "@senvenli/react/action";

export default function Example() {
  return <Link href="#">View all orders</Link>;
}
```

## Examples

### In running text

Always underlined, so it is found without relying on color.

```tsx
import { Link } from "@senvenli/react/action";
import { Text } from "@senvenli/react/display";

export default function Example() {
  return (
    <Text elementType="p">
      By placing an order you agree to{" "}
      <Link href="#" variant="inline">
        the terms of service
      </Link>{" "}
      and{" "}
      <Link href="#" variant="inline">
        the privacy policy
      </Link>
      .
    </Text>
  );
}
```

### External

Opens in a new tab, shows the arrow and tells screen readers so.

```tsx
import { Link } from "@senvenli/react/action";

export default function Example() {
  return (
    <Link href="https://example.com/docs/shipping" isExternal>
      Shipping documentation
    </Link>
  );
}
```

### Subtle

For footers and legal rows, where links should not compete with content.

```tsx
import { Link } from "@senvenli/react/action";
import { Stack } from "@senvenli/react/layout";

export default function Example() {
  return (
    <Stack direction="horizontal" space="space-200">
      <Link href="#" variant="subtle">
        Privacy policy
      </Link>
      <Link href="#" variant="subtle">
        Terms of service
      </Link>
      <Link href="#" variant="subtle">
        System status
      </Link>
    </Stack>
  );
}
```

## Guidelines

### When to use it

- Going to another page from within text or a footer.

### Use something else when

- [button](https://design.senvenli.com/docs/components/button.md): The link is a call to action that should look like a button.

### Do and avoid

- Name the destination; never "click here".

## Accessibility

Keyboard:

- Enter: Follows the link.

Built in:

- External links open in a new tab safely and say so to screen readers.

You provide:

- Link text that makes sense on its own.

## API reference

### Link

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| children | `React.ReactNode` |  | yes | Names the destination ("the terms of service"), never "click here". |
| variant | `LinkVariant` | `"default"` | no | `inline` in running text (always underlined), `subtle` in footers and legal rows. |
| isExternal | `boolean` |  | no | Opens in a new tab with `noopener noreferrer` and shows the 12px `arrow-up-right`. |

Behavior props from React Aria:

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| autoFocus | `boolean` |  | no | Whether the element should receive focus on render. |
| rel | `string` |  | no | The relationship between the linked resource and the current page. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel). |
| onFocus | `(e: FocusEvent<Element, Element>) => void` |  | no | Handler that is called when the element receives focus. |
| onBlur | `(e: FocusEvent<Element, Element>) => void` |  | no | Handler that is called when the element loses focus. |
| onClick | `(e: MouseEvent<FocusableElement, MouseEvent>) => void` |  | no | **Not recommended – use `onPress` instead.** `onClick` is an alias for `onPress` provided for compatibility with other libraries. `onPress` provides additional event details for non-mouse interactions. |
| href | `string` |  | no | A URL to link to. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#href). |
| isDisabled | `boolean` |  | no | Whether the link is disabled. |
| onPress | `(e: PressEvent) => void` |  | no | Handler that is called when the press is released over the target. |
| onPressStart | `(e: PressEvent) => void` |  | no | Handler that is called when a press interaction starts. |
| onPressEnd | `(e: PressEvent) => void` |  | no | Handler that is called when a press interaction ends, either over the target or when the pointer leaves the target. |
| onPressChange | `(isPressed: boolean) => void` |  | no | Handler that is called when the press state changes. |
| onPressUp | `(e: PressEvent) => void` |  | no | Handler that is called when a press is released over the target, regardless of whether it started on the target or not. |
| onFocusChange | `(isFocused: boolean) => void` |  | no | Handler that is called when the element's focus status changes. |
| onHoverStart | `(e: HoverEvent) => void` |  | no | Handler that is called when a hover interaction starts. |
| onHoverEnd | `(e: HoverEvent) => void` |  | no | Handler that is called when a hover interaction ends. |
| onHoverChange | `(isHovering: boolean) => void` |  | no | Handler that is called when the hover state changes. |
| render | `(props: DetailedHTMLProps<LinkWithRequiredHref, HTMLAnchorElement> \| React.JSX.IntrinsicElements[Fallback], renderProps: T) => ReactElement` |  | no | Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components. Note: You can check if `'href' in props` in order to tell whether to render an `<a>` element. Requirements: - You must render the expected element type (e.g. if `<a>` is expected, you cannot render a `<button>`). - Only a single root DOM element can be rendered (no fragments). - You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate. |
| hrefLang | `string` |  | no | Hints at the human language of the linked URL. See[MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#hreflang). |
| download | `string \| boolean` |  | no | Causes the browser to download the linked URL. A string may be provided to suggest a file name. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#download). |
| ping | `string` |  | no | A space-separated list of URLs to ping when the link is followed. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#ping). |
| referrerPolicy | `HTMLAttributeReferrerPolicy` |  | no | How much of the referrer to send when following the link. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#referrerpolicy). |

Also takes 77 standard DOM and ARIA attributes (id, aria-label, event handlers…).

### Tokens it reads

`--ds-background-brand-bold`, `--ds-background-brand-bold-hovered`, `--ds-background-brand-bold-pressed`, `--ds-background-danger`, `--ds-background-danger-bold`, `--ds-background-danger-bold-hovered`, `--ds-background-disabled`, `--ds-background-neutral`, `--ds-background-neutral-hovered`, `--ds-background-neutral-pressed`, `--ds-background-neutral-subtle-hovered`, `--ds-background-selected`, `--ds-background-selected-hovered`, `--ds-background-selected-pressed`, `--ds-border`, `--ds-border-bold`, `--ds-border-focused`, `--ds-border-selected`, `--ds-easing-standard`, `--ds-link`, `--ds-link-pressed`, `--ds-radius-control-medium`, `--ds-size-control`, `--ds-size-control-compact`, `--ds-size-control-large`, `--ds-size-icon`, `--ds-space-025`, `--ds-space-050`, `--ds-space-075`, `--ds-space-100`, `--ds-space-150`, `--ds-space-200`, `--ds-text`, `--ds-text-danger`, `--ds-text-disabled`, `--ds-text-on-brand`, `--ds-text-on-danger`, `--ds-text-subtle`

## Related

- [button](https://design.senvenli.com/docs/components/button.md)
