tdesign-react
Version:
TDesign Component for React
95 lines (94 loc) • 3.04 kB
TypeScript
import { QrCode } from '@tdesign/common-js/qrcode/qrcodegen';
import type { ErrorCorrectionLevel, ImageSettings } from '@tdesign/common-js/qrcode/types';
import React from 'react';
export type QRProps = {
/**
* The value to encode into the QR Code. An array of strings can be passed in
* to represent multiple segments to further optimize the QR Code.
*/
value: string;
/**
* The size, in pixels, to render the QR Code.
* @defaultValue 128
*/
size?: number;
/**
* The Error Correction Level to use.
* @see https://www.qrcode.com/en/about/error_correction.html
* @defaultValue L
*/
level?: ErrorCorrectionLevel;
/**
* The background color used to render the QR Code.
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
* @defaultValue #FFFFFF
*/
bgColor?: string;
/**
* The foregtound color used to render the QR Code.
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
* @defaultValue #000000
*/
fgColor?: string;
/**
* The style to apply to the QR Code.
*/
style?: React.CSSProperties;
/**
* Whether or not a margin of 4 modules should be rendered as a part of the
* QR Code.
* @deprecated Use `marginSize` instead.
* @defaultValue false
*/
includeMargin?: boolean;
/**
* The number of _modules_ to use for margin. The QR Code specification
* requires `4`, however you can specify any number. Values will be turned to
* integers with `Math.floor`. Overrides `includeMargin` when both are specified.
* @defaultValue 0
*/
marginSize?: number;
/**
* The settings for the embedded image.
*/
imageSettings?: ImageSettings;
/**
* The title to assign to the QR Code. Used for accessibility reasons.
*/
title?: string;
/**
* The minimum version used when encoding the QR Code. Valid values are 1-40
* with higher values resulting in more complex QR Codes. The optimal
* (lowest) version is determined for the `value` provided, using `minVersion`
* as the lower bound.
* @defaultValue 1
*/
minVersion?: number;
};
export type QRPropsCanvas = QRProps & React.CanvasHTMLAttributes<HTMLCanvasElement>;
export type QRPropsSVG = QRProps & React.SVGAttributes<SVGSVGElement>;
interface Options {
value: string;
level: ErrorCorrectionLevel;
minVersion: number;
includeMargin: boolean;
marginSize?: number;
imageSettings?: ImageSettings;
size: number;
}
export declare const useQRCode: (opt: Options) => {
cells: boolean[][];
margin: number;
numCells: number;
calculatedImageSettings: {
x: number;
y: number;
h: number;
w: number;
excavation: import("@tdesign/common-js/qrcode/types").Excavation | null;
opacity: number;
crossOrigin: import("@tdesign/common-js/qrcode/types").CrossOrigin;
};
qrcode: QrCode;
};
export {};