File size: 1,914 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
import clsx from 'clsx';
import { localize } from 'i18n-calypso';
import { values } from 'lodash';
import PropTypes from 'prop-types';
import { Component } from 'react';
import SectionNav from 'calypso/components/section-nav';
import NavItem from 'calypso/components/section-nav/item';
import NavTabs from 'calypso/components/section-nav/tabs';
const noop = () => {};
export const SEARCH_TYPES = { POSTS: 'posts', SITES: 'sites' };
class SearchStreamHeader extends Component {
static propTypes = {
translate: PropTypes.func,
wideDisplay: PropTypes.bool,
selected: PropTypes.oneOf( values( SEARCH_TYPES ) ),
onSelection: PropTypes.func,
isLoggedIn: PropTypes.bool,
};
static defaultProps = {
onSelection: noop,
selected: SEARCH_TYPES.posts,
};
handlePostsSelected = () => this.props.onSelection( SEARCH_TYPES.POSTS );
handleSitesSelected = () => this.props.onSelection( SEARCH_TYPES.SITES );
render() {
const { translate, wideDisplay, selected, isLoggedIn } = this.props;
if ( wideDisplay ) {
return (
<ul
className={ clsx( 'search-stream__headers', {
'search-stream__headers-logged-out': ! isLoggedIn,
} ) }
>
<li className="search-stream__post-header">{ translate( 'Posts' ) }</li>
<li className="search-stream__site-header">{ translate( 'Sites' ) }</li>
</ul>
);
}
return (
<div className="search-stream__header">
<SectionNav>
<NavTabs>
<NavItem
key="posts-nav"
selected={ selected === SEARCH_TYPES.POSTS }
onClick={ this.handlePostsSelected }
>
{ translate( 'Posts' ) }
</NavItem>
<NavItem
key="sites-nav"
selected={ selected === SEARCH_TYPES.SITES }
onClick={ this.handleSitesSelected }
>
{ translate( 'Sites' ) }
</NavItem>
</NavTabs>
</SectionNav>
</div>
);
}
}
export default localize( SearchStreamHeader );
|