Skip to content

Commit

Permalink
docs(antd): add form-layout doc
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Mar 12, 2021
1 parent a01958e commit f167a75
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/antd/docs/components/FormItem.md
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,10 @@ export default () => {
| 属性名 | 类型 | 描述 | 默认值 |
| -------------- | ------------------------------------------------------ | ------------------------------------------- | --------- |
| label | ReactNode | 标签 | - |
| style | CSSProperties | 样式 | - |
| labelStyle | CSSProperties | 标签样式 | - |
| wrapperStyle | CSSProperties | 组件容器样式 | - |
| className | string | 组件样式类名 | - |
| colon | boolean | 冒号 | true |
| tooltip | ReactNode | 问号提示 | - |
| labelAlign | `"left"` \| `"right"` | 标签文本对齐方式 | `"right"` |
Expand Down
188 changes: 188 additions & 0 deletions packages/antd/docs/components/FormLayout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
# FormLayout

> 区块级布局批量控制组件,借助该组件,我们可以轻松的控制被 FormLayout 圈住的所有 FormItem 组件的布局模式
## Markup Schema 案例

```tsx
import React from 'react'
import { Input as NextInput, Select } from 'antd'
import {
Input,
FormItem,
FormButtonGroup,
Submit,
FormLayout,
} from '@formily/antd'
import { createForm } from '@formily/core'
import { FormProvider, createSchemaField } from '@formily/react'

const SchemaField = createSchemaField({
components: {
Input,
Select,
FormItem,
FormLayout,
},
})

const form = createForm()

export default () => (
<FormProvider form={form}>
<SchemaField>
<SchemaField.Void
x-component="FormLayout"
x-component-props={{
labelCol: 6,
wrapperCol: 10,
}}
>
<SchemaField.String
name="input"
title="输入框"
x-decorator="FormItem"
x-component="Input"
required
/>
<SchemaField.String
name="select"
title="选择框"
x-decorator="FormItem"
x-component="Select"
required
/>
</SchemaField.Void>
</SchemaField>
</FormProvider>
)
```

## JSON Schema 案例

```tsx
import React from 'react'
import { Input as NextInput, Select } from 'antd'
import {
Input,
FormItem,
FormButtonGroup,
Submit,
FormLayout,
} from '@formily/antd'
import { createForm } from '@formily/core'
import { FormProvider, createSchemaField } from '@formily/react'

const SchemaField = createSchemaField({
components: {
Input,
Select,
FormItem,
FormLayout,
},
})

const schema = {
type: 'object',
properties: {
layout: {
type: 'void',
'x-component': 'FormLayout',
'x-component-props': {
labelCol: 6,
wrapperCol: 10,
},
properties: {
input: {
type: 'string',
title: '输入框',
required: true,
'x-decorator': 'FormItem',
'x-component': 'Input',
},
select: {
type: 'string',
title: '选择框',
required: true,
'x-decorator': 'FormItem',
'x-component': 'Select',
},
},
},
},
}

const form = createForm()

export default () => (
<FormProvider form={form}>
<SchemaField schema={schema} />
</FormProvider>
)
```

## 纯 JSX 案例

```tsx
import React from 'react'
import { Input as NextInput, Select } from 'antd'
import {
Input,
FormItem,
FormButtonGroup,
Submit,
FormLayout,
} from '@formily/antd'
import { createForm } from '@formily/core'
import { FormProvider, Field } from '@formily/react'

const form = createForm()

export default () => (
<FormProvider form={form}>
<FormLayout labelCol={6} wrapperCol={10}>
<Field
name="input"
required
title="输入框"
decorator={[FormItem]}
component={[Input]}
/>
<Field
name="select"
required
title="选择框"
decorator={[FormItem]}
component={[Select]}
/>
<FormButtonGroup.FormItem>
<Submit onSubmit={console.log}>提交</Submit>
</FormButtonGroup.FormItem>
</FormLayout>
</FormProvider>
)
```

## API

| 属性名 | 类型 | 描述 | 默认值 |
| -------------- | ---------------------------------------- | ----------------------- | ---------- |
| style | CSSProperties | 样式 | - |
| className | string | 类名 | - |
| colon | boolean | 是否有冒号 | true |
| labelAlign | `'right' \| 'left'` | 标签内容对齐 | - |
| wrapperAlign | `'right' \| 'left'` | 组件容器内容对齐 | - |
| labelWrap | boolean | 标签内容换行 | false |
| labelWidth | number | 标签宽度(px) | - |
| wrapperWidth | number | 组件容器宽度(px) | - |
| wrapperWrap | boolean | 组件容器换行 | false |
| labelCol | number | 标签宽度(24 column) | - |
| wrapperCol | number | 组件容器宽度(24 column) | - |
| fullness | boolean | 组件容器宽度 100% | false |
| size | `'small' \| 'default' \| 'large'` | 组件尺寸 | default |
| layout | `'vertical' \| 'horizontal' \| 'inline'` | 布局模式 | horizontal |
| direction | `'rtl' \| 'ltr'` | 方向(暂不支持) | ltr |
| inset | boolean | 内联布局 | false |
| shallow | boolean | 上下文浅层传递 | true |
| feedbackLayout | `'loose' \| 'terse' \| 'popover'` | 反馈布局 | true |
| bordered | boolean | 是否有边框 | true |
8 changes: 6 additions & 2 deletions packages/antd/src/form-item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface IFormItemProps {
label?: React.ReactNode
colon?: boolean
tooltip?: boolean
labelStyle?: React.CSSProperties
labelAlign?: 'left' | 'right'
labelWrap?: boolean
labelWidth?: number
Expand All @@ -32,6 +33,7 @@ export interface IFormItemProps {
wrapperCol?: number
wrapperAlign?: 'left' | 'right'
wrapperWrap?: boolean
wrapperStyle?: React.CSSProperties
fullness?: boolean
addonBefore?: React.ReactNode
addonAfter?: React.ReactNode
Expand Down Expand Up @@ -93,6 +95,7 @@ export const BaseItem: React.FC<IFormItemProps> = (props) => {
const shallowFormLayout = useFormShallowLayout()
const {
label,
style,
layout,
colon = true,
addonBefore,
Expand All @@ -117,8 +120,8 @@ export const BaseItem: React.FC<IFormItemProps> = (props) => {
wrapperWrap,
tooltip,
} = formLayout
const labelStyle: any = {}
const wrapperStyle: any = {}
const labelStyle: any = formLayout.labelStyle || {}
const wrapperStyle: any = formLayout.wrapperStyle || {}
// 固定宽度
let enableCol = false
if (labelWidth || wrapperWidth) {
Expand Down Expand Up @@ -163,6 +166,7 @@ export const BaseItem: React.FC<IFormItemProps> = (props) => {
return (
<div
ref={popoverContainerRef}
style={style}
className={cls({
[`${prefixCls}`]: true,
[`${prefixCls}-layout-${layout}`]: true,
Expand Down

0 comments on commit f167a75

Please sign in to comment.