-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #950 from oceanbase/dengfuping-dev
chore(design): Add form demo for Modal and Card
- Loading branch information
Showing
4 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React from 'react'; | ||
import { Button, Card, Form, Input } from '@oceanbase/design'; | ||
|
||
export default () => { | ||
const [form] = Form.useForm(); | ||
const { validateFields } = form; | ||
|
||
const handleSubmit = () => { | ||
validateFields().then(values => { | ||
const { name, age } = values; | ||
alert(`name: ${name}; age: ${age}`); | ||
}); | ||
}; | ||
|
||
return ( | ||
<Card> | ||
<Form layout="vertical" form={form} preserve={false}> | ||
<Form.Item | ||
name="name" | ||
label="Name" | ||
rules={[ | ||
{ | ||
required: true, | ||
message: 'Name is required', | ||
}, | ||
]} | ||
> | ||
<Input placeholder="name" /> | ||
</Form.Item> | ||
<Form.Item | ||
name="age" | ||
label="Age" | ||
rules={[ | ||
{ | ||
required: true, | ||
message: 'Age is required', | ||
}, | ||
]} | ||
> | ||
<Input placeholder="age" /> | ||
</Form.Item> | ||
<Form.Item style={{ marginBottom: 0 }}> | ||
<Button type="primary" onClick={handleSubmit}> | ||
Submit | ||
</Button> | ||
</Form.Item> | ||
</Form> | ||
</Card> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React, { useState } from 'react'; | ||
import { Button, Form, Input, Modal } from '@oceanbase/design'; | ||
|
||
export default () => { | ||
const [form] = Form.useForm(); | ||
const { validateFields } = form; | ||
|
||
const [open, setOpen] = useState(false); | ||
|
||
const handleSubmit = () => { | ||
validateFields().then(values => { | ||
const { name, age } = values; | ||
alert(`name: ${name}; age: ${age}`); | ||
}); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Button | ||
type="primary" | ||
onClick={() => { | ||
setOpen(true); | ||
}} | ||
> | ||
Open Modal | ||
</Button> | ||
<Modal | ||
open={open} | ||
title="Title" | ||
onOk={() => { | ||
handleSubmit(); | ||
}} | ||
onCancel={() => { | ||
setOpen(false); | ||
}} | ||
> | ||
<Form layout="vertical" form={form} preserve={false}> | ||
<Form.Item | ||
name="name" | ||
label="Name" | ||
rules={[ | ||
{ | ||
required: true, | ||
message: 'Name is required', | ||
}, | ||
]} | ||
> | ||
<Input placeholder="name" /> | ||
</Form.Item> | ||
<Form.Item | ||
name="age" | ||
label="Age" | ||
rules={[ | ||
{ | ||
required: true, | ||
message: 'Age is required', | ||
}, | ||
]} | ||
> | ||
<Input placeholder="age" /> | ||
</Form.Item> | ||
</Form> | ||
</Modal> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters