|
| 1 | +# @lglab/react-qr-code Technical Reference |
| 2 | + |
| 3 | +> Comprehensive technical documentation for @lglab/react-qr-code, a highly customizable React QR code generator. |
| 4 | + |
| 5 | +This file provides all technical details including component props, types, and API references to enable LLMs to work with the library without fetching additional context. |
| 6 | + |
| 7 | +## ReactQRCode Component |
| 8 | + |
| 9 | +The main component exported by the library. |
| 10 | + |
| 11 | +### Props (ReactQRCodeProps) |
| 12 | + |
| 13 | +| Prop | Type | Default | Description | |
| 14 | +| --- | --- | --- | --- | |
| 15 | +| `value` | `string \| string[]` | - | **Required.** The value to encode. Use an array for multi-segment optimization. | |
| 16 | +| `size` | `number` | `128` | The size in pixels of the rendered QR code. | |
| 17 | +| `level` | `'L' \| 'M' \| 'Q' \| 'H'` | `'L'` | Error Correction Level. | |
| 18 | +| `marginSize` | `number` | `0` | Number of modules to use for the margin. | |
| 19 | +| `minVersion` | `number` | `1` | Minimum version (1-40) for the QR code. | |
| 20 | +| `boostLevel` | `boolean` | `true` | Boosts ECL if version remains the same. | |
| 21 | +| `background` | `BackgroundSettings` | `'#FFFFFF'` | Background color (hex) or `GradientSettings`. | |
| 22 | +| `gradient` | `GradientSettings` | - | Gradient applied to data modules and finder patterns. | |
| 23 | +| `dataModulesSettings` | `DataModulesSettings` | - | Configuration for data modules styling. | |
| 24 | +| `finderPatternOuterSettings` | `FinderPatternOuterSettings` | - | Configuration for outer finder patterns. | |
| 25 | +| `finderPatternInnerSettings` | `FinderPatternInnerSettings` | - | Configuration for inner finder patterns. | |
| 26 | +| `imageSettings` | `ImageSettings` | - | Settings for an embedded logo or image. | |
| 27 | +| `svgProps` | `React.SVGProps<SVGSVGElement>` | - | Additional props passed to the root SVG element. | |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +## Sub-Settings Interfaces |
| 32 | + |
| 33 | +### DataModulesSettings |
| 34 | + |
| 35 | +| Property | Type | Default | Description | |
| 36 | +| --- | --- | --- | --- | |
| 37 | +| `color` | `string` | - | Color of the data modules (overridden by `gradient`). | |
| 38 | +| `style` | `DataModulesStyle` | `'square'` | Shape of the data modules. | |
| 39 | +| `randomSize` | `boolean` | `false` | If true, modules will have slightly varied sizes. | |
| 40 | + |
| 41 | +**Available Styles (`DataModulesStyle`):** |
| 42 | +`'square'`, `'square-sm'`, `'pinched-square'`, `'rounded'`, `'leaf'`, `'vertical-line'`, `'horizontal-line'`, `'circle'`, `'diamond'`, `'star'`, `'heart'`, `'hashtag'` |
| 43 | + |
| 44 | +### FinderPatternOuterSettings |
| 45 | + |
| 46 | +| Property | Type | Default | Description | |
| 47 | +| --- | --- | --- | --- | |
| 48 | +| `color` | `string` | - | Color of the outer pattern (overridden by `gradient`). | |
| 49 | +| `style` | `FinderPatternOuterStyle` | `'square'` | Shape of the outer finder pattern. | |
| 50 | + |
| 51 | +**Available Styles (`FinderPatternOuterStyle`):** |
| 52 | +`'square'`, `'pinched-square'`, `'rounded-sm'`, `'rounded'`, `'rounded-lg'`, `'circle'`, `'inpoint-sm'`, `'inpoint'`, `'inpoint-lg'`, `'outpoint-sm'`, `'outpoint'`, `'outpoint-lg'`, `'leaf-sm'`, `'leaf'`, `'leaf-lg'` |
| 53 | + |
| 54 | +### FinderPatternInnerSettings |
| 55 | + |
| 56 | +| Property | Type | Default | Description | |
| 57 | +| --- | --- | --- | --- | |
| 58 | +| `color` | `string` | - | Color of the inner pattern (overridden by `gradient`). | |
| 59 | +| `style` | `FinderPatternInnerStyle` | `'square'` | Shape of the inner finder pattern. | |
| 60 | + |
| 61 | +**Available Styles (`FinderPatternInnerStyle`):** |
| 62 | +Includes all `FinderPatternOuterStyle` plus: `'diamond'`, `'star'`, `'heart'`, `'hashtag'` |
| 63 | + |
| 64 | +### ImageSettings |
| 65 | + |
| 66 | +| Property | Type | Default | Description | |
| 67 | +| --- | --- | --- | --- | |
| 68 | +| `src` | `string` | - | **Required.** URL/Source of the image. | |
| 69 | +| `height` | `number` | - | **Required.** Height in pixels. | |
| 70 | +| `width` | `number` | - | **Required.** Width in pixels. | |
| 71 | +| `excavate` | `boolean` | `false` | Remove modules behind the image. | |
| 72 | +| `x` | `number` | - | Horizontal offset (centered by default). | |
| 73 | +| `y` | `number` | - | Vertical offset (centered by default). | |
| 74 | +| `opacity` | `number` | `1` | Image opacity (0-1). | |
| 75 | +| `crossOrigin` | `CrossOrigin` | - | CORS setting for the image. | |
| 76 | + |
| 77 | +### GradientSettings |
| 78 | + |
| 79 | +| Property | Type | Default | Description | |
| 80 | +| --- | --- | --- | --- | |
| 81 | +| `type` | `'linear' \| 'radial'` | - | **Required.** Type of gradient. | |
| 82 | +| `stops` | `GradientSettingsStop[]` | - | **Required.** Array of `{ offset: string, color: string }`. | |
| 83 | +| `rotation` | `number` | `0` | Rotation in degrees (for linear gradients). | |
| 84 | + |
| 85 | +--- |
| 86 | + |
| 87 | +## Imperative API (Ref) |
| 88 | + |
| 89 | +The component exposes the following via `forwardRef`: |
| 90 | + |
| 91 | +### ReactQRCodeRef |
| 92 | + |
| 93 | +| Method / Property | Type | Description | |
| 94 | +| --- | --- | --- | |
| 95 | +| `svg` | `SVGSVGElement \| null` | Reference to the underlying SVG element. | |
| 96 | +| `download` | `(options: DownloadOptions) => void` | Triggers a download of the QR code. | |
| 97 | + |
| 98 | +### DownloadOptions |
| 99 | + |
| 100 | +| Property | Type | Default | Description | |
| 101 | +| --- | --- | --- | --- | |
| 102 | +| `name` | `string` | `'qr-code'` | Filename without extension. | |
| 103 | +| `format` | `'svg' \| 'png' \| 'jpeg'` | `'svg'` | Target file format. | |
| 104 | +| `size` | `number` | `500` | Target size in pixels for the export. | |
| 105 | + |
| 106 | +--- |
| 107 | + |
| 108 | +## Examples |
| 109 | + |
| 110 | +### Basic Usage |
| 111 | +```tsx |
| 112 | +import { ReactQRCode } from '@lglab/react-qr-code'; |
| 113 | + |
| 114 | +<ReactQRCode value="https://reactqrcode.com" /> |
| 115 | +``` |
| 116 | + |
| 117 | +### Advanced Customization |
| 118 | +```tsx |
| 119 | +<ReactQRCode |
| 120 | + value="https://reactqrcode.com" |
| 121 | + size={256} |
| 122 | + level="H" |
| 123 | + dataModulesSettings={{ |
| 124 | + style: 'rounded', |
| 125 | + color: '#2563eb' |
| 126 | + }} |
| 127 | + finderPatternOuterSettings={{ |
| 128 | + style: 'rounded-lg' |
| 129 | + }} |
| 130 | + imageSettings={{ |
| 131 | + src: '/logo.png', |
| 132 | + width: 40, |
| 133 | + height: 40, |
| 134 | + excavate: true |
| 135 | + }} |
| 136 | +/> |
| 137 | +``` |
| 138 | + |
0 commit comments