-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #379 from Automattic/add/sites-dropdown
Framework: Create new <SitesDropdown> component.
- Loading branch information
Showing
11 changed files
with
319 additions
and
45 deletions.
There are no files selected for viewing
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
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
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
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 /> | ||
); | ||
} | ||
``` |
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,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> | ||
); | ||
} | ||
} ); |
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,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: '', | ||
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> | ||
); | ||
} | ||
} ); |
Oops, something went wrong.