Skip to content
This repository has been archived by the owner on Oct 20, 2021. It is now read-only.

Commit

Permalink
feat(Form): add width props
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimi-Gao committed May 11, 2018
1 parent 0325012 commit 265d3ea
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
15 changes: 11 additions & 4 deletions src/components/Form/Form/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import update from 'react-update'
import classnames from 'classnames'
import cx from 'classnames'
import invariant from 'invariant'
import xhr from '../../xhr'
import './index.less'
Expand Down Expand Up @@ -149,14 +149,18 @@ class Form extends Component {

render () {
const {
children, className, data, defaultData, onChange, onSubmit, onSuccess, size, rules, labelWidth, ...other
children, className, data, defaultData, onChange, onSubmit, onSuccess, size, rules, labelWidth, width, ...other
} = this.props

const classNames = classnames(
const classNames = cx(
'cmui-form',
{[`cmui-form-${size}`]: size}
)

if (width) {
other.style = Object.assign(other.style || {}, { width })
}

return (
<form
onSubmit={::this.handleSubmit}
Expand Down Expand Up @@ -194,7 +198,10 @@ Form.propTypes = {
// 表单验证规则,需要验证的 key 与 data 对象一一对应
rules: PropTypes.object,

// 表单 label 宽度,如果不需要 label,设置为 0 即可
// 表单的宽度大小,单位为px
width: PropTypes.number,

// 表单 label 宽度,如果不需要 label,设置为`0`即可
labelWidth: PropTypes.number,

// 表单提交 URL,内部调用 xhr 模块
Expand Down
1 change: 1 addition & 0 deletions src/components/Form/Form/index.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.cmui-form {
margin: 0;
width: 100%;
}
6 changes: 3 additions & 3 deletions src/components/Form/FormItem/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ FormItem.propTypes = {
children: PropTypes.node,
className: PropTypes.string,

// label 显示内容
label: PropTypes.string,

// 表单数据 key,与 data、rules 对应
name: PropTypes.string.isRequired,

// label 显示内容
label: PropTypes.string,

// 是否必填,label 显示上的区别
required: PropTypes.bool,

Expand Down
16 changes: 14 additions & 2 deletions src/components/Form/FormTextarea/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import classnames from 'classnames'
import './index.less'

const FormTextarea = (props, context) => {
const { children, className, onChange, minWidth, minHeight, ...other } = props
const { children, className, onChange, minWidth, minHeight, width, ...other } = props
const { form, formItem } = context
let value = form.getItemValue(formItem)
if (!value && value !== 0) {
Expand All @@ -15,6 +15,9 @@ const FormTextarea = (props, context) => {
form.setItemValue(formItem, e.target.value)
onChange && onChange(e)
}
if (width) {
other.style = Object.assign(other.style || {}, { width })
}
if (minWidth) {
other.style = Object.assign(other.style || {}, { minWidth })
}
Expand All @@ -25,10 +28,19 @@ const FormTextarea = (props, context) => {
}

FormTextarea.propTypes = {
onChange: PropTypes.func,
children: PropTypes.node,
className: PropTypes.string,

// onChange事件
onChange: PropTypes.func,

// 宽度大小,单位为px
width: PropTypes.number,

// 最小宽度
minWidth: PropTypes.number,

// 最小高度
minHeight: PropTypes.number
}

Expand Down
1 change: 1 addition & 0 deletions src/components/Form/FormTextarea/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

.cmui-form-textarea {
display: block;
width: 100%;
color: inherit;
border: 2px solid @lite;
padding: 10px;
Expand Down

0 comments on commit 265d3ea

Please sign in to comment.