-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Framework: Create new <SitesDropdown> component. #379
Changes from all commits
d6d84de
0440da8
f713ade
53d9646
57cf9fa
53a8a73
5be7f09
bc46a72
e087e15
888e7f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Sites Dropdown | ||
============== | ||
|
||
Renders a dropdown component for selecting a site. This is the canonical site picker component for using whenever you need to offer users a site selection flow. | ||
|
||
It support searching if you have many sites, handles sites with empty titles, sites with redirects, etc. | ||
|
||
#### How to use: | ||
|
||
```js | ||
import SitesDropdown 'components/sites-dropdown'; | ||
|
||
render() { | ||
return ( | ||
<SitesDropdown /> | ||
); | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React from 'react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import SitesDropdown from 'components/sites-dropdown'; | ||
|
||
export default React.createClass( { | ||
|
||
displayName: 'SitesDropdownExample', | ||
|
||
render: function() { | ||
return ( | ||
<div className="design-assets__group"> | ||
<h2> | ||
<a href="/devdocs/design/sites-dropdown">SitesDropdown</a> | ||
</h2> | ||
<SitesDropdown /> | ||
</div> | ||
); | ||
} | ||
} ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import noop from 'lodash/utility/noop'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Site from 'my-sites/site'; | ||
import SiteSelector from 'components/site-selector'; | ||
import sitesList from 'lib/sites-list'; | ||
import Gridicon from 'components/gridicon'; | ||
|
||
const sites = sitesList(); | ||
|
||
export default React.createClass( { | ||
|
||
displayName: 'SitesDropdown', | ||
|
||
mixins: [ React.addons.PureRenderMixin ], | ||
|
||
propTypes: { | ||
selected: React.PropTypes.oneOfType( [ | ||
React.PropTypes.number, | ||
React.PropTypes.string | ||
] ), | ||
showAllSites: React.PropTypes.bool, | ||
indicator: React.PropTypes.bool, | ||
autoFocus: React.PropTypes.bool, | ||
onClose: React.PropTypes.func, | ||
onSiteSelect: React.PropTypes.func | ||
}, | ||
|
||
getDefaultProps() { | ||
return { | ||
showAllSites: false, | ||
indicator: false, | ||
onClose: noop, | ||
onSiteSelect: noop | ||
}; | ||
}, | ||
|
||
getInitialState() { | ||
return { | ||
search: '', | ||
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. Post-merge comment -- do we need 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. I'll remove it in #1483. 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. 👍 |
||
selected: this.props.selected || sites.getPrimary().slug | ||
}; | ||
}, | ||
|
||
getSelectedSite() { | ||
return sites.getSite( this.state.selected ); | ||
}, | ||
|
||
selectSite( siteSlug ) { | ||
this.props.onSiteSelect( siteSlug ); | ||
this.setState( { | ||
selected: siteSlug, | ||
open: false | ||
} ); | ||
}, | ||
|
||
render() { | ||
return ( | ||
<div className={ classNames( 'sites-dropdown', { 'is-open': this.state.open } ) }> | ||
<div className="sites-dropdown__wrapper"> | ||
<div | ||
className="sites-dropdown__selected" | ||
onClick={ () => this.setState( { open: ! this.state.open } ) } | ||
> | ||
<Site | ||
site={ this.getSelectedSite() } | ||
indicator={ false } | ||
/> | ||
<Gridicon icon="chevron-down" /> | ||
</div> | ||
{ this.state.open && | ||
<SiteSelector | ||
sites={ sites } | ||
autoFocus={ true } | ||
onClose={ this.props.onClose } | ||
onSiteSelect={ this.selectSite } | ||
selected={ this.state.selected } | ||
hideSelected={ true } | ||
/> | ||
} | ||
</div> | ||
</div> | ||
); | ||
} | ||
} ); |
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.
Could you add this to z-index map?
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.
Ah, good call.