QR Code
A component that generates a QR code based on the provided data.
Anatomy
<QrCode.Root>
<QrCode.Frame>
<QrCode.Pattern />
</QrCode.Frame>
<QrCode.Overlay />
<QrCode.DownloadTrigger />
</QrCode.Root>
Examples
With Overlay
Add a logo or overlay to brand the QR code.
Error Correction
Raise the error correction level when the link is long or the overlay covers much of the code. Set it with
encoding.ecc or encoding.boostEcc:
L: recovers up to 7% data loss (default)M: up to 15%Q: up to 25%H: up to 30%
Root Provider
Use RootProvider with the useQrCode hook to access the state and methods from outside the component.
Download
QrCode.DownloadTrigger downloads the QR code as an image. Set fileName and mimeType for the file.
API Reference
Props
Root
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
defaultValue | stringThe initial value to encode when rendered. Use when you don't need to control the value of the qr code. | |
encoding | QrCodeGenerateOptionsThe qr code encoding options. | |
id | stringThe unique identifier of the machine. | |
ids | ElementIdsThe element ids. | |
onValueChange | (details: ValueChangeDetails) => voidCallback fired when the value changes. | |
pixelSize | numberThe pixel size of the qr code. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. | |
value | stringThe controlled value to encode. |
| CSS 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
Defines the <button> element.
| Attribute | Default | Type |
|---|---|---|
fileName | stringThe name of the file. | |
mimeType | DataUrlTypeThe mime type of the image. | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
quality | numberThe quality of the image. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Frame
Defines the <svg> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Overlay
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Pattern
Defines the <path> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
RootProvider
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
value | UseQrCodeReturn | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Context
API
| Property | Type |
|---|---|
value | stringThe value to encode. |
setValue | (value: string) => voidSet the value to encode. |
getDataUrl | (type: DataUrlType, quality?: number) => Promise<string>Returns the data URL of the qr code. Includes the overlay when present. |