Skip to content

Commit d45a932

Browse files
authored
feat(Form): contentAlign add center to available options and update demo (#4721)
* feat(Form): contentAlign add center to available options and update demo * feat(Form): contentAlign add center to available options and update demo for UniApp * fix: fix cr
1 parent 9ba9384 commit d45a932

72 files changed

Lines changed: 2541 additions & 1980 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/components/form-item/form-item.less‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@
141141
justify-content: flex-start;
142142
}
143143

144+
&--center {
145+
justify-content: center;
146+
}
147+
144148
&--right {
145149
justify-content: flex-end;
146150
}

‎packages/components/form-item/props.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
* 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC
55
* */
66

7-
import { TdFormItemProps } from './type';
7+
import type { TdFormItemProps } from './type';
88
const props: TdFormItemProps = {
99
/** 是否显示右侧箭头 */
1010
arrow: {
1111
type: Boolean,
1212
value: false,
1313
},
14-
/** 表单内容对齐方式:左对齐、右对齐,优先级高于 Form.contentAlign */
14+
/** 表单内容对齐方式:左对齐、居中对齐及右对齐,优先级高于 Form.contentAlign */
1515
contentAlign: {
1616
type: String,
1717
},

‎packages/components/form-item/type.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC
55
* */
66

7-
import { FormRule } from '../form/index';
7+
import type { FormRule } from '../form/index';
88

99
export interface TdFormItemProps {
1010
/**
@@ -16,11 +16,11 @@ export interface TdFormItemProps {
1616
value?: boolean;
1717
};
1818
/**
19-
* 表单内容对齐方式:左对齐、右对齐,优先级高于 Form.contentAlign
19+
* 表单内容对齐方式:左对齐、居中对齐及右对齐,优先级高于 Form.contentAlign
2020
*/
2121
contentAlign?: {
2222
type: StringConstructor;
23-
value?: 'left' | 'right';
23+
value?: 'left' | 'center' | 'right';
2424
};
2525
/**
2626
* 表单项说明内容

‎packages/components/form/README.en-US.md‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ name | type | default | description | required
99
style | Object | - | CSS(Cascading Style Sheets) | N
1010
custom-style | Object | - | CSS(Cascading Style Sheets),used to set style on virtual component | N
1111
colon | Boolean | false | \- | N
12-
content-align | String | left | options: left/right | N
12+
content-align | String | left | options: left/center/right | N
1313
data | Object | {} | Typescript: `FormData` | N
1414
error-message | Object | - | Typescript: `FormErrorMessage` | N
1515
label-align | String | right | options: left/right/top | N
1616
label-width | String / Number | '81px' | \- | N
1717
required-mark | Boolean | true | \- | N
18-
required-mark-position | String | left | Display position of required symbols。options: left/right | N
18+
required-mark-position | String | left | Display position of required symbols. options: left/right | N
1919
reset-type | String | empty | options: empty/initial | N
20-
rules | Object | - | Typescript: `FormRules<FormData>` `type FormRules<T extends Data = any> = { [field in keyof T]?: Array<FormRule> }`。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts) | N
20+
rules | Object | - | Typescript: `FormRules<FormData>` `type FormRules<T extends Data = any> = { [field in keyof T]?: Array<FormRule> }`. [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts) | N
2121
scroll-to-first-error | String | - | options: ''/smooth/auto | N
2222
show-error-message | Boolean | true | \- | N
2323
submit-with-warning-message | Boolean | false | \- | N
@@ -27,18 +27,18 @@ submit-with-warning-message | Boolean | false | \- | N
2727
name | params | description
2828
-- | -- | --
2929
reset | `(detail: { e?: FormResetEvent })` | [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/common/common.ts)
30-
submit | `(detail: SubmitContext<FormData>)` | [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts)。<br/>`interface SubmitContext<T extends Data = Data> { e?: FormSubmitEvent; validateResult: FormValidateResult<T>; firstError?: string; fields?: any }`<br/><br/>`type FormValidateResult<T> = boolean \| ValidateResultObj<T>`<br/><br/>`type ValidateResultObj<T> = { [key in keyof T]: boolean \| ValidateResultList }`<br/><br/>`type ValidateResultList = Array<AllValidateResult>`<br/><br/>`type AllValidateResult = CustomValidateObj \| ValidateResultType`<br/><br/>`interface ValidateResultType extends FormRule { result: boolean }`<br/><br/>`type ValidateResult<T> = { [key in keyof T]: boolean \| ErrorList }`<br/><br/>`type ErrorList = Array<FormRule>`<br/>
31-
validate | `(result: ValidateResultContext<FormData>)` | [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts)。<br/>`type ValidateResultContext<T extends Data> = Omit<SubmitContext<T>, 'e'>`<br/>
30+
submit | `(detail: SubmitContext<FormData>)` | [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts). <br/>`interface SubmitContext<T extends Data = Data> { e?: FormSubmitEvent; validateResult: FormValidateResult<T>; firstError?: string; fields?: any }`<br/><br/>`type FormValidateResult<T> = boolean \| ValidateResultObj<T>`<br/><br/>`type ValidateResultObj<T> = { [key in keyof T]: boolean \| ValidateResultList }`<br/><br/>`type ValidateResultList = Array<AllValidateResult>`<br/><br/>`type AllValidateResult = CustomValidateObj \| ValidateResultType`<br/><br/>`interface ValidateResultType extends FormRule { result: boolean }`<br/><br/>`type ValidateResult<T> = { [key in keyof T]: boolean \| ErrorList }`<br/><br/>`type ErrorList = Array<FormRule>`<br/>
31+
validate | `(result: ValidateResultContext<FormData>)` | [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts). <br/>`type ValidateResultContext<T extends Data> = Omit<SubmitContext<T>, 'e'>`<br/>
3232

3333
### FormInstanceFunctions 组件实例方法
3434

3535
name | params | return | description
3636
-- | -- | -- | --
3737
clear-validate | `(fields?: Array<keyof FormData>)` | \- | required
38-
reset | `(params?: FormResetParams<FormData>)` | \- | required。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts)。<br/>`interface FormResetParams<FormData> { type?: 'initial' \| 'empty'; fields?: Array<keyof FormData> }`<br/>
39-
set-validate-message | `(message: FormValidateMessage<FormData>)` | \- | required。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts)。<br/>`type FormValidateMessage<FormData> = { [field in keyof FormData]: FormItemValidateMessage[] }`<br/><br/>`interface FormItemValidateMessage { type: 'warning' \| 'error'; message: string }`<br/>
38+
reset | `(params?: FormResetParams<FormData>)` | \- | required. [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts). <br/>`interface FormResetParams<FormData> { type?: 'initial' \| 'empty'; fields?: Array<keyof FormData> }`<br/>
39+
set-validate-message | `(message: FormValidateMessage<FormData>)` | \- | required. [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts). <br/>`type FormValidateMessage<FormData> = { [field in keyof FormData]: FormItemValidateMessage[] }`<br/><br/>`interface FormItemValidateMessage { type: 'warning' \| 'error'; message: string }`<br/>
4040
submit | `(params?: { showErrorMessage?: boolean })` | \- | required
41-
validate | `(params?: FormValidateParams)` | `Promise<FormValidateResult<FormData>> ` | required。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts)。<br/>`interface FormValidateParams { fields?: Array<string>; showErrorMessage?: boolean; trigger?: ValidateTriggerType }`<br/><br/>`type ValidateTriggerType = 'blur' \| 'change' \| 'submit' \| 'all'`<br/><br/>`type FormValidateResult<T> = boolean \| ValidateResultObj<T>`<br/><br/>`type ValidateResultObj<T> = { [key in keyof T]: boolean \| ValidateResultList }`<br/><br/>`type ValidateResultList = Array<AllValidateResult>`<br/><br/>`type AllValidateResult = CustomValidateObj \| ValidateResultType`<br/><br/>`interface ValidateResultType extends FormRule { result: boolean }`<br/>
41+
validate | `(params?: FormValidateParams)` | `Promise<FormValidateResult<FormData>> ` | required. [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts). <br/>`interface FormValidateParams { fields?: Array<string>; showErrorMessage?: boolean; trigger?: ValidateTriggerType }`<br/><br/>`type ValidateTriggerType = 'blur' \| 'change' \| 'submit' \| 'all'`<br/><br/>`type FormValidateResult<T> = boolean \| ValidateResultObj<T>`<br/><br/>`type ValidateResultObj<T> = { [key in keyof T]: boolean \| ValidateResultList }`<br/><br/>`type ValidateResultList = Array<AllValidateResult>`<br/><br/>`type AllValidateResult = CustomValidateObj \| ValidateResultType`<br/><br/>`interface ValidateResultType extends FormRule { result: boolean }`<br/>
4242

4343

4444
### FormItem Props
@@ -48,14 +48,14 @@ name | type | default | description | required
4848
style | Object | - | CSS(Cascading Style Sheets) | N
4949
custom-style | Object | - | CSS(Cascading Style Sheets),used to set style on virtual component | N
5050
arrow | Boolean | false | \- | N
51-
content-align | String | - | options: left/right | N
51+
content-align | String | - | options: left/center/right | N
5252
help | String | - | \- | N
5353
label | String | '' | \- | N
5454
label-align | String | - | options: left/right/top | N
5555
label-width | String / Number | - | \- | N
5656
name | String | - | \- | N
5757
required-mark | Boolean | undefined | \- | N
58-
rules | Array | - | Typescript: `Array<FormRule> `,[Form API Documents](./form?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form-item/type.ts) | N
58+
rules | Array | - | Typescript: `Array<FormRule> `,[Form API Documents](./form?tab=api). [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form-item/type.ts) | N
5959
show-error-message | Boolean | undefined | \- | N
6060

6161
### FormItem Slots
@@ -70,8 +70,8 @@ label | \-
7070
name | type | default | description | required
7171
-- | -- | -- | -- | --
7272
boolean | Boolean | - | \- | N
73-
date | Boolean / Object | - | Typescript: `boolean \| IsDateOptions` `interface IsDateOptions { format: string; strictMode: boolean; delimiters: string[] }`。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts) | N
74-
email | Boolean / Object | - | Typescript: `boolean \| IsEmailOptions` `import { IsEmailOptions } from 'validator/es/lib/isEmail'`。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts) | N
73+
date | Boolean / Object | - | Typescript: `boolean \| IsDateOptions` `interface IsDateOptions { format: string; strictMode: boolean; delimiters: string[] }`. [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts) | N
74+
email | Boolean / Object | - | Typescript: `boolean \| IsEmailOptions` `import { IsEmailOptions } from 'validator/es/lib/isEmail'`. [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts) | N
7575
enum | Array | - | Typescript: `Array<string>` | N
7676
idcard | Boolean | - | \- | N
7777
len | Number / Boolean | - | \- | N
@@ -84,8 +84,8 @@ required | Boolean | - | \- | N
8484
telnumber | Boolean | - | \- | N
8585
trigger | String | change | Typescript: `ValidateTriggerType` | N
8686
type | String | error | options: error/warning | N
87-
url | Boolean / Object | - | Typescript: `boolean \| IsURLOptions` `import { IsURLOptions } from 'validator/es/lib/isURL'`。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts) | N
88-
validator | Function | - | Typescript: `CustomValidator` `type CustomValidator = (val: ValueType, context?: { formData: Data , name: string }) => CustomValidateResolveType \| Promise<CustomValidateResolveType>` `type CustomValidateResolveType = boolean \| CustomValidateObj` `interface CustomValidateObj { result: boolean; message: string; type?: 'error' \| 'warning' \| 'success' }` `type ValueType = any`。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts) | N
87+
url | Boolean / Object | - | Typescript: `boolean \| IsURLOptions` `import { IsURLOptions } from 'validator/es/lib/isURL'`. [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts) | N
88+
validator | Function | - | Typescript: `CustomValidator` `type CustomValidator = (val: ValueType, context?: { formData: Data , name: string }) => CustomValidateResolveType \| Promise<CustomValidateResolveType>` `type CustomValidateResolveType = boolean \| CustomValidateObj` `interface CustomValidateObj { result: boolean; message: string; type?: 'error' \| 'warning' \| 'success' }` `type ValueType = any`. [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/form/type.ts) | N
8989
whitespace | Boolean | - | \- | N
9090

9191
### FormErrorMessage

‎packages/components/form/README.md‎

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,41 @@ toc: false
3535

3636
#### 基础表单
3737

38-
{{ horizontal }}
38+
{{ base }}
3939

40-
{{ vertical }}
40+
41+
### 02 组件状态
42+
43+
#### 提示
44+
45+
{{ help }}
46+
47+
#### 校验规则
48+
49+
{{ rules }}
50+
51+
52+
### 03 组件样式
53+
54+
#### 标签对齐样式
55+
56+
{{ label-align }}
57+
58+
#### 标签带冒号
59+
60+
{{ colon }}
61+
62+
#### 标签必填位置
63+
64+
{{ required-mark }}
65+
66+
#### 标签宽度
67+
68+
{{ label-width }}
69+
70+
#### 标签内容对齐样式
71+
72+
{{ content-align }}
4173

4274

4375
## API
@@ -49,7 +81,7 @@ toc: false
4981
style | Object | - | 样式 | N
5082
custom-style | Object | - | 样式,一般用于开启虚拟化组件节点场景 | N
5183
colon | Boolean | false | 是否在表单标签字段右侧显示冒号 | N
52-
content-align | String | left | 表单内容对齐方式:左对齐、右对齐。可选项:left/right | N
84+
content-align | String | left | 表单内容对齐方式:左对齐、居中对齐及右对齐。可选项:left/center/right | N
5385
data | Object | {} | 表单数据。TS 类型:`FormData` | N
5486
error-message | Object | - | 表单错误信息配置,示例:`{ idcard: '请输入正确的身份证号码', max: '字符长度不能超过 ${max}' }`。TS 类型:`FormErrorMessage` | N
5587
label-align | String | right | 表单字段标签对齐方式:左对齐、右对齐、顶部对齐。可选项:left/right/top | N
@@ -88,7 +120,7 @@ validate | `(params?: FormValidateParams)` | `Promise<FormValidateResult<FormDat
88120
style | Object | - | 样式 | N
89121
custom-style | Object | - | 样式,一般用于开启虚拟化组件节点场景 | N
90122
arrow | Boolean | false | 是否显示右侧箭头 | N
91-
content-align | String | - | 表单内容对齐方式:左对齐、右对齐,优先级高于 Form.contentAlign。可选项:left/right | N
123+
content-align | String | - | 表单内容对齐方式:左对齐、居中对齐及右对齐,优先级高于 Form.contentAlign。可选项:left/center/right | N
92124
help | String | - | 表单项说明内容 | N
93125
label | String | '' | 字段标签名称 | N
94126
label-align | String | - | 表单字段标签对齐方式:左对齐、右对齐、顶部对齐。默认使用 Form 的对齐方式,优先级高于 Form.labelAlign。可选项:left/right/top | N

0 commit comments

Comments
 (0)