Skip to content
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 1 commit into from
Mar 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions docs/app/Examples/modules/Dropdown/Content/AsyncOptions.js
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>
)
}
}
17 changes: 17 additions & 0 deletions docs/app/Examples/modules/Dropdown/Content/Content.js
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>
)
}
}
16 changes: 16 additions & 0 deletions docs/app/Examples/modules/Dropdown/DropdownExamples.js
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>
)
}
}
16 changes: 16 additions & 0 deletions docs/app/Examples/modules/Dropdown/States/Disabled.js
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' />
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linking #346

<Dropdown.Item text='Choice 2' />
<Dropdown.Item text='Choice 3' />
</Dropdown.Menu>
</Dropdown>
)
}
}
17 changes: 17 additions & 0 deletions docs/app/Examples/modules/Dropdown/States/States.js
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>
)
}
}
31 changes: 31 additions & 0 deletions docs/app/Examples/modules/Dropdown/Types/Dropdown.js
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'>
Copy link
Member Author

Choose a reason for hiding this comment

The 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 File text in the dropdown space so it looks and works like a normal dropdown menu (not a selection dropdown).

<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>
)
}
}
23 changes: 23 additions & 0 deletions docs/app/Examples/modules/Dropdown/Types/Types.js
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>
)
}
}
Loading