-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Dropdown): add support for allowAdditions (#356)
- Loading branch information
1 parent
4557289
commit ba1c9b3
Showing
4 changed files
with
333 additions
and
3 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
docs/app/Examples/modules/Dropdown/Types/AllowAdditions.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,72 @@ | ||
import React, { Component } from 'react' | ||
import { Dropdown, Grid, Header } from 'stardust' | ||
|
||
const options = [ | ||
{ text: 'English', value: 'English' }, | ||
{ text: 'French', value: 'French' }, | ||
{ text: 'Spanish', value: 'Spanish' }, | ||
{ text: 'German', value: 'German' }, | ||
{ text: 'Chinese', value: 'Chinese' }, | ||
] | ||
|
||
export default class AllowAdditionsExample extends Component { | ||
state = { optionsSingle: options, optionsMultiple: options } | ||
|
||
handleAdditionSingle = value => { | ||
// validate, save to server, show a message to the user ... | ||
this.setState({ | ||
optionsSingle: [{ text: value, value }, ...this.state.optionsSingle], | ||
}) | ||
} | ||
|
||
handleAdditionMultiple = value => { | ||
// validate, save to server, show a message to the user ... | ||
this.setState({ | ||
optionsMultiple: [{ text: value, value }, ...this.state.optionsMultiple], | ||
}) | ||
} | ||
|
||
handleChangeSingle = (e, value) => this.setState({ currentValue: value }) | ||
|
||
handleChangeMultiple = (e, values) => this.setState({ currentValues: values }) | ||
|
||
render() { | ||
const { currentValue, currentValues } = this.state | ||
|
||
return ( | ||
<Grid> | ||
<Grid.Column width={8}> | ||
<Header>Single Option</Header> | ||
<pre>Current value: {currentValue}</pre> | ||
<Dropdown | ||
options={this.state.optionsSingle} | ||
placeholder='Choose Language' | ||
search | ||
selection | ||
fluid | ||
allowAdditions | ||
onAddItem={this.handleAdditionSingle} | ||
onChange={this.handleChangeSingle} | ||
/> | ||
</Grid.Column> | ||
<Grid.Column width={8}> | ||
<Header>Multiple Options</Header> | ||
<pre>Current values: {JSON.stringify(currentValues)}</pre> | ||
<Dropdown | ||
options={this.state.optionsMultiple} | ||
placeholder='Choose Languages' | ||
search | ||
selection | ||
fluid | ||
multiple | ||
allowAdditions | ||
additionPosition='top' | ||
additionLabel='' | ||
onAddItem={this.handleAdditionMultiple} | ||
onChange={this.handleChangeMultiple} | ||
/> | ||
</Grid.Column> | ||
</Grid> | ||
) | ||
} | ||
} |
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
Oops, something went wrong.