| 1 |
/** |
| 2 |
* WordPress deendencies. |
| 3 |
*/ |
| 4 |
import { useContext, WPElement } from '@wordpress/element'; |
| 5 |
import { chevronDown, chevronUp, Icon } from '@wordpress/icons'; |
| 6 |
import { __ } from '@wordpress/i18n'; |
| 7 |
|
| 8 |
/** |
| 9 |
* Internal deendencies. |
| 10 |
*/ |
| 11 |
import Context from '../../context'; |
| 12 |
|
| 13 |
/** |
| 14 |
* Open sidebar component. |
| 15 |
* |
| 16 |
* @returns {WPElement} Element. |
| 17 |
*/ |
| 18 |
export default () => { |
| 19 |
const { |
| 20 |
state: { isSidebarOpen }, |
| 21 |
dispatch, |
| 22 |
} = useContext(Context); |
| 23 |
|
| 24 |
/** |
| 25 |
* Handle click. |
| 26 |
*/ |
| 27 |
const onClick = () => { |
| 28 |
dispatch({ type: 'TOGGLE_SIDEBAR' }); |
| 29 |
}; |
| 30 |
|
| 31 |
return ( |
| 32 |
<button |
| 33 |
aria-expanded={isSidebarOpen} |
| 34 |
className="ep-search-sidebar-toggle ep-search-icon-button" |
| 35 |
onClick={onClick} |
| 36 |
type="button" |
| 37 |
> |
| 38 |
{isSidebarOpen |
| 39 |
? __('Close filters', 'elasticpress') |
| 40 |
: __('All filters', 'elasticoress')} |
| 41 |
|
| 42 |
<Icon icon={isSidebarOpen ? chevronUp : chevronDown} /> |
| 43 |
</button> |
| 44 |
); |
| 45 |
}; |
| 46 |
|