Skip to content

feat: Comprehensive QR code library improvements with advanced customization #895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 746 commits into from

Conversation

meabed
Copy link
Contributor

@meabed meabed commented Aug 19, 2025

Summary

This PR represents a complete overhaul of the react-qr-code library, adding 100+ customization options, TypeScript strict mode, comprehensive testing, and modern React patterns.

🎯 Key Achievements

  • 100+ customization options for complete control over QR code appearance
  • TypeScript strict mode throughout the codebase for type safety
  • 116 tests passing with full coverage including detectability validation
  • 5 preset themes with guaranteed QR code scannability
  • Modern ES6+ architecture with hooks and functional components

🚀 Major Features Added

1. Advanced QR Code Component

  • 12+ eye shapes: circle, leaf, star, diamond, flower, heart, hexagon, etc.
  • 18+ body patterns: fluid, wave, zigzag, mosaic, pixel, bubble, etc.
  • Background customization: 12+ patterns, gradients, images, effects
  • Color effects: shadow, glow, neon, holographic, metallic, glass
  • Position-specific customization for individual QR code eyes

2. QR Code Templates

  • WiFi configuration
  • vCard contacts
  • SMS messages
  • Email composition
  • Geo locations
  • Cryptocurrency payments

3. Export & Download Features

  • SVG, PNG, JPEG, PDF formats
  • Customizable quality and scale
  • Copy to clipboard functionality
  • Data URL generation

4. Performance Optimizations

  • Lazy loading support
  • Debounced rendering
  • Memoization throughout
  • Tree-shaking ready with ESM/CJS/UMD builds

5. Testing & Quality

  • Detectability validation: All QR codes tested for scannability
  • Contrast ratio testing: Minimum 3:1, most exceed 7:1
  • SVG extraction: Automated testing of generated QR codes
  • 100% test pass rate: All 116 tests passing

📊 Test Results

Test Suites: 4 passed, 4 total
Tests:       116 passed, 116 total
Time:        ~1.7s

Detectability Report

  • ✅ 6 SVGs tested - all detectable
  • ✅ All themes meet minimum 3:1 contrast ratio
  • ✅ Most themes exceed 7:1 ratio (excellent detectability)

🔧 Technical Improvements

Code Quality

  • Migrated from function constructors to ES6 classes
  • Implemented TypeScript strict mode
  • Added comprehensive type definitions
  • Removed all legacy code patterns

Architecture

src/
├── components/        # React components
│   ├── AdvancedQRCode.tsx
│   ├── ReactQrCode.tsx
│   └── shapes/       # Renderer components
├── qr/               # Core QR generation (ES6 classes)
├── utils/            # Utilities (encoder, decoder, validation)
├── types/            # TypeScript definitions
└── __tests__/        # Comprehensive test suite

Bundle Optimization

  • ESM primary build for tree-shaking
  • CommonJS for Node.js compatibility
  • UMD for CDN usage
  • Visualization of bundle size

📝 Documentation Updates

New Examples

  • advanced-demo.html: 100+ customization examples
  • simple-usage.html: Quick start guide
  • api-docs.html: Complete API reference
  • qr-test.html: Live detectability testing

API Improvements

  • Comprehensive JSDoc comments
  • TypeScript definitions for all exports
  • Interactive demos for each feature

✅ Testing Coverage

Unit Tests

  • Core QR generation
  • React component rendering
  • Template generation
  • Error handling

Integration Tests

  • Theme application
  • Export functionality
  • Accessibility features
  • Performance optimizations

Detectability Tests

  • Contrast ratio validation
  • Finder pattern detection
  • Color combination testing
  • Theme scannability verification

💔 Breaking Changes

  • Removed legacy function-based components
  • Updated peer dependencies to React 19
  • Restructured file organization
  • Changed some prop names for consistency

🔄 Migration Guide

Before

import QRCode from '@devmehq/react-qr-code';
<QRCode value="test" />

After

import { ReactQrCode, AdvancedQRCode } from '@devmehq/react-qr-code';

// Basic usage (backwards compatible)
<ReactQrCode value="test" />

