@acusti/react-code-input

中文文档
3.11.0发布于 2022/06/23MITTypeScriptCommonJS近 30 天下载 4228

React component for entering and validating numbers, text or password.

原始使用文档
文档目录10 节
  1. Installation
  2. Usage
  3. Numeric input:
  4. Text input:
  5. Password input:
  6. Numeric input with options:
  7. Usage with next.js
  8. Props:
  9. Compatible with
  10. License

react-code-input

React component for entering and validating PIN code.

CircleCI npm version codecov

Live example here

Installation

npm i --save react-code-input

Usage

Numeric input:

Numeric input

...
<ReactCodeInput type='number' fields={6} />
...

Text input:

Text input

...
<ReactCodeInput type='text' fields={6} />
...

Password input:

Password input

...
<ReactCodeInput type='password' fields={6} />
...

Numeric input with options:

Numeric input with options

import { reactCodeInput } from 'CodeInputField.scss'
...
const props = {
  className: reactCodeInput,
  inputStyle: {
    fontFamily: 'monospace',
    margin:  '4px',
    MozAppearance: 'textfield',
    width: '15px',
    borderRadius: '3px',
    fontSize: '14px',
    height: '26px',
    paddingLeft: '7px',
    backgroundColor: 'black',
    color: 'lightskyblue',
    border: '1px solid lightskyblue'
  },
  inputStyleInvalid: {
    fontFamily: 'monospace',
    margin:  '4px',
    MozAppearance: 'textfield',
    width: '15px',
    borderRadius: '3px',
    fontSize: '14px',
    height: '26px',
    paddingLeft: '7px',
    backgroundColor: 'black',
    color: 'red',
    border: '1px solid red'
  }
}
...
<ReactCodeInput type='number' fields={6} {...props}/>
...

Usage with next.js

import dynamic from 'next/dynamic';

const ReactCodeInput = dynamic(import('react-code-input'));
...
<ReactCodeInput type='number' fields={6} {...props}/>
...

Props:

PropertyTypeDescription
typestringOnly types like: text, number, password and tel are accepted.
fieldsnumberAllowed amount of characters to enter.
valuestringSetting the value of code input field.
placeholderstringSetting the placeholder of code input field.
namestringSetting the name of component.
onChangefuncFunction, which is called whenever there is a change of value in the input box.
touchfuncMarks the given fields as "touched" to show errors.
untouchfuncClears the "touched" flag for the given fields.
classNamestringAdd classname to the root element.
styleobjectSetting the styles of container element.
inputStyleobjectSetting the styles of each input field.
inputStyleInvalidobjectSetting the styles of each input field if isValid prop is false.
isValidboolReturns true if an input element contains valid data.
disabledboolWhen present, it specifies that the element should be disabled.
autoFocusboolSetup autofocus on the first input, true by default.
filterKeyCodesarrayFilter characters on key down.
filterCharsarrayFilter characters; default is ['-', '.']
filterCharsIsWhitelistboolfilterChars acts as blacklist if false, whitelist if true; false by default.
patternstringThe pattern prop specifies a regular expression that the element's value is checked against.
inputModestringThe inputMode prop tells the browser on devices with dynamic keyboards which keyboard to display.
autoCompletestringThe autoComplete prop specifies whether or not an input field should have autocomplete enabled.

Compatible with

redux-form from erikras

next.js from zeit

License

MIT

版本与发布记录

@acusti/react-code-input 共发布 3 个版本,首次发布于 2021/10/15;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.11.0latest2022/06/234 年前
3.11.0-beta.22021/10/165 年前
3.11.0-beta2021/10/155 年前

关于 @acusti/react-code-input 的常见问题

@acusti/react-code-input 是什么?

React component for entering and validating numbers, text or password.

如何安装 @acusti/react-code-input?

在项目目录运行 npm install @acusti/react-code-input,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:prop-types(^15)、react(^15.5.4 ||^16.2.0 || ^17.0.0 || ^18.0.0)、react-dom(^15.5.4 ||^16.2.0 || ^17.0.0 || ^18.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@acusti/react-code-input 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@acusti/react-code-input 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@acusti/react-code-input 可以商用吗?

@acusti/react-code-input 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@acusti/react-code-input 的下载量有多少?

根据 npm 官方下载统计,@acusti/react-code-input 在 2026/10/05 – 2026/11/03 这 30 天内被下载 4,228 次,日均约 141 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@acusti/react-code-input 还在维护吗?

最新版本 3.11.0 发布于 2022/06/23(4 年前);至今共发布 3 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/10/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。