npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-vcode

v1.0.11

Published

a react verification code component

Downloads

249

Readme

react-vcode npm codebeat badge npm downloads

一个简单的React验证码组件

示例图

image

image

1. 安装

npm install react-vcode

2. 使用

import Vcode from 'react-vcode';

 <Vcode />
 

3. 自定义参数

可自行设置覆盖原有值

value               // string  受控,不设置的话将随机生成验证码 (支持的值: 普通字符串/网络图片路径/import的本地图片/base64)
onChange            // func    回调,生成新的验证码时触发,将新的验证码字符串返回上级 (如果value字段被传入了图片,将返回null)
onClick             // func    回调,点击组件本身时触发,外部可通过此回调来更新需要传入的验证码 (如果没设置value,点击就会自动重新生成二维码)
length: 4           // number  生成几位验证码(没设置value时有效)
width: 150          // number  容器宽度(px)
height: 40          // number  容器高度(px)
className           // string  自定义容器样式class
style: {            // object  容器默认样式 (注:如果在style中设置width和height,将覆盖上面通过属性设置的width和height)
  position: 'relative',
  backgroundColor: '#fff',
  overflow: 'hidden',
  cursor: 'pointer',
  verticalAlign: 'middle',
  userSelect: 'none',
}
options:{           // 验证码相关自定义参数
  codes: [          // 所有可能出现的字符
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
    'o', 'p', 'q', 'r', 's', 't', 'x', 'u', 'v', 'y', 'z', 'w', 'n',
    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  ],
  fontSizeMin: 22,  // 字体尺寸最小值
  fontSizeMax: 26,  // 字体尺寸最大值
  colors: [         // 字可能的颜色
    '#117cb3',
    '#f47b06',
    '#202890',
    '#db1821',
    '#b812c2',
  ],
  fonts: [          // 可能的字体
    'Times New Roman',
    'Georgia',
    'Serif',
    'sans-serif',
    'arial',
    'tahoma',
    'Hiragino Sans GB',
  ],
  lines: 8,         // 生成多少根干扰线
  lineColors: [     // 线可能的颜色
    '#7999e1',
    '#383838',
    '#ec856d',
    '#008888',
  ],
  lineHeightMin: 1, // 线的粗细最小值
  lineHeightMax: 1, // 线的粗细最大值
  lineWidthMin: 20, // 线的长度最小值
  lineWidthMax: 60, // 线的长度最大值
}

// 例子:

<Vcode
  length={6}
  onChange={(v) => {console.log('当前的验证码值:', v)}}
  options={{ codes: [ 'A', 'B', 'C' ] }}
/>

4. 手动刷新验证码

<Vcode ref={(obj)=>this.vcode = obj} />

this.vcode.onClick(); // 调用内部的onClick方法可刷新验证码

5. 额外说明

  • 之前用过一个验证码插件叫 vcode.js, 不知道作者。 本react-vcode是通过vcode.js的源码进行修改加工,转成了react组件。感谢原作者。

更新日志

1.0.3 - 2019/03/11

  • 去掉UNSAFE_componentWillReceiveProps,使用componentDidUpdate
  • 修复动态改变width、height、style时不刷新的问题