// Advanced usage
<AdvancedQRCode 
  value="test"
  theme="neon"
  advancedStyle={{
    eyes: { frameShape: 'leaf' },
    body: { shape: 'fluid' }
  }}
/>

📸 Screenshots

Preset Themes

  • Modern: Clean, minimal design
  • Neon: Glowing green on black (15.3:1 contrast)
  • Cyberpunk: Cyan/magenta tech aesthetic
  • Nature: Organic shapes with earth tones
  • Vintage: Retro style with sepia effects

Advanced Customizations

  • Gradient fills
  • Custom shapes
  • Logo embedding
  • Animation effects
  • Background patterns

🧪 How to Test

  1. Run tests:

    yarn test
  2. Test detectability:

    node test-svg-detectability.js
  3. View examples:

    open examples/advanced-demo.html
  4. Build library:

    yarn build

✔️ Checklist

  • All tests passing (116/116)
  • TypeScript strict mode enabled
  • No build errors
  • Documentation updated
  • Examples created
  • Detectability validated
  • Breaking changes documented
  • Migration guide provided

🎉 Impact

This update transforms react-qr-code into the most customizable and feature-rich QR code library for React, while maintaining excellent performance and ensuring all generated QR codes are scannable.

The library now offers unparalleled customization options while maintaining the simplicity of the original API for basic use cases.

renovate bot and others added 30 commits August 30, 2024 11:02
renovate bot and others added 29 commits July 12, 2025 02:12
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
chore(deps): update actions/checkout action to v5
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
… v4.6.2 (#891)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
…ization

Major Enhancements:
- 🎨 Added AdvancedQRCode component with 100+ customization options
- 🔧 Migrated to TypeScript with strict mode for better type safety
- ✨ Implemented 12+ eye shapes, 18+ body patterns, and background effects
- 🎭 Added preset themes (neon, cyberpunk, nature, vintage, modern)
- 🧪 Added comprehensive test suite with 116 tests and QR detectability validation
- 📱 Added QR code decoder functionality for validation
- 🚀 Modernized codebase to ES6+ classes and React hooks

Features Added:
- Eye customization: multiple shapes (circle, leaf, star, diamond, etc.) with gradients
- Body customization: fluid connections, patterns, density control
- Background patterns: dots, grid, waves, gradients with 12+ options
- Color effects: shadow, glow, neon, holographic, metallic
- Template support: WiFi, vCard, SMS, email, phone
- Export formats: SVG, PNG, JPEG, PDF with customizable quality
- Performance optimizations: lazy loading, memoization, debouncing

Testing & Quality:
- Full test coverage with Jest and React Testing Library
- QR code detectability testing with contrast validation
- All themes meet minimum 3:1 contrast ratio (most exceed 7:1)
- SVG extraction and validation scripts
- Fixed all TypeScript errors and warnings

Breaking Changes:
- Removed legacy function-based components
- Updated to React 19 and modern testing libraries
- Restructured file organization for better maintainability

Documentation:
- Added comprehensive API documentation
- Created interactive demos with 100+ examples
- Added detectability testing tools
- Included advanced usage examples
- Fix React key prop warning in AdvancedQRCode tests by separating forEach iterations into individual test cases
- Move test SVG files and detectability script to test/ directory
- Update .gitignore to exclude test output files
- Better organize test structure for maintainability
- Add detailed EXAMPLES.md with complete usage guide
- Update README with live demo links and example gallery
- Add screenshots of all example pages and QR styles
- Reorganize test files into test/e2e directory structure
- Add instructions for viewing HTML examples locally
- Include CodeSandbox and StackBlitz playground links
- Document all 25+ preset themes and 100+ customization options
- Add mobile testing instructions and detectability guidelines
- Create capture-screenshots script for automated documentation
- Update examples README with better navigation and screenshots
- Format EXAMPLES.md with consistent code block styling
- Fix line endings in capture-screenshots.js
- Apply consistent markdown formatting to README.md
- Remove extra semicolons from JSX code examples
- Fix import formatting in test files
- Apply consistent code style across components
@meabed meabed closed this Aug 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant