@cat-react/form

中文文档
0.1.2发布于 2018/01/30MITESM + CJS近 30 天下载 5577

一个简单而强大的库, 帮助创建有效的反应形式 .

中文使用文档
文档目录6 节
  1. 安装
  2. 开始
  3. 示例自定义文本输入
  4. 捐款
  5. 如何建立一个发布
  6. 许可证

cat-react

@ cat- react / 窗体 Build Status codecov npm version

一个简单而强大的库, 帮助创建有效的反应形式 。 这个项目的灵感来自 窗体反应。 。 。 .

安装

npm package

  • 安装依赖 @cat-react/form
    (如: yarn add @cat-react/form 或者说 npm install @cat-react/form --save(中文(简体) )
  • 导入组件为 import {Form, Input} from '@cat-react/form';

开始

API 文档实例

您是否在寻找一种简单的方法, 用 React 创建有效的表格 ?

祝贺你! 你的搜索结束了,因为 @cat-react/form 提供了一种简单的方式来创建前端或后端验证的表格。 验证既可以是同步处理,也可以是同步处理,形式状态正在被实时刷新.

看看这个 实例 找出如何创造你的欲望.

<Form>
    <MyInput name="email"
             validations={{
                 isEmail: true,
                 isRequired: true
             }}/>
    <MyInput name="email_confirm"
             validations={{
                 isRequired: true,
                 equalsField: 'email'
             }}
             messages={{
                 isRequired: 'Please confirm your email address.',
                 equalsField: 'The email addresses do not match each other.'
             }}/>
</Form>

示例自定义文本输入

您可以在此看到一个自定义文本输入的例子, 显示您如何执行自己的输入 :

import React from 'react';
import {Input} from '@cat-react/form'

@Input
export default class BasicInput extends React.Component {
    onChange(event) {
        this.props.setValue(event.target.value);
    }

    getClassName() {
        let className = 'form-control';
        if (!this.props.isPristine()) {
            if (this.props.isValid()) {
                const isWarning = this.props.getMessages().length > 0;
                if (isWarning) {
                    className += ' warning';
                }
            } else {
                className += ' error';
            }
        }
        return className;
    }

    renderMessages() {
        let messages = [];
        if (!this.props.isPristine()) {
            messages = this.props.getMessages();
        }

        if (!messages || messages.length <= 0) {
            return null;
        }

        let className = 'errorText';
        if (this.props.isValid()) {
            className = 'warningText';
        }

        return <ul className={className}>{messages.map((message, i) => <li key={i}>{message}</li>)}</ul>;
    }

    render() {
        return (
            <div className="form-group">
                <label htmlFor={this.props.name}>{this.props.label} {this.props.isRequired() ? '*' : null}</label>
                <input type={this.props.type}
                       className={this.getClassName()}
                       id={this.props.name}
                       aria-describedby={this.props.name}
                       placeholder={this.props.placeholder}
                       value={this.props.getValue()}
                       onChange={this.onChange.bind(this)}
                       onBlur={this.props.touch}/>
                {this.renderMessages()}
            </div>
        );
    }
}

说明数字 : 你需要那个 bail-plugin-变形器 要使用的插件 @Input 装饰师. 如果您不想或无法将此插件添加到您的 Webpack 配置中, 您需要将 HOC 用作一个 函数( 如 connect() (原始内容存档于2018-10-12). HOC of Redux.

示例 export default Input(BasicInput)

见 Babel 文档 详细指南 如何在应用程序中添加装饰器.

捐款

该项目至少需要最新稳定的节点和npm版本. 你还需要在全球安装纱线.

两个简单的步骤 让你的本地机器运行的东西:

  • 叉出还原
  • 执行 yarn

您可以以 yarn run examples 和试验 yarn test。 。 。 .

如何建立一个发布

  • 更新 CHANGELOG.md 与新版本相关的所有更改
  • 更新 package.json
  • 推动更改
  • 本地创建项目 npm run build
  • cd 输入 dist 文件夹并运行 npm publish --access public
  • 起草新版本 Github 与《京都议定书》 CHANGELOG.md 文件

许可证

MIT 许可证

版权(c)2018年 催化器 GmbH

版本与发布记录

@cat-react/form 共发布 6 个版本,首次发布于 2017/09/12;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.1.2latest2018/01/308 年前
0.1.12017/11/228 年前
0.1.02017/10/039 年前
0.0.32017/09/189 年前
0.0.22017/09/189 年前
0.0.12017/09/129 年前

关于 @cat-react/form 的常见问题

@cat-react/form 是什么?

一个简单而强大的库, 帮助创建有效的反应形式 .

如何安装 @cat-react/form?

在项目目录运行 npm install @cat-react/form,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>= 15.0.0 < 17.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@cat-react/form 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/cat-react__form 是否存在。

@cat-react/form 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@cat-react/form 可以商用吗?

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

@cat-react/form 的下载量有多少?

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

@cat-react/form 还在维护吗?

最新版本 0.1.2 发布于 2018/01/30(8 年前);至今共发布 6 个版本,其中过去 12 个月发布了 0 个;首次发布于 2017/09/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。