# @acusti/react-code-input 中文文档

规范地址：https://npmcn.com/package/%40acusti/react-code-input/

版本：3\.11\.0
npm 元数据更新时间：2022-06-22T19:33:11.067Z
中文译文更新时间：2026-11-06T07:03:09.231Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40acusti/react-code-input
原文对照：https://npmcn.com/package/%40acusti/react-code-input/?lang=original
项目主页：https://github.com/40818419/react-code-input#readme
源码仓库：https://github.com/40818419/react-code-input

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：83.9 kB，19 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：1 个
- 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
- 首次发布：2021-10-15T01:02:22.212Z
- 最新版本发布：2022-06-22T19:33:10.983Z
- 近 30 天下载量：4228（2026-10-05 至 2026-11-03，npm 官方下载统计）
- 已发布版本数：3（近 12 个月 0 个）

## 中文简介

用于输入和验证数字、文本或密码的响应组件.

## 安装

```sh
npm install @acusti/react-code-input
```

也可以使用：`pnpm add @acusti/react-code-input`、`yarn add @acusti/react-code-input`、`bun add @acusti/react-code-input`

## README

# 反应-代码输入

用于输入和验证 PIN 代码的响应组件 .

[![CircleCI](https://circleci.com/gh/40818419/react-code-input.svg?style=svg)](https://circleci.com/gh/40818419/react-code-input) [![npm version](https://badge.fury.io/js/react-code-input.svg)](https://badge.fury.io/js/react-code-input) [![codecov](https://codecov.io/gh/40818419/react-code-input/branch/master/graph/badge.svg)](https://codecov.io/gh/40818419/react-code-input)

##### 现场实例 [这里](https://40818419.github.io/react-code-input)

## 安装

`npm i --save react-code-input`

## 使用量

### 数字输入 :

![Numeric input](https://cloud.githubusercontent.com/assets/2235499/21593670/eafea336-d119-11e6-9d4b-738141f24b44.png)

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

### 文本输入 :

![Text input](https://cloud.githubusercontent.com/assets/2235499/21593708/61cebee2-d11a-11e6-9b8d-e99dbeeec23b.png)

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

### 密码输入 :

![Password input](https://cloud.githubusercontent.com/assets/2235499/21593710/65ed7252-d11a-11e6-995f-f0127af5bd9f.png)

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

### 带有选项的数字输入 :

![Numeric input with options](https://cloud.githubusercontent.com/assets/2235499/21593674/f3bb887c-d119-11e6-8b3f-ba478a0f4692.png)

```js
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}/>
...
```

### 使用下一个.js

```js
import dynamic from 'next/dynamic';

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

## 道具 :

| 财产 | 类型 | 说明 |
| :-- | :-- | :-- |
| 类型 | 字符串 | 仅包括以下类型: `text`, (中文(简体) ), `number`, (中文(简体) ), `password` 财务报告和审定财务报表 `tel` 现予接受. |
| 字段 | 编号 | 允许输入字符的数量 . |
| 价值 | 字符串 | 设置代码输入字段的值 . |
| 占位符 | 字符串 | 设置代码输入字段的占位符 . |
| 名称 | 字符串 | 设置组件名称 . |
| 变化 | 乐趣c | 函数,当输入框中值有变化时,该函数就称为函数. |
| 触摸 | 乐趣c | 标记给定的字段为“ 触碰” 以显示出错 . |
| 贱民 | 乐趣c | 为给定的田地清除"触地"旗. |
| 类Name | 字符串 | 在根元素中添加类名 . |
| 样式 | 对象 | 设置容器元素的样式. |
| 输入样式 | 对象 | 设置每个输入字段的样式. |
| 输入样式验证 | 对象 | 设置每个输入字段的样式,如果 `isValid` 道具为 `false`。 。 。 . |
| 是瓦利德语 | 嘘 | 如果输入元素包含有效数据,则返回真实性. |
| 已禁用 | 嘘 | 当存在时,它规定该元素应当被禁用. |
| 自动聚焦 | 嘘 | 设置自动聚焦于第一个输入, `true` 默认. |
| 过滤密钥编码 | 数组 | 向下过滤密钥上的字符 . |
| 过滤器 | 数组 | 过滤字符; 默认为 \['-','.\] |
| 过滤器Chars Is 白名单 | 嘘 | `filterChars` 如果 `false`白名单,如果 `true`· ; `false` 默认. |
| 模式 | 字符串 | 图案道克指定一个正则表达式,即:  元素的值被选中. |
| 输入模式 | 字符串 | 输入Mode prof在带有动态键盘的设备上告诉浏览器要显示的键盘. |
| 自动完成 | 字符串 | 自动补全道具指定一个输入字段是否应该启用自动补全 . |

## 兼容

[`redux-form`](https://github.com/erikras/redux-form) 从 [埃里克拉斯语name](https://github.com/erikras)

[`next.js`](https://github.com/zeit/next.js) 从 [齐特](https://github.com/zeit)

## 许可证

麻省理工学院

## 常见问题

### @acusti/react-code-input 是什么？

用于输入和验证数字、文本或密码的响应组件\.

### 如何安装 @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 和提交记录判断。

