2018-05-14 15:47:42 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { Component } from '@wordpress/element';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import { IconButton, Dropdown, NavigableMenu } from '@wordpress/components';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
|
|
|
|
2018-08-31 17:27:21 +00:00
|
|
|
/**
|
|
|
|
* This is a dropdown menu hidden behind a vertical ellipsis icon. When clicked, the inner MenuItems are displayed.
|
|
|
|
*/
|
2018-05-14 15:47:42 +00:00
|
|
|
class EllipsisMenu extends Component {
|
|
|
|
render() {
|
|
|
|
const { children, label } = this.props;
|
|
|
|
if ( ! children ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const renderToggle = ( { onToggle, isOpen } ) => {
|
2018-06-01 14:35:18 +00:00
|
|
|
const toggleClassname = classnames( 'woocommerce-ellipsis-menu__toggle', {
|
2018-05-14 15:47:42 +00:00
|
|
|
'is-opened': isOpen,
|
|
|
|
} );
|
|
|
|
|
|
|
|
return (
|
|
|
|
<IconButton
|
|
|
|
className={ toggleClassname }
|
|
|
|
onClick={ onToggle }
|
|
|
|
icon="ellipsis"
|
|
|
|
label={ label }
|
|
|
|
aria-expanded={ isOpen }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const renderContent = () => (
|
2018-06-01 14:35:18 +00:00
|
|
|
<NavigableMenu className="woocommerce-ellipsis-menu__content">{ children }</NavigableMenu>
|
2018-05-14 15:47:42 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
2018-06-01 14:35:18 +00:00
|
|
|
<div className="woocommerce-ellipsis-menu">
|
2018-05-14 15:47:42 +00:00
|
|
|
<Dropdown
|
2018-06-01 14:35:18 +00:00
|
|
|
contentClassName="woocommerce-ellipsis-menu__popover"
|
2018-05-14 15:47:42 +00:00
|
|
|
position="bottom left"
|
|
|
|
renderToggle={ renderToggle }
|
|
|
|
renderContent={ renderContent }
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EllipsisMenu.propTypes = {
|
2018-08-31 17:27:21 +00:00
|
|
|
/**
|
|
|
|
* The label shown when hovering/focusing on the icon button.
|
|
|
|
*/
|
2018-05-14 15:47:42 +00:00
|
|
|
label: PropTypes.string.isRequired,
|
2018-08-31 17:27:21 +00:00
|
|
|
/**
|
|
|
|
* A list of `MenuTitle`/`MenuItem` components
|
|
|
|
*/
|
|
|
|
children: PropTypes.node,
|
2018-05-14 15:47:42 +00:00
|
|
|
};
|
|
|
|
|
2018-08-31 17:19:13 +00:00
|
|
|
export default EllipsisMenu;
|