ant-design/components/drawer/demo/from-drawer.md

142 lines
4.4 KiB
Markdown
Raw Normal View History

2018-06-03 22:00:27 +08:00
---
order: 0
title:
2018-06-06 22:55:29 +08:00
zh-CN: 表单抽屉
en-US: from drawer
2018-06-03 22:00:27 +08:00
---
## zh-CN
展示用户的详细信息
## en-US
Display user details
```jsx
import { Drawer, Form, Button, Col, Row, Input, Select, DatePicker } from 'antd';
const { Option } = Select;
class App extends React.Component {
state = { visible: false };
showDrawer = () => {
this.setState({
visible: !this.state.visible,
});
};
onClose = () => {
this.setState({
visible: false,
});
};
render() {
const { getFieldDecorator } = this.props.form;
return (
<div>
<Button type="primary" onClick={this.showDrawer}>
Create
</Button>
<Drawer
title="Create"
width={720}
placement="right"
onClose={this.onClose}
visible={this.state.visible}
>
<Form layout="vertical" hideRequiredMark>
<Row gutter={16}>
<Col span={12}>
2018-06-06 22:55:29 +08:00
<Form.Item label="Name">
2018-06-03 22:00:27 +08:00
{getFieldDecorator('name', {
2018-06-06 22:55:29 +08:00
rules: [{ required: true, message: 'please enter user name' }],
})(<Input placeholder="please enter user name" />)}
2018-06-03 22:00:27 +08:00
</Form.Item>
</Col>
<Col span={12}>
2018-06-06 22:55:29 +08:00
<Form.Item label="Url">
2018-06-03 22:00:27 +08:00
{getFieldDecorator('url', {
2018-06-06 22:55:29 +08:00
rules: [{ required: true, message: 'please enter url' }],
2018-06-03 22:00:27 +08:00
})(
<Input
style={{ width: '100%' }}
addonBefore="http://"
addonAfter=".com"
2018-06-06 22:55:29 +08:00
placeholder="please enter url"
2018-06-03 22:00:27 +08:00
/>
)}
</Form.Item>
</Col>
</Row>
<Row gutter={16}>
<Col span={12}>
2018-06-06 22:55:29 +08:00
<Form.Item label="Owner">
2018-06-03 22:00:27 +08:00
{getFieldDecorator('owner', {
2018-06-06 22:55:29 +08:00
rules: [{ required: true, message: 'Please select an owner' }],
2018-06-03 22:00:27 +08:00
})(
2018-06-06 22:55:29 +08:00
<Select placeholder="Please select an owner">
<Option value="xiao">Xiaoxiao Fu</Option>
<Option value="mao">Maomao Zhou</Option>
2018-06-03 22:00:27 +08:00
</Select>
)}
</Form.Item>
</Col>
<Col span={12}>
2018-06-06 22:55:29 +08:00
<Form.Item label="Type">
2018-06-03 22:00:27 +08:00
{getFieldDecorator('type', {
2018-06-06 22:55:29 +08:00
rules: [{ required: true, message: 'Please choose the type' }],
2018-06-03 22:00:27 +08:00
})(
2018-06-06 22:55:29 +08:00
<Select placeholder="Please choose the type">
<Option value="private">Private</Option>
<Option value="public">Public</Option>
2018-06-03 22:00:27 +08:00
</Select>
)}
</Form.Item>
</Col>
</Row>
<Row gutter={16}>
<Col span={12}>
2018-06-06 22:55:29 +08:00
<Form.Item label="Approver">
2018-06-03 22:00:27 +08:00
{getFieldDecorator('approver', {
2018-06-06 22:55:29 +08:00
rules: [{ required: true, message: 'Please choose the approver' }],
2018-06-03 22:00:27 +08:00
})(
2018-06-06 22:55:29 +08:00
<Select placeholder="Please choose the approver">
<Option value="jack">Jack Ma</Option>
<Option value="tom">Tom Liu</Option>
2018-06-03 22:00:27 +08:00
</Select>
)}
</Form.Item>
</Col>
<Col span={12}>
2018-06-06 22:55:29 +08:00
<Form.Item label="DateTime">
2018-06-03 22:00:27 +08:00
{getFieldDecorator('dateTime', {
2018-06-06 22:55:29 +08:00
rules: [{ required: true, message: 'Please choose the dateTime' }],
2018-06-03 22:00:27 +08:00
})(
<DatePicker.RangePicker
style={{ width: '100%' }}
getPopupContainer={trigger => trigger.parentNode}
/>
)}
</Form.Item>
</Col>
</Row>
<Row gutter={16}>
<Col span={24}>
2018-06-06 22:55:29 +08:00
<Form.Item label="description">
{getFieldDecorator('description', {
rules: [{ required: true, message: 'please enter url description' }],
})(<Input.TextArea rows={4} placeholder="please enter url description" />)}
2018-06-03 22:00:27 +08:00
</Form.Item>
</Col>
</Row>
</Form>
</Drawer>
</div>
);
}
}
const WarpApp = Form.create()(App);
ReactDOM.render(<WarpApp />, mountNode);
```