2020-01-03 13:38:16 +08:00
|
|
|
---
|
|
|
|
order: 3.1
|
|
|
|
title:
|
|
|
|
zh-CN: 表单尺寸
|
|
|
|
en-US: Form size
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
设置表单组件尺寸,仅对 antd 组件有效。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
Set component size, only works for antd components.
|
|
|
|
|
|
|
|
```tsx
|
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
Cascader,
|
|
|
|
DatePicker,
|
2022-05-23 14:37:16 +08:00
|
|
|
Form,
|
|
|
|
Input,
|
2020-01-03 13:38:16 +08:00
|
|
|
InputNumber,
|
2022-05-23 14:37:16 +08:00
|
|
|
Radio,
|
|
|
|
Select,
|
2020-01-03 13:38:16 +08:00
|
|
|
Switch,
|
2022-05-23 14:37:16 +08:00
|
|
|
TreeSelect,
|
2020-01-03 13:38:16 +08:00
|
|
|
} from 'antd';
|
2022-05-23 14:37:16 +08:00
|
|
|
import React, { useState } from 'react';
|
2020-12-17 15:09:18 +08:00
|
|
|
|
|
|
|
type SizeType = Parameters<typeof Form>[0]['size'];
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const App: React.FC = () => {
|
2020-12-17 15:09:18 +08:00
|
|
|
const [componentSize, setComponentSize] = useState<SizeType | 'default'>('default');
|
2022-05-19 09:46:26 +08:00
|
|
|
|
2020-12-17 15:09:18 +08:00
|
|
|
const onFormLayoutChange = ({ size }: { size: SizeType }) => {
|
2020-01-03 13:38:16 +08:00
|
|
|
setComponentSize(size);
|
|
|
|
};
|
2022-05-19 09:46:26 +08:00
|
|
|
|
2020-01-03 13:38:16 +08:00
|
|
|
return (
|
2021-11-26 12:18:21 +08:00
|
|
|
<Form
|
|
|
|
labelCol={{ span: 4 }}
|
|
|
|
wrapperCol={{ span: 14 }}
|
|
|
|
layout="horizontal"
|
|
|
|
initialValues={{ size: componentSize }}
|
|
|
|
onValuesChange={onFormLayoutChange}
|
|
|
|
size={componentSize as SizeType}
|
|
|
|
>
|
|
|
|
<Form.Item label="Form Size" name="size">
|
|
|
|
<Radio.Group>
|
|
|
|
<Radio.Button value="small">Small</Radio.Button>
|
|
|
|
<Radio.Button value="default">Default</Radio.Button>
|
|
|
|
<Radio.Button value="large">Large</Radio.Button>
|
|
|
|
</Radio.Group>
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="Input">
|
|
|
|
<Input />
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="Select">
|
|
|
|
<Select>
|
|
|
|
<Select.Option value="demo">Demo</Select.Option>
|
|
|
|
</Select>
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="TreeSelect">
|
|
|
|
<TreeSelect
|
|
|
|
treeData={[
|
|
|
|
{ title: 'Light', value: 'light', children: [{ title: 'Bamboo', value: 'bamboo' }] },
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="Cascader">
|
|
|
|
<Cascader
|
|
|
|
options={[
|
|
|
|
{
|
|
|
|
value: 'zhejiang',
|
|
|
|
label: 'Zhejiang',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
value: 'hangzhou',
|
|
|
|
label: 'Hangzhou',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="DatePicker">
|
|
|
|
<DatePicker />
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="InputNumber">
|
|
|
|
<InputNumber />
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="Switch" valuePropName="checked">
|
|
|
|
<Switch />
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="Button">
|
|
|
|
<Button>Button</Button>
|
|
|
|
</Form.Item>
|
|
|
|
</Form>
|
2020-01-03 13:38:16 +08:00
|
|
|
);
|
|
|
|
};
|
2020-12-17 15:09:18 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
export default App;
|
2020-01-03 13:38:16 +08:00
|
|
|
```
|