Giter Club home page Giter Club logo

react-conf-form's Introduction

React Conf Form

集成了antd的配置化表单(思路来源于jsonschema form) 不同的是,简化了配置的书写以及数据的提取

继承了控件Input, Button, Select, Upload等常用控件,可自定义扩展控件

自带校验规则,可扩展校验规则

表单数据自动提取

安装install

yarn add react-conf-form 
or 
npm install react-conf-form

使用usage

import * as React from 'react'
import Form from 'react-conf-form'
import 'react-conf-form/dist/index.css' // import once

export default class FormDemo extends React.Component {
    onSubmit = (data) => { console.log(data) }
    
    render() {
      return (
        <Form
          fields={FIELDS_CONF}
          dataSource={DATA_SOURCE}
          onSubmit={this.onSubmit}
        />
      )
    }
}

参数 props

参数 类型 默认值 描述
spinning? boolean false 是否显示加载状态
validateOnChange? boolean true 是否在onChange自动进行校验
labelDirection? 'vertical' | 'horizontal' horizontal label位置
labelWidth? number 120 label的宽度
fields Array<...> - fields
dataSource? Object - 初始值对象(对应fields的key相应的属性值)
onSubmit? (data) => void - 提交(data为最新的值)
onChange? (key, value, data) => void - 任意表单项修改触发
onReset? () => void - 重置触发
extendFields? Array - 扩展表单控件
extendValidators? Array - 扩展校验规则
onSubmit = (data) => console.log(data)

onChange = (name, value, data) => console.log(name, value, data)

onReset = () => {}

render() {
  const FIELDS = [...]

  return (
    <Form
      spinning={false}
      validateOnChange={true}
      labelDirection="horizontal"
      labelWidth={120}
      fields={FIELDS}
      dataSource={{}}
      onSubmit={this.onSubmit}
      onChange={this.onChange}
      onReset={this.onReset}
      extendFields={[]}
      extendValidators={[]}
    />
  )
}

配置

行 Row

参数 类型 默认值 描述
span? number 8 行内单元格所占珊格,最大24
gutter? number 16(px) 间隔
type? 'FormButtons' | string - 按钮行 / 常规控件行
style? object - 自定义样式
className? string - 自定义样式class
display? string true 是否显示
fields array 单元格配置
align? center | left | right - 适用于按钮行(FormButtons), 按钮的对齐方式
const FIELDS = [
  { // row 
    span: 8,
    gutter: 16,
    display: true,
    type: 'fields',
    fields: [...], // field's cols
  }
]

列 (fields: [field, ...])

参数 类型 默认值 描述
key string(唯一) - field & data对应的key
span? number(1~24) 继承row 栅格宽度
offset? number(1~24) 0 偏移栅格
label string -
type string - input, render, timepicker...
display? boolean true 是否展示
readOnly? boolean false 是否只读
className? string - css class
props 控件内部的参数
className? - css class
rules: Array [] rules for validation
onChange?: (name, value) => void -
beforeChange?: (name, value) => new value - onChange触发前调用,用于覆盖处理onChange的值
onClick?: (data) => any type="button",点击回调
render?: string | Node | (data) => any type="render",render方法/对象
addon?: string | Node | (data) => any 额外的render
...others

react-conf-form's People

Stargazers

BensonChen avatar 曹倩云 avatar Joyer.Z avatar

Watchers

jin avatar Joyer.Z avatar BensonChen avatar

Forkers

472756921 jinjim

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.