Skip to content

Commit ae6aee6

Browse files
PanStartangjinzhou
authored andcommitted
feat: From 组件新增 labelCol、wrapperCol (#1365)
* From 组件新增 labelCol、wrapperCol * 1 Form 组件 types 补充 2 Button 组件 文档优化 3 Radio 组件 样式优化
1 parent 3136e59 commit ae6aee6

File tree

8 files changed

+51
-33
lines changed

8 files changed

+51
-33
lines changed

components/button/demo/basic.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<cn>
22
#### 按钮类型
3-
按钮有四种类型:主按钮、次按钮、虚线按钮、危险按钮和链接按钮。主按钮在同一个操作区域最多出现一次。
3+
按钮有五种类型:主按钮、次按钮、虚线按钮、危险按钮和链接按钮。主按钮在同一个操作区域最多出现一次。
44
</cn>
55

66
<us>
77
#### Type
8-
There are `primary` button, `default` button, `dashed` button and `danger` button and `link` button in antd.
8+
There are `primary` button, `default` button, `dashed` button , `danger` button and `link` button in antd.
99
</us>
1010

1111
```tpl

components/form/Form.jsx

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import PropTypes from '../_util/vue-types';
22
import classNames from 'classnames';
3+
import { ColProps } from '../grid/Col';
34
import Vue from 'vue';
45
import isRegExp from 'lodash/isRegExp';
56
import warning from '../_util/warning';
@@ -59,6 +60,8 @@ export const WrappedFormUtils = {
5960

6061
export const FormProps = {
6162
layout: PropTypes.oneOf(['horizontal', 'inline', 'vertical']),
63+
labelCol: PropTypes.shape(ColProps).loose,
64+
wrapperCol: PropTypes.shape(ColProps).loose,
6265
form: PropTypes.object,
6366
// onSubmit: React.FormEventHandler<any>;
6467
prefixCls: PropTypes.string,

components/form/FormItem.jsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ export default {
314314
},
315315

316316
renderWrapper(prefixCls, children) {
317-
const { wrapperCol = {} } = this;
317+
const { FormProps: { wrapperCol: wrapperColForm = {} } = {} } = this;
318+
const { wrapperCol = wrapperColForm } = this;
318319
const { class: cls, style, id, on, ...restProps } = wrapperCol;
319320
const className = classNames(`${prefixCls}-item-control-wrapper`, cls);
320321
const colProps = {
@@ -369,7 +370,8 @@ export default {
369370
},
370371

371372
renderLabel(prefixCls) {
372-
const { labelCol = {}, colon, id } = this;
373+
const { FormProps: { labelCol: labelColForm = {} } = {} } = this;
374+
const { labelCol = labelColForm, colon, id } = this;
373375
const label = getComponentFromProp(this, 'label');
374376
const required = this.isRequired();
375377
const {

components/form/demo/validate-other.vue

+13-17
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ Demonstration of validation configuration for form controls which are not shown
99
</us>
1010

1111
<template>
12-
<a-form id="components-form-demo-validate-other" :form="form" @submit="handleSubmit">
13-
<a-form-item v-bind="formItemLayout" label="Plain Text">
12+
<a-form id="components-form-demo-validate-other" :form="form" v-bind="formItemLayout" @submit="handleSubmit">
13+
<a-form-item label="Plain Text">
1414
<span class="ant-form-text">
1515
China
1616
</span>
1717
</a-form-item>
18-
<a-form-item v-bind="formItemLayout" label="Select" has-feedback>
18+
<a-form-item label="Select" has-feedback>
1919
<a-select
2020
v-decorator="[
2121
'select',
@@ -32,7 +32,7 @@ Demonstration of validation configuration for form controls which are not shown
3232
</a-select>
3333
</a-form-item>
3434

35-
<a-form-item v-bind="formItemLayout" label="Select[multiple]">
35+
<a-form-item label="Select[multiple]">
3636
<a-select
3737
v-decorator="[
3838
'select-multiple',
@@ -57,25 +57,25 @@ Demonstration of validation configuration for form controls which are not shown
5757
</a-select>
5858
</a-form-item>
5959

60-
<a-form-item v-bind="formItemLayout" label="InputNumber">
60+
<a-form-item label="InputNumber">
6161
<a-input-number v-decorator="['input-number', { initialValue: 3 }]" :min="1" :max="10" />
6262
<span class="ant-form-text">
6363
machines
6464
</span>
6565
</a-form-item>
6666

67-
<a-form-item v-bind="formItemLayout" label="Switch">
67+
<a-form-item label="Switch">
6868
<a-switch v-decorator="['switch', { valuePropName: 'checked' }]" />
6969
</a-form-item>
7070

71-
<a-form-item v-bind="formItemLayout" label="Slider">
71+
<a-form-item label="Slider">
7272
<a-slider
7373
v-decorator="['slider']"
7474
:marks="{ 0: 'A', 20: 'B', 40: 'C', 60: 'D', 80: 'E', 100: 'F' }"
7575
/>
7676
</a-form-item>
7777

78-
<a-form-item v-bind="formItemLayout" label="Radio.Group">
78+
<a-form-item label="Radio.Group">
7979
<a-radio-group v-decorator="['radio-group']">
8080
<a-radio value="a">
8181
item 1
@@ -89,7 +89,7 @@ Demonstration of validation configuration for form controls which are not shown
8989
</a-radio-group>
9090
</a-form-item>
9191

92-
<a-form-item v-bind="formItemLayout" label="Radio.Button">
92+
<a-form-item label="Radio.Button">
9393
<a-radio-group v-decorator="['radio-button']">
9494
<a-radio-button value="a">
9595
item 1
@@ -103,7 +103,7 @@ Demonstration of validation configuration for form controls which are not shown
103103
</a-radio-group>
104104
</a-form-item>
105105

106-
<a-form-item v-bind="formItemLayout" label="Checkbox.Group">
106+
<a-form-item label="Checkbox.Group">
107107
<a-checkbox-group
108108
v-decorator="['checkbox-group', { initialValue: ['A', 'B'] }]"
109109
style="width: 100%;"
@@ -138,15 +138,11 @@ Demonstration of validation configuration for form controls which are not shown
138138
</a-checkbox-group>
139139
</a-form-item>
140140

141-
<a-form-item v-bind="formItemLayout" label="Rate">
141+
<a-form-item label="Rate">
142142
<a-rate v-decorator="['rate', { initialValue: 3.5 }]" allow-half />
143143
</a-form-item>
144144

145-
<a-form-item
146-
v-bind="formItemLayout"
147-
label="Upload"
148-
extra="longgggggggggggggggggggggggggggggggggg"
149-
>
145+
<a-form-item label="Upload" extra="longgggggggggggggggggggggggggggggggggg">
150146
<a-upload
151147
v-decorator="[
152148
'upload',
@@ -163,7 +159,7 @@ Demonstration of validation configuration for form controls which are not shown
163159
</a-upload>
164160
</a-form-item>
165161

166-
<a-form-item v-bind="formItemLayout" label="Dragger">
162+
<a-form-item label="Dragger">
167163
<div class="dropbox">
168164
<a-upload-dragger
169165
v-decorator="[

components/form/index.en-US.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
| form | Decorated by `Form.create()` will be automatically set `this.form` property, so just pass to form. If you use the template syntax, you can use `this.$form.createForm(this, options)` | object | n/a |
88
| hideRequiredMark | Hide required mark of all form items | Boolean | false |
99
| layout | Define form layout | 'horizontal'\|'vertical'\|'inline' | 'horizontal' |
10+
| labelCol | The layout of label. You can set `span` `offset` to something like `{span: 3, offset: 12}` or `sm: {span: 3, offset: 12}` same as with `<Col>` | [object](/components/grid/#Col) | |
11+
| wrapperCol | The layout for input controls, same as `labelCol` | [object](/components/grid/#Col) | |
1012
| autoFormCreate(deprecated) | Automate Form.create, Recommended for use under the `template` component, and cannot be used with `Form.create()`. You should use `$form.createForm` to instead it after 1.1.9. | Function(form) | |
1113
| options(deprecated) | The `options` corresponding to `Form.create(options)`. You should use `$form.createForm` to instead it after 1.1.9. | Object | {} |
1214

components/form/index.zh-CN.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
| form |`Form.create()` 包装过的组件会自带 `this.form` 属性,如果使用 template 语法,可以使用 this.\$form.createForm(this, options) | object ||
88
| hideRequiredMark | 隐藏所有表单项的必选标记 | Boolean | false |
99
| layout | 表单布局 | 'horizontal'\|'vertical'\|'inline' | 'horizontal' |
10+
| labelCol | label 标签布局,同 `<Col>` 组件,设置 `span` `offset` 值,如 `{span: 3, offset: 12}``sm: {span: 3, offset: 12}` | [object](/components/grid-cn/#Col) | |
11+
| wrapperCol | 需要为输入控件设置布局样式时,使用该属性,用法同 labelCol | [object](/components/grid-cn/#Col) | |
1012
| selfUpdate | 自定义字段更新逻辑,说明[见下](/components/form-cn/#selfUpdate),需 1.3.17 版本以上 | boolean | false |
1113

1214
### 事件

components/radio/style/index.less

+12-12
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,18 @@ span.@{radio-prefix-cls} + * {
184184
line-height: @input-height-sm - 2px;
185185
}
186186

187-
&:not(:first-child) {
188-
&::before {
189-
position: absolute;
190-
top: 0;
191-
left: -1px;
192-
display: block;
193-
width: 1px;
194-
height: 100%;
195-
background-color: @border-color-base;
196-
content: '';
197-
}
198-
}
187+
// &:not(:first-child) {
188+
// &::before {
189+
// position: absolute;
190+
// top: 0;
191+
// left: -1px;
192+
// display: block;
193+
// width: 1px;
194+
// height: 100%;
195+
// background-color: @border-color-base;
196+
// content: '';
197+
// }
198+
// }
199199
&:first-child {
200200
border-left: @border-width-base @border-style-base @border-color-base;
201201
border-radius: @border-radius-base 0 0 @border-radius-base;

types/form/form.d.ts

+13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Definitions: https://github.com/vueComponent/ant-design-vue/types
44

55
import { AntdComponent } from '../component';
6+
import { Col } from '../grid/col';
67
import Vue from 'vue';
78
import { FormItem } from './form-item';
89

@@ -348,13 +349,25 @@ export declare class Form extends AntdComponent {
348349
*/
349350
hideRequiredMark: boolean;
350351

352+
/**
353+
* The layout of label. You can set span offset to something like {span: 3, offset: 12} or sm: {span: 3, offset: 12} same as with <Col>
354+
* @type Col
355+
*/
356+
labelCol: Col;
357+
351358
/**
352359
* Define form layout
353360
* @default 'horizontal'
354361
* @type string
355362
*/
356363
layout: 'horizontal' | 'inline' | 'vertical';
357364

365+
/**
366+
* The layout for input controls, same as labelCol
367+
* @type Col
368+
*/
369+
wrapperCol: Col;
370+
358371
/**
359372
* Automate Form.create, Recommended for use under the template component, and cannot be used with Form.create().
360373
* You should use $form.createForm to instead it after 1.1.9.

0 commit comments

Comments
 (0)