2.0.4 • Published 2 years ago

qr-scanner-react v2.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

qr-scanner-react

Install

npm install --save qr-scanner-react

Usage

Without props

<QrScanner />

With props

<QrScanner {...props} />

Props

Type

{
  viewFinderConfig: ViewFinderConfig | undefined;
  onResult: ResultHandler | undefined;
  onError: ErrorHandler | undefined;
  styles: QrScannerStyles | undefined;
  scanConfig: ScanConfig | undefined;
  'full-width': boolean | undefined;
}
PropDescription
viewFinderConfigConfigure the appearance of the viewFinder.
onResultCalled when a QR code is read.
onErrorCalled when an error occurred or a QR Code cannot be read.
stylesConfigure the CSS of the rendered elements.
scanConfigConfigure the scanning behavior.
full-widthA boolean describing whether the camera should be cropped to square, or not. By default, full-width is false, and so it is cropped to a square.

viewFinderConfig

An object used to configure the appearance of the view finder.

Type

{
  visible: boolean | undefined;
  outerColor: string | undefined;
  strokeWidth: string | undefined;
  strokeColor: string | undefined;
  radius: string | undefined;
  strokeLength: string | undefined;
  custom: React.ReactElement<undefined> | undefined;
}

Explanation

AttributeDescriptionDefaultExamples
visibleWhether the view finder should be visible.falsevisible : true
outerColorBackground color outside the scanning region.#00000000outerColor: "black" outerColor: "#FFFFFFAA",
strokeWidthWidth of the lines constituting the view finder.3pxstrokeWidth: "10px" strokeWidth: "1.2em"
strokeColorColor of the lines constituting the view finder.#000000strokeColor: "black" strokeColor: "#FFFFFFAA"
radiusRadius of the corners of the view finder.5pxradius: "10px" radius: "1.2em" radius: "15%"
strokeLengthLength of the lines constituting the view finder.40pxstrokeLength: "100px" strokeLength: "1.2em" strokeLength: "55%"
customInstead of using the built-in view finder with the customizations, you can provide your own, in which case, your view finder will be used.undefinedcustom : <CustomViewFinder />

onResult

A function called when a QR code is read.

Type

(result: ScanResult) => void

ScanResult

{
  data: string;
  cornerPoints: ({ x: number; y: number; }[]);
}
AttributeDescription
dataThe data read from the QR code.
cornerPointsThe location of the corners of the QR code scanned.

Default

(result) => {
  console.log(result);
};

onError

A function called when an error occurred or a QR Code cannot be read.

Type

(error: Error | string) => void;

Default

(error) => {
  console.log(error);
};

styles

An object used to configure the CSS of the rendered elements.

Type

{
  video: CSSProperties | undefined;
  videoContainer: CSSProperties | undefined;
  container: CSSProperties | undefined;
}

scanConfig

An object used to configure the scanning behavior.

Type

{
  qrColor: 'dark' | 'light' | 'both' | undefined;
  maxScansPerSecond: number | undefined;
  cameraPreference: 'environment' | 'user' | DeviceId: string | undefined;
}

Explanation

AttributeDescriptionDefault
qrColorThe colors of the QR codes that should be scanned."both"
maxScansPerSecondLimit the number of scans made a second.5
cameraPreferenceWhich camera should be used, if there are multiple camera options."environment"

License

MIT © jakub-ucinski

2.0.4

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago