/** * Styles */ import './style.scss'; /** * WordPress dependencies */ import classnames from 'classnames'; const { canvasBreakpoints, } = window; const { Component, createRef, } = wp.element; const { compose, } = wp.compose; const { withSelect, withDispatch, } = wp.data; /** * Component */ class ComponentResponsiveDropdown extends Component { constructor() { super( ...arguments ); this.state = { isOpened: false, }; this.componentRef = createRef(); this.handleClickOutside = this.handleClickOutside.bind(this); this.getButton = this.getButton.bind( this ); } componentDidMount() { document.addEventListener( 'mousedown', this.handleClickOutside ); } componentWillUnmount() { document.removeEventListener( 'mousedown', this.handleClickOutside ); } /** * Hide opened dropdown */ handleClickOutside( e ) { if ( this.componentRef && this.componentRef.current && this.componentRef.current.contains( e.target ) ) { return; } this.setState( { isOpened: false, } ); } /** * Get responsive button * * @param {string} name - breakpoint name. * @param {function} onClick - click callback * * @return {JSX} */ getButton( name, onClick ) { const { breakpoint, } = this.props; name = name || 'desktop'; if ( typeof canvasBreakpoints[ name ] === 'undefined' ) { return ''; } const info = canvasBreakpoints[ name ]; return (