Giter Site home page Giter Site logo

bunlong / next-qrcode Goto Github PK

View Code? Open in Web Editor NEW
146.0 3.0 15.0 1.99 MB

React hooks for generating QRCode for your next React apps.

Home Page: https://next-qrcode.js.org

License: MIT License

JavaScript 38.97% TypeScript 45.08% CSS 2.80% HTML 13.15%
react qrcode react-hooks hooks typescript react-components javascript qrcode-generator japanese-font japanese chinese chinese-fonts japanese-fonts next-qrcode nextjs nextjs-plugin react-qrcode

next-qrcode's Introduction

next-qrcode

React hooks for generating QR code for your next React apps.

downloads downloads

NPM npm bundle size JavaScript Style Guide

๐ŸŽ Features

  • Render Canvas, SVG and Image
  • Support Numeric, Alphanumeric, Kanji and Byte mode
  • Support Japanese, Chinese, Greek and Cyrillic characters
  • Support multibyte characters (like emojis smile)

Live Demo

๐Ÿ”ง Install

next-qrcode is available on npm. It can be installed with the following command:

npm install next-qrcode --save

next-qrcode is available on yarn as well. It can be installed with the following command:

yarn add next-qrcode --save

๐Ÿ’ก Canvas

Usage

import React from 'react';
import { useQRCode } from 'next-qrcode';

function App() {
  const { Canvas } = useQRCode();

  return (
    <Canvas
      text={'https://github.com/bunlong/next-qrcode'}
      options={{
        errorCorrectionLevel: 'M',
        margin: 3,
        scale: 4,
        width: 200,
        color: {
          dark: '#010599FF',
          light: '#FFBF60FF',
        },
      }}
    />
  );
}

export default App;

Canvas props

Prop Type Require Description
text string โœ”๏ธ Text/URL to encode.
options options โŒ QR code options.
logo logo โŒ QR code logo.

options

Prop Type Default Require Description
errorCorrectionLevel string M โŒ Correction level. Possible values are low, medium, quartile, high or L, M, Q, H.
margin number 4 โŒ Define how much wide the quiet zone should be.
scale number 4 โŒ Scale factor. A value of 1 means 1px per modules (black dots).
width number 4 โŒ Forces a specific width for the output image. If width is too small to contain the qr symbol, this option will be ignored. Takes precedence over scale.
color.dark string #000000ff โŒ Color of dark module. Value must be in hex format (RGBA). Note: dark color should always be darker than color.light.
color.light string #ffffffff โŒ Color of light module. Value must be in hex format (RGBA).

logo

Prop Type Require Description
src string โœ”๏ธ The path to the image.
options options โŒ Logo options.

options

Prop Type Default Require Description
width number โŒ Logo dimension.
x number โŒ If none or undefined, will center.
y number โŒ If none or undefined, will center.

๐Ÿ’ก SVG

Usage

import React from 'react';
import { useQRCode } from 'next-qrcode';

function App() {
  const { SVG } = useQRCode();

  return (
    <SVG
      text={'https://github.com/bunlong/next-qrcode'}
      options={{
        margin: 2,
        width: 200,
        color: {
          dark: '#010599FF',
          light: '#FFBF60FF',
        },
      }}
    />
  );
}

export default App;

SVG props

Prop Type Require Description
text string โœ”๏ธ Text/URL to encode.
options options โŒ QR code options.

options

Prop Type Default Require Description
margin number 4 โŒ Define how much wide the quiet zone should be.
width number 4 โŒ Forces a specific width for the output image. If width is too small to contain the qr symbol, this option will be ignored. Takes precedence over scale.
color.dark string #000000ff โŒ Color of dark module. Value must be in hex format (RGBA). Note: dark color should always be darker than color.light.
color.light string #ffffffff โŒ Color of light module. Value must be in hex format (RGBA).

๐Ÿ’ก Image

Usage

import React from 'react';
import { useQRCode } from 'next-qrcode';

function App() {
  const { Image } = useQRCode();

  return (
    <Image
      text={'https://github.com/bunlong/next-qrcode'}
      options={{
        type: 'image/jpeg',
        quality: 0.3,
        errorCorrectionLevel: 'M',
        margin: 3,
        scale: 4,
        width: 200,
        color: {
          dark: '#010599FF',
          light: '#FFBF60FF',
        },
      }}
    />
  );
}

export default App;

Image props

Prop Type Require Description
text string โœ”๏ธ Text/URL to encode.
options object โŒ QR code options

options

Prop Type Default Require Description
type string (image/png, image/jpeg, image/webp) image/png โŒ Image format.
quality number 0.92 โŒ A Number between 0 and 1 indicating image quality if the type is image/jpeg or image/webp.
errorCorrectionLevel string M โŒ Correction level. Possible values are low, medium, quartile, high or L, M, Q, H.
margin number 4 โŒ Define how much wide the quiet zone should be.
scale number 4 โŒ Scale factor. A value of 1 means 1px per modules (black dots).
width number 4 โŒ Forces a specific width for the output image. If width is too small to contain the qr symbol, this option will be ignored. Takes precedence over scale.
color.dark string #000000ff โŒ Color of dark module. Value must be in hex format (RGBA). Note: dark color should always be darker than color.light.
color.light string #ffffffff โŒ Color of light module. Value must be in hex format (RGBA).

๐Ÿ“œ Changelog

Latest version 2.5.1 (2023-08-01):

  • Upgrade QRCode options API

Details changes for each release are documented in the CHANGELOG.md.

โ— Issues

