# Link — SvelteKit UI

Package: sveltekit-ui 1.1.94

Page: https://www.sveltekit-ui.com/components/link

Category: Foundations

Renders a hyperlink (`<a>`) with optional popover preview. Can handle internal (SvelteKit `goto`) or external links, show a QR, copy link, etc.

Public component import: `Link`

Public manager import: `create_link_manager`

## Usage

```svelte
<script>
  // Import the shared stylesheet once in your application's root layout.
  import "sveltekit-ui/style.css"
  import { Link, create_link_manager } from "sveltekit-ui"

  const manager = create_link_manager({
    href: "https://svelte.dev",
    display_text: "Svelte documentation",
    is_show_preview: true,
  })
</script>

<Link {manager} />
```

## Configuration

### `id`

- type: string or null
- default: generated unique ID
- description: A unique string ID for this link.

### `href`

- type: string
- default: null
- description: The URL to navigate to. Determines internal vs external link.

### `display_text`

- type: string
- default: null
- description: The text displayed in the link if no child content is provided.

### `text_color`

- type: CSS color
- default: null
- description: Color of the link text.

### `is_show_preview`

- type: boolean
- default: !is_internal_link
- description: If true, clicking the link opens a popover with a QR code and copy button. If false, no popover is shown.

### `on_goto_external_link`

- type: function
- default: null
- description: Optional callback when user opens an external link.

## Methods

### `init()`

- description: Sets up popover, QR code manager, copy/goto buttons, etc. Called once with config.

### `handle_a_click()`

- description: Click handler for the `<a>` element. Prevents default and either triggers internal or external link logic.

### `open_link()`

- description: Opens the link via SvelteKit `goto` if internal, or in a new tab if external.

## Returned state

### `href`

- type: string
- description: Current link address.

### `popover_manager`

- type: object
- description: Popover manager for the link preview popover.

### `copy_link_button_manager`

- type: object
- description: Button manager for the 'Copy Link' button in the popover.

### `goto_link_button_manager`

- type: object
- description: Button manager for the 'Open Link In New Tab' button in the popover.

### `goto_link_same_tab_button_manager`

- type: object
- description: Button manager for the 'Open Link In Same Tab' button in the popover.

### `inline_goto_link_button_manager`

- type: object
- description: Button manager displayed inline for direct navigation if `is_show_preview` is false.

### `qr_manager`

- type: object
- description: QR manager for generating the link's QR code preview.

### `is_internal_link`

- type: boolean
- description: Whether `href` starts with '/' (treated as internal).

### `is_show_preview`

- type: boolean
- description: Whether the popover preview is shown on click.
