Add packages/react-captcha
This commit is contained in:
parent
a59b9032a9
commit
e726b1f32d
@ -21,7 +21,8 @@
|
||||
"@rondo.dev/db": "file:packages/db",
|
||||
"@rondo.dev/db-typeorm": "file:packages/db-typeorm",
|
||||
"@rondo.dev/middleware": "file:packages/middleware",
|
||||
"@rondo.dev/captcha": "file:packages/captcha"
|
||||
"@rondo.dev/captcha": "file:packages/captcha",
|
||||
"@rondo.dev/react-captcha": "file:packages/react-captcha"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bcrypt": "^3.0.0",
|
||||
@ -127,4 +128,4 @@
|
||||
"watchify": "^3.11.1"
|
||||
},
|
||||
"name": "node"
|
||||
}
|
||||
}
|
||||
16
packages/react-captcha/jest.config.js
Normal file
16
packages/react-captcha/jest.config.js
Normal file
@ -0,0 +1,16 @@
|
||||
module.exports = {
|
||||
roots: [
|
||||
'<rootDir>/src',
|
||||
],
|
||||
transform: {
|
||||
'^.+\\.tsx?$': 'ts-jest',
|
||||
},
|
||||
testRegex: '(/__tests__/.*|\\.(test|spec))\\.tsx?$',
|
||||
moduleFileExtensions: [
|
||||
'ts',
|
||||
'tsx',
|
||||
'js',
|
||||
'jsx',
|
||||
],
|
||||
setupFiles: ['<rootDir>/jest.setup.js'],
|
||||
}
|
||||
4
packages/react-captcha/jest.setup.js
Normal file
4
packages/react-captcha/jest.setup.js
Normal file
@ -0,0 +1,4 @@
|
||||
if (!process.env.LOG) {
|
||||
process.env.LOG = 'sql:warn'
|
||||
}
|
||||
process.chdir(__dirname)
|
||||
15
packages/react-captcha/package.json
Normal file
15
packages/react-captcha/package.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "@rondo.dev/react-captcha",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"test": "jest",
|
||||
"lint": "tslint --project .",
|
||||
"compile": "tsc",
|
||||
"clean": "rm -rf lib/"
|
||||
},
|
||||
"dependencies": {},
|
||||
"main": "lib/index.js",
|
||||
"module": "esm/index.js",
|
||||
"types": "lib/index.d.ts"
|
||||
}
|
||||
67
packages/react-captcha/src/Captcha.tsx
Normal file
67
packages/react-captcha/src/Captcha.tsx
Normal file
@ -0,0 +1,67 @@
|
||||
import React from 'react'
|
||||
|
||||
export interface CaptchaProps {
|
||||
onChange: (value: React.ChangeEvent<HTMLInputElement>) => void
|
||||
value: string
|
||||
audioUrl?: string
|
||||
imageUrl: string
|
||||
}
|
||||
|
||||
export type CaptchaType = 'image' | 'audio'
|
||||
|
||||
export interface CaptchaState {
|
||||
type: CaptchaType
|
||||
attempt: number
|
||||
}
|
||||
|
||||
export class Captcha extends React.PureComponent<CaptchaProps, CaptchaState> {
|
||||
state: CaptchaState = {
|
||||
type: 'image',
|
||||
attempt: 0,
|
||||
}
|
||||
changeType(type: CaptchaType) {
|
||||
this.setState({ type })
|
||||
}
|
||||
changeToAudio = () => {
|
||||
this.changeType('audio')
|
||||
}
|
||||
changeToImage = () => {
|
||||
this.changeType('image')
|
||||
}
|
||||
refresh = () => {
|
||||
this.setState({ attempt: this.state.attempt + 1 })
|
||||
}
|
||||
render() {
|
||||
const { onChange, value, imageUrl, audioUrl } = this.props
|
||||
const { attempt, type } = this.state
|
||||
|
||||
return (
|
||||
<div>
|
||||
{type === 'image' && (
|
||||
<>
|
||||
<img key={attempt} src={imageUrl} />
|
||||
<a onClick={this.refresh}>
|
||||
Refresh
|
||||
</a>
|
||||
<a onClick={this.changeToAudio}>
|
||||
Click here for image version
|
||||
</a>
|
||||
</>
|
||||
)}
|
||||
{type === 'audio' && (
|
||||
<>
|
||||
<audio key={attempt} controls src={audioUrl} />
|
||||
<a onClick={this.refresh}>
|
||||
Refresh
|
||||
</a>
|
||||
<a onClick={this.changeToImage}>
|
||||
Click here for audio version
|
||||
</a>
|
||||
</>
|
||||
)}
|
||||
k
|
||||
<input value={value} onChange={onChange} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
0
packages/react-captcha/src/index.ts
Normal file
0
packages/react-captcha/src/index.ts
Normal file
8
packages/react-captcha/tsconfig.esm.json
Normal file
8
packages/react-captcha/tsconfig.esm.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "esm"
|
||||
},
|
||||
"references": [
|
||||
]
|
||||
}
|
||||
9
packages/react-captcha/tsconfig.json
Normal file
9
packages/react-captcha/tsconfig.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../tsconfig.common.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "lib",
|
||||
"rootDir": "src"
|
||||
},
|
||||
"references": [
|
||||
]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user