diff --git a/packages/antd/docs/components/FormItem.md b/packages/antd/docs/components/FormItem.md index b488a6cf173..c03a528cece 100644 --- a/packages/antd/docs/components/FormItem.md +++ b/packages/antd/docs/components/FormItem.md @@ -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"` | diff --git a/packages/antd/docs/components/FormLayout.md b/packages/antd/docs/components/FormLayout.md index e69de29bb2d..3bb5f81a3d3 100644 --- a/packages/antd/docs/components/FormLayout.md +++ b/packages/antd/docs/components/FormLayout.md @@ -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 () => ( + + + + + + + + +) +``` + +## 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 () => ( + + + +) +``` + +## 纯 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 () => ( + + + + + + 提交 + + + +) +``` + +## 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 | diff --git a/packages/antd/src/form-item/index.tsx b/packages/antd/src/form-item/index.tsx index 18164cf0794..99a24a4b00c 100644 --- a/packages/antd/src/form-item/index.tsx +++ b/packages/antd/src/form-item/index.tsx @@ -24,6 +24,7 @@ export interface IFormItemProps { label?: React.ReactNode colon?: boolean tooltip?: boolean + labelStyle?: React.CSSProperties labelAlign?: 'left' | 'right' labelWrap?: boolean labelWidth?: number @@ -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 @@ -93,6 +95,7 @@ export const BaseItem: React.FC = (props) => { const shallowFormLayout = useFormShallowLayout() const { label, + style, layout, colon = true, addonBefore, @@ -117,8 +120,8 @@ export const BaseItem: React.FC = (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) { @@ -163,6 +166,7 @@ export const BaseItem: React.FC = (props) => { return (