|
| 1 | +# Examples & Demos |
| 2 | + |
| 3 | +## 🎮 Live Playground |
| 4 | + |
| 5 | +Try out the library in your browser: |
| 6 | + |
| 7 | +- [**CodeSandbox**](https://codesandbox.io/s/react-qr-code-demo-ccho5l) - Full interactive playground |
| 8 | +- [**StackBlitz**](https://stackblitz.com/edit/react-qr-code-demo) - Instant online IDE |
| 9 | + |
| 10 | +## 📂 Local Examples |
| 11 | + |
| 12 | +The `/examples` directory contains comprehensive demonstrations of all features: |
| 13 | + |
| 14 | +### 🚀 Quick Start |
| 15 | + |
| 16 | +```bash |
| 17 | +# Clone and install |
| 18 | +git clone https://github.com/devmehq/react-qr-code.git |
| 19 | +cd react-qr-code |
| 20 | +yarn install |
| 21 | +yarn build |
| 22 | + |
| 23 | +# Serve examples (choose one) |
| 24 | +npx http-server examples -o # Using http-server |
| 25 | +python3 -m http.server 8080 -d examples # Using Python |
| 26 | +php -S localhost:8080 -t examples # Using PHP |
| 27 | +``` |
| 28 | + |
| 29 | +### 📄 Available Example Pages |
| 30 | + |
| 31 | +#### 1. **Main Interactive Demo** (`index.html`) |
| 32 | +- Live customization controls |
| 33 | +- Real-time preview |
| 34 | +- Export functionality |
| 35 | +- All basic options |
| 36 | + |
| 37 | +#### 2. **Advanced Customization** (`advanced-demo.html`) |
| 38 | +- 100+ QR code variations |
| 39 | +- All shape combinations |
| 40 | +- Gradient examples |
| 41 | +- Pattern backgrounds |
| 42 | +- Theme presets |
| 43 | +- Logo integration |
| 44 | + |
| 45 | +#### 3. **Simple Usage** (`simple-usage.html`) |
| 46 | +- Basic implementation |
| 47 | +- Common use cases |
| 48 | +- Template examples (WiFi, vCard, etc.) |
| 49 | +- Copy & paste code snippets |
| 50 | + |
| 51 | +#### 4. **API Documentation** (`api-docs.html`) |
| 52 | +- Complete props reference |
| 53 | +- Method documentation |
| 54 | +- TypeScript interfaces |
| 55 | +- Hook examples |
| 56 | + |
| 57 | +#### 5. **Detectability Test** (`qr-test.html`) |
| 58 | +- Test QR code scanning |
| 59 | +- Contrast validation |
| 60 | +- Real-time detectability feedback |
| 61 | +- Camera scanning test |
| 62 | + |
| 63 | +## 🎨 Featured Examples |
| 64 | + |
| 65 | +### Basic QR Code |
| 66 | + |
| 67 | +```tsx |
| 68 | +import { ReactQrCode } from '@devmehq/react-qr-code' |
| 69 | + |
| 70 | +<ReactQrCode |
| 71 | + value="https://example.com" |
| 72 | + size={256} |
| 73 | +/> |
| 74 | +``` |
| 75 | + |
| 76 | +### With Custom Styling |
| 77 | + |
| 78 | +```tsx |
| 79 | +import { AdvancedQRCode } from '@devmehq/react-qr-code' |
| 80 | + |
| 81 | +<AdvancedQRCode |
| 82 | + value="https://example.com" |
| 83 | + size={300} |
| 84 | + eyeShape="rounded" |
| 85 | + bodyShape="circle" |
| 86 | + theme="ocean" |
| 87 | +/> |
| 88 | +``` |
| 89 | + |
| 90 | +### Gradient QR Code |
| 91 | + |
| 92 | +```tsx |
| 93 | +<AdvancedQRCode |
| 94 | + value="https://example.com" |
| 95 | + bodyGradient={{ |
| 96 | + type: 'linear', |
| 97 | + colors: ['#667EEA', '#764BA2'], |
| 98 | + angle: 45 |
| 99 | + }} |
| 100 | +/> |
| 101 | +``` |
| 102 | + |
| 103 | +### With Logo |
| 104 | + |
| 105 | +```tsx |
| 106 | +<AdvancedQRCode |
| 107 | + value="https://example.com" |
| 108 | + logo="/path/to/logo.png" |
| 109 | + logoSize={60} |
| 110 | + logoExcavate={true} |
| 111 | +/> |
| 112 | +``` |
| 113 | + |
| 114 | +### WiFi QR Code |
| 115 | + |
| 116 | +```tsx |
| 117 | +import { AdvancedQRCode, QRHelpers } from '@devmehq/react-qr-code' |
| 118 | + |
| 119 | +<AdvancedQRCode |
| 120 | + value={QRHelpers.wifi('NetworkName', 'password123', 'WPA2')} |
| 121 | + theme="professional" |
| 122 | +/> |
| 123 | +``` |
| 124 | + |
| 125 | +### vCard Contact |
| 126 | + |
| 127 | +```tsx |
| 128 | +<AdvancedQRCode |
| 129 | + value={QRHelpers.vcard({ |
| 130 | + firstName: 'John', |
| 131 | + lastName: 'Doe', |
| 132 | + phone: '+1234567890', |
| 133 | + email: 'john@example.com', |
| 134 | + organization: 'ACME Corp' |
| 135 | + })} |
| 136 | + theme="elegant" |
| 137 | +/> |
| 138 | +``` |
| 139 | + |
| 140 | +## 🎭 Preset Themes |
| 141 | + |
| 142 | +The library includes 25+ professionally designed themes: |
| 143 | + |
| 144 | +### Minimal & Clean |
| 145 | +- `minimal` - Clean black and white |
| 146 | +- `monochrome` - Grayscale elegance |
| 147 | +- `elegant` - Sophisticated style |
| 148 | +- `professional` - Business ready |
| 149 | + |
| 150 | +### Colorful & Vibrant |
| 151 | +- `ocean` - Deep blue waves |
| 152 | +- `sunset` - Warm orange/pink |
| 153 | +- `forest` - Natural greens |
| 154 | +- `rainbow` - Full spectrum |
| 155 | +- `aurora` - Northern lights |
| 156 | + |
| 157 | +### Tech & Modern |
| 158 | +- `neon` - Bright cyber green |
| 159 | +- `cyberpunk` - Tech noir |
| 160 | +- `retrowave` - 80s aesthetic |
| 161 | +- `gradient` - Modern gradients |
| 162 | + |
| 163 | +### Nature & Earth |
| 164 | +- `earth` - Natural browns |
| 165 | +- `nature` - Green harmony |
| 166 | +- `ice` - Cool blues |
| 167 | +- `fire` - Hot reds |
| 168 | + |
| 169 | +### Metallic |
| 170 | +- `gold` - Luxurious gold |
| 171 | +- `silver` - Sleek silver |
| 172 | +- `bronze` - Warm bronze |
| 173 | + |
| 174 | +### Special |
| 175 | +- `cosmic` - Space theme |
| 176 | +- `pastel` - Soft colors |
| 177 | +- `dark` - Dark mode |
| 178 | +- `colorful` - Vibrant mix |
| 179 | +- `playful` - Fun and bright |
| 180 | + |
| 181 | +## 🔧 Customization Options |
| 182 | + |
| 183 | +### Eye (Finder Pattern) Shapes |
| 184 | +- `square` - Classic square |
| 185 | +- `circle` - Smooth circles |
| 186 | +- `rounded` - Rounded corners |
| 187 | +- `leaf` - Organic leaf |
| 188 | +- `star` - Star shape |
| 189 | +- `diamond` - Diamond cut |
| 190 | +- `hexagon` - Six-sided |
| 191 | +- `octagon` - Eight-sided |
| 192 | +- `flower` - Floral design |
| 193 | +- `cat` - Cat eyes |
| 194 | + |
| 195 | +### Body (Data Module) Shapes |
| 196 | +- `square` - Traditional pixels |
| 197 | +- `circle` - Circular dots |
| 198 | +- `rounded` - Soft corners |
| 199 | +- `diamond` - Diamond shapes |
| 200 | +- `star` - Star modules |
| 201 | +- `hexagon` - Hexagonal |
| 202 | +- `octagon` - Octagonal |
| 203 | +- `triangle` - Triangular |
| 204 | +- `cross` - Cross pattern |
| 205 | +- `plus` - Plus signs |
| 206 | +- `dots` - Dotted style |
| 207 | +- `lines` - Linear pattern |
| 208 | +- `zigzag` - Zigzag pattern |
| 209 | +- `waves` - Wave pattern |
| 210 | +- `noise` - Noise texture |
| 211 | +- `circuit` - Circuit board |
| 212 | +- `organic` - Organic shapes |
| 213 | +- `fluid` - Fluid design |
| 214 | + |
| 215 | +### Background Patterns |
| 216 | +- `none` - Solid color |
| 217 | +- `dots` - Dot pattern |
| 218 | +- `lines` - Line pattern |
| 219 | +- `grid` - Grid overlay |
| 220 | +- `mesh` - Mesh texture |
| 221 | +- `circuit` - Circuit design |
| 222 | +- `waves` - Wave pattern |
| 223 | +- `noise` - Noise texture |
| 224 | +- `gradient` - Gradient fill |
| 225 | +- `radial` - Radial pattern |
| 226 | +- `hexagon` - Hex pattern |
| 227 | +- `triangle` - Triangle pattern |
| 228 | + |
| 229 | +## 📊 Performance Tips |
| 230 | + |
| 231 | +1. **Use Canvas for Large QR Codes** |
| 232 | + ```tsx |
| 233 | + <ReactQrCode renderAs="canvas" size={512} /> |
| 234 | + ``` |
| 235 | + |
| 236 | +2. **Enable Lazy Loading** |
| 237 | + ```tsx |
| 238 | + <AdvancedQRCode lazy={true} /> |
| 239 | + ``` |
| 240 | + |
| 241 | +3. **Optimize Logo Images** |
| 242 | + - Use WebP or optimized PNG |
| 243 | + - Keep logos under 100KB |
| 244 | + - Use appropriate dimensions |
| 245 | + |
| 246 | +4. **Batch Rendering** |
| 247 | + ```tsx |
| 248 | + // Render multiple QR codes efficiently |
| 249 | + const codes = data.map(item => ( |
| 250 | + <AdvancedQRCode |
| 251 | + key={item.id} |
| 252 | + value={item.value} |
| 253 | + lazy={true} |
| 254 | + /> |
| 255 | + )) |
| 256 | + ``` |
| 257 | + |
| 258 | +## 🧪 Testing Detectability |
| 259 | + |
| 260 | +Use the `qr-test.html` page to: |
| 261 | +1. Test QR code scanning with real devices |
| 262 | +2. Validate contrast ratios |
| 263 | +3. Check error correction levels |
| 264 | +4. Verify logo doesn't interfere |
| 265 | + |
| 266 | +### Recommended Contrast Ratios |
| 267 | +- **Minimum**: 3:1 |
| 268 | +- **Recommended**: 7:1 |
| 269 | +- **Best**: 10:1+ |
| 270 | + |
| 271 | +## 📱 Mobile Optimization |
| 272 | + |
| 273 | +```tsx |
| 274 | +// Responsive QR codes |
| 275 | +<AdvancedQRCode |
| 276 | + value="https://example.com" |
| 277 | + size={window.innerWidth < 768 ? 200 : 300} |
| 278 | +/> |
| 279 | +``` |
| 280 | + |
| 281 | +## 🎯 Common Use Cases |
| 282 | + |
| 283 | +### Event Tickets |
| 284 | +```tsx |
| 285 | +<AdvancedQRCode |
| 286 | + value={`TICKET:${eventId}:${userId}`} |
| 287 | + theme="elegant" |
| 288 | + enableDownload={true} |
| 289 | +/> |
| 290 | +``` |
| 291 | + |
| 292 | +### Product Labels |
| 293 | +```tsx |
| 294 | +<AdvancedQRCode |
| 295 | + value={`PRODUCT:${sku}:${batch}`} |
| 296 | + theme="minimal" |
| 297 | + size={150} |
| 298 | +/> |
| 299 | +``` |
| 300 | + |
| 301 | +### Restaurant Menus |
| 302 | +```tsx |
| 303 | +<AdvancedQRCode |
| 304 | + value="https://restaurant.com/menu" |
| 305 | + theme="professional" |
| 306 | + logo="/restaurant-logo.png" |
| 307 | +/> |
| 308 | +``` |
| 309 | + |
| 310 | +### Social Media |
| 311 | +```tsx |
| 312 | +<AdvancedQRCode |
| 313 | + value={`instagram://user?username=${username}`} |
| 314 | + theme="gradient" |
| 315 | +/> |
| 316 | +``` |
| 317 | + |
| 318 | +## 🔗 Resources |
| 319 | + |
| 320 | +- [GitHub Repository](https://github.com/devmehq/react-qr-code) |
| 321 | +- [NPM Package](https://www.npmjs.com/package/@devmehq/react-qr-code) |
| 322 | +- [Issue Tracker](https://github.com/devmehq/react-qr-code/issues) |
| 323 | +- [Discussions](https://github.com/devmehq/react-qr-code/discussions) |
0 commit comments