# QR Code Download (Components)

URL: https://qrdx.dev/docs/components/qr-code-download
Source: https://github.com/qrdxinc/qrdx/blob/main/apps/docs/content/docs/components/qr-code-download.mdx

A download menu for shadcn/ui projects that exports a QR code as PNG, SVG, JPG or PDF at the size you pick, or copies it as an image.

`QrCodeDownload` is one button that opens a menu of formats and sizes and saves the code as a file, or copies a PNG to the clipboard. Use it next to any code you render, with the same style object, so the file matches the preview.

## Installation [#installation]

```bash
npx shadcn@latest add @qrdx/qr-code-download
```

Or by URL, which works with older versions of the CLI too:

```bash
npx shadcn@latest add https://qrdx.dev/r/qr-code-download.json
```

## Usage [#usage]

```tsx title="components/example.tsx"
import { QrCodeDownload } from "@/components/qr-code-download";
```

```tsx title="components/example.tsx"
<QrCodeDownload value="https://qrdx.dev" />
```

The menu lists each format with a short hint, a size picker, and **Copy image**, which puts a PNG on the clipboard. Files are rendered in the browser; nothing is uploaded.

## Examples [#examples]

### Styled export [#styled-export]

Give `qr` the same style object you render on screen, so every exported file matches the preview. `formats`, `sizes`, `label` and `variant` shape the menu and its button.

### Formats [#formats]

| Format | Output |
| --- | --- |
| `png` | Image with the code's background |
| `jpg` | Image with a solid background |
| `svg` | Vector that scales to any size |
| `pdf` | Single-page document. Needs the optional `jspdf` package (`npm install jspdf`) |
| `eps` | Vector for print shops and design tools |

Raster sizes go from 50 to 5000 pixels. Pass a single entry in `sizes` to hide the size picker. The menu shows the pixel size next to raster formats and "vector" next to SVG and EPS.

### After a download [#after-a-download]

`onComplete` is called with the format, or `"copy"`, after a file is saved or the image is copied. `onError` receives the error when an export fails; the message also shows under the button.

```tsx title="components/tracked-download.tsx"
import { QrCodeDownload } from "@/components/qr-code-download";

export function TrackedDownload({ url }: { url: string }) {
  return (
    <QrCodeDownload
      value={url}
      onComplete={(action) => console.log("exported", action)}
      onError={(error) => console.error(error.message)}
    />
  );
}
```

## Accessibility and rendering [#accessibility-and-rendering]

- The trigger is your Button, with `aria-busy` while a file is rendered. A result is announced through a polite live region, and an error shows under the button with `role="alert"`.
- The menu is your DropdownMenu, so keyboard navigation and focus follow your theme's components.
- Copying needs a user gesture and a secure context (HTTPS or localhost); the browser rejects it otherwise, and the error shows under the button.
- The component is a Client Component. It renders nothing visual on the server beyond the button.

## API reference [#api-reference]

### $Fumadocs

| Prop           | Type          | Description                                                                                     |
| -------------- | ------------- | ----------------------------------------------------------------------------------------------- |
| `value`        | `string`      | Text or URL to encode.                                                                          |
| `qr?`          | `QrCodeStyle` | qrdx style options for the exported code.                                                       |
| `formats?`     | `array`       | Formats in the menu. "pdf" needs the optional `jspdf` package. Default: `["png", "svg", "jpg"]` |
| `sizes?`       | `array`       | Pixel sizes to choose from. Pass one size to hide the size picker. Default: `[512, 1024, 2048]` |
| `defaultSize?` | `number`      | Size selected when the menu first opens. Default: `1024`                                        |
| `filename?`    | `string`      | Download file name without extension. Default: `"qr-code"`                                      |
| `copy?`        | `union`       | Show a "Copy image" item that copies a PNG to the clipboard. Default: `true`                    |
| `label?`       | `string`      | Trigger button label. Default: `"Download"`                                                     |
| `variant?`     | `union`       | Trigger button variant. Default: `"outline"`                                                    |
| `onComplete?`  | `function`    | Called after a file is saved or the image is copied.                                            |
| `onError?`     | `function`    | Called when an export fails.                                                                    |

Any other prop, such as `className`, is passed to the wrapping `<div>`.

## Related [#related]

- [QR Code](https://qrdx.dev/docs/components/qr-code): A code with a row of download buttons instead of a menu.
- [Export and download](https://qrdx.dev/docs/features/downloads): The library functions behind the menu, and every format's details.
- [QR Code Card](https://qrdx.dev/docs/components/qr-code-card): A card whose footer takes this menu.
