-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
768eb0c
commit 8a025da
Showing
4 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
docs/app/Examples/collections/Form/Usage/FormExampleCaptureValues.js
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,38 @@ | ||
import React, { Component } from 'react' | ||
import { Form } from 'semantic-ui-react' | ||
|
||
class FormExampleCaptureValues extends Component { | ||
state = { name: '', email: '', submitted: { name: '', email: '' } } | ||
|
||
handleChange = (e, { name, value }) => this.setState({ [name]: value }) | ||
|
||
handleSubmit = e => { | ||
e.preventDefault() | ||
const state = { ...this.state } | ||
delete state.submitted | ||
|
||
this.setState({ submitted: state }) | ||
} | ||
|
||
render() { | ||
const { name, email, submitted } = this.state | ||
|
||
return ( | ||
<div> | ||
<Form onSubmit={this.handleSubmit}> | ||
<Form.Group> | ||
<Form.Input placeholder='Name' name='name' value={name} onChange={this.handleChange} /> | ||
<Form.Input placeholder='Email' name='email' value={email} onChange={this.handleChange} /> | ||
<Form.Button content='Submit' /> | ||
</Form.Group> | ||
</Form> | ||
<strong>onChange:</strong> | ||
<pre>{JSON.stringify({ name, email }, null, 2)}</pre> | ||
<strong>onSubmit:</strong> | ||
<pre>{JSON.stringify(submitted, null, 2)}</pre> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
export default FormExampleCaptureValues |
29 changes: 29 additions & 0 deletions
29
docs/app/Examples/collections/Form/Usage/FormExampleClearOnSubmit.js
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,29 @@ | ||
import React, { Component } from 'react' | ||
import { Form } from 'semantic-ui-react' | ||
|
||
class FormExampleClearOnSubmit extends Component { | ||
state = {} | ||
|
||
handleChange = (e, { name, value }) => this.setState({ [name]: value }) | ||
|
||
handleSubmit = e => { | ||
e.preventDefault() | ||
this.setState({ email: '', name: '' }) | ||
} | ||
|
||
render() { | ||
const { name, email } = this.state | ||
|
||
return ( | ||
<Form onSubmit={this.handleSubmit}> | ||
<Form.Group> | ||
<Form.Input placeholder='Name' name='name' value={name} onChange={this.handleChange} /> | ||
<Form.Input placeholder='Email' name='email' value={email} onChange={this.handleChange} /> | ||
<Form.Button content='Submit' /> | ||
</Form.Group> | ||
</Form> | ||
) | ||
} | ||
} | ||
|
||
export default FormExampleClearOnSubmit |
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,36 @@ | ||
import React from 'react' | ||
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection' | ||
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample' | ||
|
||
import { Message, Icon } from 'src' | ||
|
||
const FormFormUsageExamples = () => ( | ||
<ExampleSection title='Usage'> | ||
<Message info icon> | ||
<Icon name='pointing right' /> | ||
<Message.Content> | ||
<Message.Header>Tip</Message.Header> | ||
<p> | ||
Our <code>{'<Form />'}</code> handles data just like a vanilla React <code>{'<form />'}</code>. | ||
See React's | ||
<a href='https://facebook.github.io/react/docs/forms.html#controlled-components' target='_blank'> | ||
{' '}controlled components{' '} | ||
</a> | ||
docs for more. | ||
</p> | ||
</Message.Content> | ||
</Message> | ||
<ComponentExample | ||
title='Capture Values' | ||
description='You can capture form data on change or on submit.' | ||
examplePath='collections/Form/Usage/FormExampleCaptureValues' | ||
/> | ||
<ComponentExample | ||
title='Clear On Submit' | ||
description='You can clear form values on submit.' | ||
examplePath='collections/Form/Usage/FormExampleClearOnSubmit' | ||
/> | ||
</ExampleSection> | ||
) | ||
|
||
export default FormFormUsageExamples |
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