Browse Source

feat: Form[vertical], close: #2449

pull/2618/head
Benjy Cui 8 years ago
parent
commit
7d9585377e
  1. 5
      components/form/Form.tsx
  2. 2
      components/form/demo/horizontal-form.md
  3. 37
      components/form/demo/validate-customized.md
  4. 3
      components/form/index.en-US.md
  5. 1
      components/form/index.zh-CN.md
  6. 12
      components/form/style/index.less

5
components/form/Form.tsx

@ -14,6 +14,7 @@ export default class Form extends React.Component {
static propTypes = { static propTypes = {
prefixCls: React.PropTypes.string, prefixCls: React.PropTypes.string,
vertical: React.PropTypes.bool,
horizontal: React.PropTypes.bool, horizontal: React.PropTypes.bool,
inline: React.PropTypes.bool, inline: React.PropTypes.bool,
children: React.PropTypes.any, children: React.PropTypes.any,
@ -31,9 +32,10 @@ export default class Form extends React.Component {
} }
render() { render() {
const { prefixCls, className, inline, horizontal } = this.props; const { prefixCls, className, inline, horizontal, vertical } = this.props;
const formClassName = classNames({ const formClassName = classNames({
[`${prefixCls}-horizontal`]: horizontal, [`${prefixCls}-horizontal`]: horizontal,
[`${prefixCls}-vertical`]: vertical,
[`${prefixCls}-inline`]: inline, [`${prefixCls}-inline`]: inline,
[className]: !!className, [className]: !!className,
}); });
@ -43,6 +45,7 @@ export default class Form extends React.Component {
'className', 'className',
'inline', 'inline',
'horizontal', 'horizontal',
'vertical',
'form', 'form',
]); ]);

2
components/form/demo/horizontal-form.md

@ -62,7 +62,7 @@ let Demo = React.createClass({
</FormItem> </FormItem>
<FormItem <FormItem
{...formItemLayout} {...formItemLayout}
label={<span>Sold myself to Hua palace <Tooltip title="I come for Qiu Xiang"><Icon type="question-circle-o" /></Tooltip></span>} label={<span>Sold myself <Tooltip title="I come for Qiu Xiang"><Icon type="question-circle-o" /></Tooltip></span>}
> >
<Checkbox {...getFieldProps('agreement', { initialValue: false, valuePropName: 'checked' })}>agree</Checkbox> <Checkbox {...getFieldProps('agreement', { initialValue: false, valuePropName: 'checked' })}>agree</Checkbox>
</FormItem> </FormItem>

37
components/form/demo/validate-customized.md

@ -145,19 +145,12 @@ let Demo = React.createClass({
validator: this.checkPass2, validator: this.checkPass2,
}], }],
}); });
const formItemLayout = {
labelCol: { span: 6 },
wrapperCol: { span: 18 },
};
return ( return (
<div> <div>
<Form horizontal form={this.props.form}> <Form vertical style={{ maxWidth: 600 }} form={this.props.form}>
<Row> <Row type="flex" align="middle">
<Col span="18"> <Col span={12}>
<FormItem <FormItem label="Password">
{...formItemLayout}
label="Password"
>
<Input {...passProps} type="password" <Input {...passProps} type="password"
onContextMenu={noop} onPaste={noop} onCopy={noop} onCut={noop} onContextMenu={noop} onPaste={noop} onCopy={noop} onCut={noop}
autoComplete="off" id="pass" autoComplete="off" id="pass"
@ -168,34 +161,24 @@ let Demo = React.createClass({
/> />
</FormItem> </FormItem>
</Col> </Col>
<Col span="6"> <Col span={12}>
{this.state.passBarShow ? this.renderPassStrengthBar('pass') : null} {this.state.passBarShow ? this.renderPassStrengthBar('pass') : null}
</Col> </Col>
</Row> </Row>
<Row type="flex" align="middle">
<Row> <Col span={12}>
<Col span="18"> <FormItem label="Confirm">
<FormItem
{...formItemLayout}
label="Confirm password"
>
<Input {...rePassProps} type="password" <Input {...rePassProps} type="password"
onContextMenu={noop} onPaste={noop} onCopy={noop} onCut={noop} onContextMenu={noop} onPaste={noop} onCopy={noop} onCut={noop}
autoComplete="off" id="rePass" autoComplete="off" id="rePass"
/> />
</FormItem> </FormItem>
</Col> </Col>
<Col span="6"> <Col span={12}>
{this.state.rePassBarShow ? this.renderPassStrengthBar('rePass') : null} {this.state.rePassBarShow ? this.renderPassStrengthBar('rePass') : null}
</Col> </Col>
</Row> </Row>
<Row> <FormItem><Button type="primary" onClick={this.handleSubmit}>提交</Button></FormItem>
<Col span="18">
<Col span="18" offset="6">
<Button type="primary" onClick={this.handleSubmit}>提交</Button>
</Col>
</Col>
</Row>
</Form> </Form>
</div> </div>
); );

3
components/form/index.en-US.md

@ -37,7 +37,8 @@ A form field is defined using `<Form.Item />`.
| Property | Description | Type | Default Value | | Property | Description | Type | Default Value |
|-----------|------------------------------------------|------------|---------| |-----------|------------------------------------------|------------|---------|
| form | Decorated by `Form.create()` will be automatically set `this.props.form` property, so just pass to form, you don't need to set it by yourself after 1.7.0. | object | n/a | form | Decorated by `Form.create()` will be automatically set `this.props.form` property, so just pass to form, you don't need to set it by yourself after 1.7.0. | object | n/a
| horizontal | Use horizontal alignment. | boolean | false | | vertical | Use vertical layout. | boolean | false |
| horizontal | Use horizontal layout. | boolean | false |
| inline | Use inline alignment. | boolean | false | | inline | Use inline alignment. | boolean | false |
| onSubmit | Defines a function will be called if form data validation is successful. | Function(e:Event) | | | onSubmit | Defines a function will be called if form data validation is successful. | Function(e:Event) | |
| prefixCls | Set the CSS class name of form component (optional). | string | 'ant-form' | | prefixCls | Set the CSS class name of form component (optional). | string | 'ant-form' |

1
components/form/index.zh-CN.md

@ -39,6 +39,7 @@ english: Form
| 参数 | 说明 | 类型 | 默认值 | | 参数 | 说明 | 类型 | 默认值 |
|-----------|------------------------------------------|------------|-------| |-----------|------------------------------------------|------------|-------|
| form | 经 `Form.create()` 包装过的组件会自带 `this.props.form` 属性,直接传给 Form 即可。1.7.0 之后无需设置 | object | 无 | | form | 经 `Form.create()` 包装过的组件会自带 `this.props.form` 属性,直接传给 Form 即可。1.7.0 之后无需设置 | object | 无 |
| vertical | 垂直排列布局 | boolean | false |
| horizontal | 水平排列布局 | boolean | false | | horizontal | 水平排列布局 | boolean | false |
| inline | 行内排列布局 | boolean | false | | inline | 行内排列布局 | boolean | false |
| onSubmit | 数据验证成功后回调事件 | Function(e:Event) | | | onSubmit | 数据验证成功后回调事件 | Function(e:Event) | |

12
components/form/style/index.less

@ -226,6 +226,18 @@ form {
} }
} }
// Form layout
//== Vertical Form
.@{form-prefix-cls}-vertical {
.@{form-prefix-cls}-item-label {
padding: 0 0 8px;
label:after {
content: '';
}
}
}
//== Inline Form //== Inline Form
.@{form-prefix-cls}-inline { .@{form-prefix-cls}-inline {
.@{form-prefix-cls}-item { .@{form-prefix-cls}-item {

Loading…
Cancel
Save