You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
2.3 KiB
100 lines
2.3 KiB
5 years ago
|
---
|
||
|
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 {
|
||
|
Form,
|
||
|
Input,
|
||
|
Button,
|
||
|
Radio,
|
||
|
Select,
|
||
|
Cascader,
|
||
|
DatePicker,
|
||
|
InputNumber,
|
||
|
TreeSelect,
|
||
|
Switch,
|
||
|
} from 'antd';
|
||
|
const FormSizeDemo = () => {
|
||
|
const [componentSize, setComponentSize] = React.useState('small');
|
||
|
const onFormLayoutChange = ({ size }) => {
|
||
|
setComponentSize(size);
|
||
|
};
|
||
|
return (
|
||
|
<div>
|
||
|
<Form
|
||
|
labelCol={{ span: 4 }}
|
||
|
wrapperCol={{ span: 14 }}
|
||
|
layout="horizontal"
|
||
|
initialValues={{ size: componentSize }}
|
||
|
onValuesChange={onFormLayoutChange}
|
||
|
size={componentSize}
|
||
|
>
|
||
|
<Form.Item label="Form Size" name="size">
|
||
|
<Radio.Group>
|
||
|
<Radio.Button value="small">Small</Radio.Button>
|
||
|
<Radio.Button value="middle">Middle</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">
|
||
|
<Switch />
|
||
|
</Form.Item>
|
||
|
<Form.Item label="Button">
|
||
|
<Button>Button</Button>
|
||
|
</Form.Item>
|
||
|
</Form>
|
||
|
</div>
|
||
|
);
|
||
|
};
|
||
|
ReactDOM.render(<FormSizeDemo />, mountNode);
|
||
|
```
|