# QR Code URL: https://ark-ui.com/docs/components/qr-code Source: https://raw.githubusercontent.com/chakra-ui/ark/refs/heads/main/website/src/content/pages/components/qr-code.mdx A component that generates a QR code based on the provided data. --- ## Anatomy ```tsx ``` ## Examples **Example: basic** ```ripple import { QrCode } from 'ark-ripple/qr-code'; import styles from 'styles/qr-code.module.css'; export component Basic() { } ``` ### With Overlay You can also add a logo or overlay to the QR code. This is useful when you want to brand the QR code. **Example: overlay** ```ripple import { QrCode } from 'ark-ripple/qr-code'; import styles from 'styles/qr-code.module.css'; export component Overlay() { Ark UI Logo } ``` ### Error Correction In cases where the link is too long or the logo overlay covers a significant area, the error correction level can be increased. Use the `encoding.ecc` or `encoding.boostEcc` property to set the error correction level: - `L`: Allows recovery of up to 7% data loss (default) - `M`: Allows recovery of up to 15% data loss - `Q`: Allows recovery of up to 25% data loss - `H`: Allows recovery of up to 30% data loss **Example: error-correction** ```ripple import { QrCode } from 'ark-ripple/qr-code'; import { RadioGroup } from 'ark-ripple/radio-group'; import { track } from 'ripple'; import styles from 'styles/qr-code.module.css'; import radio from 'styles/radio-group.module.css'; export component ErrorCorrection() { let errorLevel = track('L');
{ @errorLevel = e.value; }} >
for (const level of ['L', 'M', 'Q', 'H']; key level) { {level} }
} ``` ### Root Provider An alternative way to control the QR code is to use the `RootProvider` component and the `useQrCode` hook. This way you can access the state and methods from outside the component. **Example: root-provider** ```ripple import { QrCode, useQrCode } from 'ark-ripple/qr-code'; import styles from 'styles/qr-code.module.css'; export component RootProvider() { const qrCode = useQrCode({ value: 'http://ark-ui.com' });
{@qrCode.value}
} ``` ### Download Use the `QrCode.DownloadTrigger` component to allow users to download the QR code as an image. Specify the `fileName` and `mimeType` props for the downloaded file. **Example: download** ```ripple import { QrCode } from 'ark-ripple/qr-code'; import button from 'styles/button.module.css'; import styles from 'styles/qr-code.module.css'; export component Download() { {'Download'} } ``` ## API Reference ### Props **Component API Reference** **Root Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | | `defaultValue` | `string` | No | The initial value to encode when rendered. Use when you don't need to control the value of the qr code. | | `encoding` | `QrCodeGenerateOptions` | No | The qr code encoding options. | | `id` | `string` | No | The unique identifier of the machine. | | `ids` | `Partial<{ root: string; frame: string }>` | No | The element ids. | | `onValueChange` | `(details: ValueChangeDetails) => void` | No | Callback fired when the value changes. | | `pixelSize` | `number` | No | The pixel size of the qr code. | | `value` | `string` | No | The controlled value to encode. | **Root CSS Variables:** | Variable | Description | |----------|-------------| | `--qrcode-pixel-size` | The size of the Root | | `--qrcode-width` | The width of the Root | | `--qrcode-height` | The height of the Root | **DownloadTrigger Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `fileName` | `string` | Yes | The name of the file. | | `mimeType` | `DataUrlType` | Yes | The mime type of the image. | | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | | `quality` | `number` | No | The quality of the image. | **Frame Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **Overlay Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **Pattern Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **RootProvider Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `value` | `UseQrCodeReturn` | Yes | | | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | ### Context **API:** | Property | Type | Description | |----------|------|-------------| | `value` | `string` | The value to encode. | | `setValue` | `(value: string) => void` | Set the value to encode. | | `getDataUrl` | `(type: DataUrlType, quality?: number) => Promise` | Returns the data URL of the qr code. |