-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support full dropdown functionality #168
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
docs/app/Examples/modules/Dropdown/Content/AsyncOptions.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,48 @@ | ||
import _ from 'lodash' | ||
import cx from 'classnames' | ||
import faker from 'faker' | ||
import React, { Component } from 'react' | ||
import { Button, Dropdown } from 'stardust' | ||
|
||
const getOptions = () => _.times(3, () => { | ||
const name = faker.name.findName() | ||
return { text: name, value: _.snakeCase(name) } | ||
}) | ||
|
||
export default class DropdownAsyncOptions extends Component { | ||
state = { isFetching: false, value: [], options: [] } | ||
|
||
handleChange = value => this.setState({ value }) | ||
|
||
// fake api call | ||
fetchOptions = () => { | ||
this.setState({ isFetching: true }) | ||
|
||
setTimeout(() => { | ||
this.setState({ isFetching: false, options: getOptions() }) | ||
this.selectRandom() | ||
}, 500) | ||
} | ||
|
||
selectRandom = () => this.setState({ value: _.sample(this.state.options).value }) | ||
|
||
render() { | ||
const { options, isFetching, value } = this.state | ||
const classes = cx('search selection multiple', { 'disabled loading': isFetching }) | ||
|
||
return ( | ||
<div> | ||
<Button onClick={this.fetchOptions}>Fetch</Button> | ||
<Button onClick={this.selectRandom} disabled={_.isEmpty(options)}>Random</Button> | ||
<Dropdown | ||
defaultText='Add Users' | ||
className={classes} | ||
options={options} | ||
value={value} | ||
onChange={this.handleChange} | ||
/> | ||
<pre>{JSON.stringify(this.state, null, 2)}</pre> | ||
</div> | ||
) | ||
} | ||
} |
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,17 @@ | ||
import React, { Component } from 'react' | ||
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample' | ||
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection' | ||
|
||
export default class DropdownContentExamples extends Component { | ||
render() { | ||
return ( | ||
<ExampleSection title='Content'> | ||
<ComponentExample | ||
title='Async Options' | ||
description="A dropdown's options can change over time" | ||
examplePath='modules/Dropdown/Content/AsyncOptions' | ||
/> | ||
</ExampleSection> | ||
) | ||
} | ||
} |
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,16 @@ | ||
import React, { Component } from 'react' | ||
import Types from './Types/Types' | ||
import Content from './Content/Content' | ||
import States from './States/States' | ||
|
||
export default class DropdownExamples extends Component { | ||
render() { | ||
return ( | ||
<div> | ||
<Types /> | ||
<Content /> | ||
<States /> | ||
</div> | ||
) | ||
} | ||
} |
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,16 @@ | ||
import React, { Component } from 'react' | ||
import { Dropdown } from 'stardust' | ||
|
||
export default class DropdownDisabledExample extends Component { | ||
render() { | ||
return ( | ||
<Dropdown className='disabled' text='Dropdown'> | ||
<Dropdown.Menu> | ||
<Dropdown.Item text='Choice 1' /> | ||
<Dropdown.Item text='Choice 2' /> | ||
<Dropdown.Item text='Choice 3' /> | ||
</Dropdown.Menu> | ||
</Dropdown> | ||
) | ||
} | ||
} |
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,17 @@ | ||
import React, { Component } from 'react' | ||
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample' | ||
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection' | ||
|
||
export default class DropdownStatesExamples extends Component { | ||
render() { | ||
return ( | ||
<ExampleSection title='States'> | ||
<ComponentExample | ||
title='Disabled' | ||
description='A disabled dropdown menu or item does not allow user interaction' | ||
examplePath='modules/Dropdown/States/Disabled' | ||
/> | ||
</ExampleSection> | ||
) | ||
} | ||
} |
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,31 @@ | ||
import React, { Component } from 'react' | ||
import { Dropdown } from 'stardust' | ||
|
||
export default class DropdownDropdownExample extends Component { | ||
render() { | ||
return ( | ||
<Dropdown text='File' action='hide'> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you only want to show a menu, and not have the text update, set the correct Semantic UI action. In this case, we just hide the dropdown on select. This leaves the |
||
<Dropdown.Item text='New' /> | ||
<Dropdown.Item text='Open...' description='ctrl + o' /> | ||
<Dropdown.Item text='Save as...' description='ctrl + s' /> | ||
<Dropdown.Item text='Rename' description='ctrl + r' /> | ||
<Dropdown.Item text='Make a copy' /> | ||
<Dropdown.Item icon='trash' text='Move to trash' /> | ||
<Dropdown.Divider /> | ||
<Dropdown.Item text='Download As...' /> | ||
<Dropdown.Item text='Publish To Web'> | ||
<Dropdown.Menu> | ||
<Dropdown.Item text='Google Docs' /> | ||
<Dropdown.Item text='Google Drive' /> | ||
<Dropdown.Item text='Dropbox' /> | ||
<Dropdown.Item text='Adobe Creative Cloud' /> | ||
<Dropdown.Item text='Private FTP' /> | ||
<Dropdown.Item text='Another Service...' /> | ||
</Dropdown.Menu> | ||
</Dropdown.Item> | ||
{/* item text can also be defined as children */} | ||
<Dropdown.Item>E-mail Collaborators</Dropdown.Item> | ||
</Dropdown> | ||
) | ||
} | ||
} |
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,23 @@ | ||
import React, { Component } from 'react' | ||
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample' | ||
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection' | ||
import { Message } from 'stardust' | ||
|
||
export default class DropdownTypesExamples extends Component { | ||
render() { | ||
return ( | ||
<ExampleSection title='Types'> | ||
<ComponentExample | ||
title='Dropdown' | ||
description='A dropdown' | ||
examplePath='modules/Dropdown/Types/Dropdown' | ||
> | ||
<Message> | ||
Dropdown <code>children</code> are automatically wrapped in a | ||
{' '}<code>{`<Dropdown.Menu />`}</code> for convenience. | ||
</Message> | ||
</ComponentExample> | ||
</ExampleSection> | ||
) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't get this example to work. the Dropdown.Items don't show up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linking #346