# LinkButton

Text link with an animated underline: a short gradient stroke that grows to the full width on hover and focus, while the icon after the text slides forward. It renders a native `<a>`: `href`, `target`, `download` and events (`onclick`, ...) work as in HTML, and with `target="_blank"` `rel` defaults to `noopener noreferrer`. A disabled link loses its `href` and gets `aria-disabled`, so it cannot be followed or focused and does not call `onclick`. For a link that looks like a button use `Button` with `href`. Its state is exposed as `data-disabled` for app CSS.

```ts
import { LinkButton } from '@likable-hair/svelte';
```

Category: simple. Source: `src/lib/components/simple/buttons/LinkButton.svelte`.

## Examples

### Basic

A text link whose underline grows on hover and focus. `appendIcon` slides forward with it; `prependIcon` stays still. The color comes from `--link-button-color`.

```svelte
<script lang="ts">
	import { mdiArrowRight, mdiBookOpenVariant } from '@mdi/js';
	import { LinkButton } from '@likable-hair/svelte';
</script>

<div class="row">
	<LinkButton href="#appointments" appendIcon={mdiArrowRight}>See all appointments</LinkButton>
	<LinkButton
		href="https://svelte.dev"
		target="_blank"
		prependIcon={mdiBookOpenVariant}
		--link-button-color="var(--global-color-primary)"
	>
		Documentation
	</LinkButton>
	<LinkButton href="#disabled" disabled>Disabled</LinkButton>
</div>

<style>
	.row {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		gap: 12px 28px;
	}
</style>
```

### Inside text

The link is inline: it takes the font size of the text around it, so it can sit inside a sentence.

```svelte
<script lang="ts">
	import { LinkButton } from '@likable-hair/svelte';
</script>

<p>
	Your plan renews on 1 November. You can <LinkButton href="#billing">change the payment method</LinkButton>
	or <LinkButton href="#cancel">cancel the renewal</LinkButton> at any time.
</p>

<style>
	p {
		max-width: 46ch;
		margin: 0;
		line-height: 1.7;
	}
</style>
```

## Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `href` (required) | `string` |  | URL of the link. |
| `target` | `'_self' \| '_blank' \| '_parent' \| '_top' \| (string & {})` |  | Native `target`. With `_blank`, `rel` defaults to `noopener noreferrer`. |
| `rel` | `string` |  | Native `rel`. |
| `disabled` | `boolean` | `false` | Removes the `href` and sets `aria-disabled`: the link cannot be followed, focused or clicked. |
| `prependIcon` | `string` |  | SVG path of an icon before the text, for example from `@mdi/js`. |
| `appendIcon` | `string` |  | SVG path of an icon after the text. It slides forward on hover. |
| `linkElement` (bindable) | `HTMLAnchorElement` |  | The native `<a>` element. |

It also accepts the native attributes and events of `<a>` (for example `id`, `title`, `aria-label`, `onkeydown`), which are forwarded to the element.

## Snippets

| Name | Parameters | Description |
| --- | --- | --- |
| `children` |  | Link text. |
| `prependSnippet` | `{ prependIcon: string \| undefined }` | Replaces the icon before the text. |
| `appendSnippet` | `{ appendIcon: string \| undefined }` | Replaces the icon after the text. It still slides forward on hover. |

## CSS variables

For a single instance, pass them as style props: `<LinkButton --link-button-background="tomato">`. The `--link-button-default-*` defaults apply to the whole app: override them in `:root` or in a theme.

| Per-instance variable | Default |
| --- | --- |
| `--link-button-duration` | `--link-button-default-duration`: `var(--global-duration-slow)` |
| `--link-button-icon-size` | `--link-button-default-icon-size`: `1.15em` |
| `--link-button-gap` | `--link-button-default-gap`: `6px` |
| `--link-button-padding` | `--link-button-default-padding`: `0` |
| `--link-button-border-radius` | `--link-button-default-border-radius`: `var(--global-radius-xs)` |
| `--link-button-background` | `--link-button-default-background`: `transparent` |
| `--link-button-color` | `--link-button-default-color`: `var(--global-color-text)` |
| `--link-button-font-size` | `--link-button-default-font-size`: `inherit` |
| `--link-button-font-weight` | `--link-button-default-font-weight`: `500` |
| `--link-button-line-height` | `--link-button-default-line-height`: `inherit` |
| `--link-button-underline-offset` | `--link-button-default-underline-offset`: `3px` |
| `--link-button-underline-height` | `--link-button-default-underline-height`: `2px` |
| `--link-button-underline-background` | `--link-button-default-underline-background`: `var(--global-gradient)` |
| `--link-button-underline-opacity` | `--link-button-default-underline-opacity`: `0.6` |
| `--link-button-underline-scale` | `--link-button-default-underline-scale`: `0.2` |
| `--link-button-hover-color` | `--link-button-default-hover-color`: `var(--link-button-default-color)` |
| `--link-button-hover-background` | `--link-button-default-hover-background`: `transparent` |
| `--link-button-icon-shift` | `--link-button-default-icon-shift`: `3px` |
| `--link-button-focus-ring-width` | `--link-button-default-focus-ring-width`: `var(--global-focus-ring-width)` |
| `--link-button-focus-ring-color` | `--link-button-default-focus-ring-color`: `var(--global-focus-ring-color)` |
| `--link-button-focus-ring-offset` | `--link-button-default-focus-ring-offset`: `var(--global-focus-ring-offset)` |
| `--link-button-disabled-opacity` | `--link-button-default-disabled-opacity`: `0.4` |
