@gm-mobile/c-qrcode 3.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ declare module 'weapp-qrcode' {
2
+ interface drawQrCodeProps {
3
+ width: number
4
+ height: number
5
+ canvasId: string
6
+ text: string
7
+ correctLevel: number
8
+ }
9
+
10
+ function drawQrCode(props: drawQrCodeProps): void
11
+
12
+ export default drawQrCode
13
+ }
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@gm-mobile/c-qrcode",
3
+ "version": "3.9.0",
4
+ "description": "> TODO: description",
5
+ "author": "liyatang <liyatang@qq.com>",
6
+ "homepage": "https://github.com/gmfe/gm-mobile#readme",
7
+ "license": "ISC",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "main": "src/index.ts",
12
+ "types": "src/index.ts",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/gmfe/gm-mobile.git"
16
+ },
17
+ "scripts": {
18
+ "test": "echo \"Error: run tests from root\" && exit 1"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/gmfe/gm-mobile/issues"
22
+ },
23
+ "peerDependencies": {
24
+ "qrcode.react": "^1.0.0",
25
+ "weapp-qrcode": "^1.0.0"
26
+ },
27
+ "devDependencies": {
28
+ "@types/qrcode.react": "^1.0.1"
29
+ }
30
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { default as QRCode } from './qrcode'
2
+ export type { QRCodeProps } from './type'
package/src/qrcode.tsx ADDED
@@ -0,0 +1,14 @@
1
+ import React, { FC } from 'react'
2
+ import QRCodeReact from 'qrcode.react'
3
+ import { QRCodeProps } from './type'
4
+
5
+ export const QRCode: FC<QRCodeProps> = (props) => {
6
+ return <QRCodeReact {...props} />
7
+ }
8
+
9
+ QRCode.defaultProps = {
10
+ size: 200,
11
+ level: 'L',
12
+ }
13
+
14
+ export default QRCode
@@ -0,0 +1,38 @@
1
+ import React, { useEffect, useMemo, FC } from 'react'
2
+ import { Canvas } from '@tarojs/components'
3
+ import drawQrCode from 'weapp-qrcode'
4
+ import { LevelMapProps, QRCodeProps } from './type'
5
+
6
+ const levelMap: LevelMapProps = {
7
+ L: 1,
8
+ M: 0,
9
+ Q: 3,
10
+ H: 2,
11
+ }
12
+
13
+ const QRCode: FC<QRCodeProps> = ({ value, size = 200, level = 'L' }) => {
14
+ const id = useMemo(() => Math.random().toString(), [])
15
+
16
+ useEffect(() => {
17
+ drawQrCode({
18
+ width: size,
19
+ height: size,
20
+ canvasId: id,
21
+ text: value,
22
+ correctLevel: levelMap[level],
23
+ })
24
+ }, [])
25
+
26
+ return (
27
+ <Canvas
28
+ // type='2d'
29
+ canvasId={id}
30
+ style={{
31
+ width: `${size}px`,
32
+ height: `${size}px`,
33
+ }}
34
+ />
35
+ )
36
+ }
37
+
38
+ export default QRCode
@@ -0,0 +1,11 @@
1
+ import React from 'react'
2
+ import QRCode from './qrcode'
3
+
4
+ export const normal = () => {
5
+ return <QRCode value='https://www.guanmai.cn' />
6
+ }
7
+
8
+ export default {
9
+ title: 'QRCode/QRCode',
10
+ component: QRCode,
11
+ }
package/src/type.ts ADDED
@@ -0,0 +1,14 @@
1
+ interface QRCodeProps {
2
+ value: string
3
+ level?: 'L' | 'M' | 'Q' | 'H'
4
+ size?: number
5
+ }
6
+
7
+ interface LevelMapProps {
8
+ L: number
9
+ M: number
10
+ Q: number
11
+ H: number
12
+ }
13
+
14
+ export type { QRCodeProps, LevelMapProps }