If you think any of the next-qrcode can be improved, please do open a PR with any updates and submit any issues. Also, I will continue to improve this, so you might want to watch/star this repository to revisit.

๐ŸŒŸ Contribution

We'd love to have your helping hand on contributions to next-qrcode by forking and sending a pull request!

Your contributions are heartily โ™ก welcome, recognized and appreciated. (โœฟโ— โ€ฟโ— )

How to contribute:

  • Open pull request with improvements
  • Discuss ideas in issues
  • Spread the word
  • Reach out with any feedback

๐Ÿ† Contributors

Bunlong
Bunlong
Michael Desa
Michael Desa
Jared Scheib
Jared Scheib
Mehrdad MotaghiFar
Mehrdad MotaghiFar

๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘ฆ Advertisement

You maybe interested.

  • React Patterns โ€“ React patterns & techniques to use in development for React Developer.
  • React Papaparse โ€“ The fastest in-browser CSV (or delimited text) parser for React.
  • Next Share โ€“ Social media share buttons for your next React apps.
  • Next Time Ago โ€“ A lightweight tiny time-ago component for your next React apps.

โš–๏ธ License

The MIT License License: MIT

next-qrcode's People

Contributors

bunlong avatar jaredscheib avatar mehrdadx10 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

next-qrcode's Issues

Github and NPM README mismatch

On github README the installation goes as, e.g., yarn add next-qrcode but on NPM is like yarn add react-qrcodes.

Why is that and which one should be used?

Possible to provide options that are not relevant for the component type

The QR code can be rendered in three different types, i.e. Canvas, SVG and Image. All three types have different available options prop parameters (as shown in the readme/documentation). However, they are all linked to the QRCodeOptions type in code which contains all props.

Issues:

  • It is possible to provide non relevant props when generating a qr.
  • Will need to check documentation which props are relevant for a given type.

useQRCode always returns false

  import { useQRCode } from 'react-qrcodes';

  const qrCode = useQRCode<HTMLImageElement>({
    text: 'https://google.com',
    options: {
      type: 'image/jpeg',
      quality: 0.3,
      level: 'M',
      margin: 3,
      scale: 4,
      width: 200,
      color: {
        dark: '#010599FF',
        light: '#FFBF60FF',
      },
    },
  });

  console.log(qrCode);

--> qrCode is always false, never an array as docs would imply is supposed to be

Micro QR?

Is there a way to make Micro QR codes with this?

On download image QR code, "Unknown" file name and no file extension

Using the Image Render, when we right click on the image to save as, the file appears has an "Unknown" file name without file extension and no file Icon, only a blank Icon.
On MacOS, this file can be open with the built in Preview.app OS App, even with the preview on Finder.
On Windows, only open after choosing an App.

TypeError: Cannot read properties of undefined (reading 'getContext')

I have the following code:

const { Image } =  useQRCode()
  return (
    <>
    <Image text={link} />
    <p/>
    <a href={link} target="_new">{link}</a>
    </>
  )

which breaks with the following errors:

Uncaught TypeError: Cannot read properties of undefined (reading 'getContext')
at renderCanvas (browser.js?b4d5:27:1)
at eval (next-qrcode.es.js?5558:1:168)
at invokePassiveEffectCreate (react-dom.development.js?ac89:23487:1)
at HTMLUnknownElement.callCallback (react-dom.development.js?ac89:3945:1)
at Object.invokeGuardedCallbackDev (react-dom.development.js?ac89:3994:1)
at invokeGuardedCallback (react-dom.development.js?ac89:4056:1)
at flushPassiveEffectsImpl (react-dom.development.js?ac89:23574:1)
at unstable_runWithPriority (scheduler.development.js?bcd2:468:1)
at runWithPriority$1 (react-dom.development.js?ac89:11276:1)
at flushPassiveEffects (react-dom.development.js?ac89:23447:1)
at eval (react-dom.development.js?ac89:23324:1)
at workLoop (scheduler.development.js?bcd2:417:1)
at flushWork (scheduler.development.js?bcd2:390:1)
at MessagePort.performWorkUntilDeadline (scheduler.development.js?bcd2:157:1)

The above error occurred in the component:

at n (webpack-internal:///./node_modules/next-qrcode/dist/next-qrcode.es.js:7:138)
at eval (webpack-internal:///./pages/index.js:52:62)
at __WEBPACK_DEFAULT_EXPORT__ (webpack-internal:///./pages/_app.js:40:27)
at ErrorBoundary (webpack-internal:///./node_modules/next/dist/compiled/@next/react-dev-overlay/client.js:8:20638)
at ReactDevOverlay (webpack-internal:///./node_modules/next/dist/compiled/@next/react-dev-overlay/client.js:8:23179)
at Container (webpack-internal:///./node_modules/next/dist/client/index.js:323:9)
at AppContainer (webpack-internal:///./node_modules/next/dist/client/index.js:820:26)
at Root (webpack-internal:///./node_modules/next/dist/client/index.js:944:27)

React will try to recreate this component tree from scratch using the error boundary you provided, ErrorBoundary.

Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
at eval (webpack-internal:///./pages/index.js:52:62)
at WEBPACK_DEFAULT_EXPORT (webpack-internal:///./pages/_app.js:40:27)

if I remove the image component from the page, the value displayed in the link is http://localhost:3000/auth?id=u5-btJ73LdoDIqwaAAAn&userId=288100 and if I hard code that value in the image:

    <Image text={'http://localhost:3000/auth?id=u5-btJ73LdoDIqwaAAAn&userId=288100'} />

the QR code shows up correctly. what am I doing wrong here?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.