File size: 1,519 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 |
import { Popover } from '@automattic/components';
import { Button, Icon } from '@wordpress/components';
import { moreVertical } from '@wordpress/icons';
import clsx from 'clsx';
import { useRef } from 'react';
import usePopoverToggle from 'calypso/landing/subscriptions/hooks/use-popover-toggle';
import './styles.scss';
type SubscriptionsEllipsisMenuProps = {
children?: ( ( onClose: () => void ) => React.ReactNode ) | React.ReactNode;
popoverClassName?: string;
toggleTitle?: string;
verticalToggle?: boolean;
};
const SubscriptionsEllipsisMenu = ( {
children,
popoverClassName,
toggleTitle,
verticalToggle,
}: SubscriptionsEllipsisMenuProps ) => {
const { showPopover, onToggle, onClose } = usePopoverToggle();
const buttonRef = useRef< HTMLButtonElement >( null );
return (
<div className="subscriptions-ellipsis-menu">
<Button
className={ clsx( 'subscriptions-ellipsis-menu__toggle', {
'is-popover-visible': showPopover,
'has-vertical-toggle': verticalToggle,
} ) }
onClick={ onToggle }
ref={ buttonRef }
title={ toggleTitle }
icon={ <Icon icon={ moreVertical } size={ 24 } /> }
/>
<Popover
position="bottom left"
hideArrow
onClose={ onClose }
isVisible={ showPopover }
context={ buttonRef.current }
className={ clsx( 'subscriptions-ellipsis-menu__popover', popoverClassName ) }
>
{ typeof children === 'function' ? children( onClose ) : children }
</Popover>
</div>
);
};
export default SubscriptionsEllipsisMenu;
|