# Qr — SvelteKit UI

Package: sveltekit-ui 1.1.94

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

Category: Data & content

Generates a stylized QR code with optional image in the center, supporting download and copying features.

Public component import: `Qr`

Public manager import: `create_qr_manager`

## Usage

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

  const manager = create_qr_manager({
    data: "https://svelte.dev",
    size: 180,
    margin: 8,
    is_show_copy: true,
    is_show_download: true,
  })
</script>

<Qr {manager} />
```

## Configuration

### `data`

- type: string
- default: null
- description: The primary data/content encoded within the QR code.

### `image`

- type: string or null (URL)
- default: null
- description: Optional image URL to place in the center of the QR code.

### `image_size`

- type: number
- default: 0.5
- description: How large the center image is as a fraction of overall QR size (0.5 means 50%).

### `size`

- type: number
- default: 200
- description: Width/height in px for the QR code.

### `margin`

- type: number
- default: 10
- description: Margin in px around the QR code.

### `type_number`

- type: number
- default: 0
- description: Integer (0-40) specifying detail level of QR. 0 means auto, higher means more capacity but bigger code.

### `error_correction_level`

- type: string
- default: Q
- allowed_values:
  - L
  - M
  - Q
  - H
- description: Amount of error correction. 'L' ~7%, 'M' ~15%, 'Q' ~25%, 'H' ~30%. Higher can handle more damage but uses bigger code.

### `color`

- type: string (CSS color)
- default: var(--primary-t)
- description: Main dots color of the QR code.

### `corner_color`

- type: string (CSS color)
- default: color-mix(in oklab, var(--primary-t), var(--bg) 20%)
- description: Special color for the larger 'corner squares' in the QR code.

### `background_color`

- type: string (CSS color)
- default: var(--shadow1-t)
- description: Background fill behind the QR code (the 'negative space' inside the bounding square).

### `border_color`

- type: string (CSS color)
- default: var(--shadow7-t)
- description: Border color of the QR container.

### `border_width`

- type: number
- default: 1
- description: Width in px of the QR container border.

### `border_radius`

- type: number
- default: (size + 2 * margin) / 100
- description: Border radius (in rem or direct numeric) for the QR container.

### `extension`

- type: string
- default: svg
- allowed_values:
  - svg
  - png
  - webp
- description: File type for the download if is_show_download is true.

### `quality`

- type: number (0.0 to 1.0)
- default: 0.8
- description: Used when downloading as raster formats like png or webp to specify image quality.

### `is_show_copy`

- type: boolean
- default: false
- description: If true, displays a text input of `data` plus a button to copy it to clipboard.

### `is_show_download`

- type: boolean
- default: false
- description: If true, shows a dropdown to pick file extension and a button to download the generated QR.

## Methods

### `init()`

- description: Initializes the manager with config values, sets up the internal managers (text, copy, download).

### `on_mount()`

- description: Called typically on Svelte's onMount. Creates the QR code with QRCodeStyling and appends to the DOM. If there's an error (e.g. data too large for type_number), sets error_message.

### `update()`

- description: Re-generates/updates the QR code with any changed config (color, data, etc.).

### `download()`

- description: Triggers a file download of the QR code with the chosen extension and quality.

## Returned state

### `id`

- type: string
- description: Unique ID for the QR container.

### `error_message`

- type: string or null
- description: Displays any generation errors encountered, e.g. if the data is too large for the chosen type_number/error_correction_level.

### `is_loaded`

- type: boolean
- description: True once the QR code is fully rendered. If false, shows a loading spinner.

### `text_manager`

- type: object
- description: A text input manager for the main data. If is_show_copy=true, this is displayed.

### `copy_button_manager`

- type: object
- description: Button manager for copying data to clipboard if is_show_copy=true.

### `download_button_manager`

- type: object
- description: Button manager for triggering the QR code download if is_show_download=true.

### `extention_dropdown_manager`

- type: object
- description: Dropdown manager controlling which extension is used when downloading (svg, png, webp).
