File size: 1,024 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
import { Gridicon, Button } from '@automattic/components';
import { useState, useRef } from 'react';
import PopoverMenu from 'calypso/components/popover-menu';
import type { ReactElement } from 'react';

import './style.scss';

interface Props {
	renderActions: ( args: any ) => ReactElement;
	item: any;
}

export default function PluginCommonActions( { renderActions, item }: Props ) {
	const [ isOpen, setIsOpen ] = useState( false );

	const buttonActionRef = useRef< HTMLButtonElement | null >( null );

	const showActions = () => {
		setIsOpen( true );
	};

	const closeDropdown = () => {
		setIsOpen( false );
	};

	return (
		<>
			<Button borderless compact onClick={ showActions } ref={ buttonActionRef }>
				<Gridicon icon="ellipsis" size={ 18 } className="plugin-common-actions__all-actions" />
			</Button>
			<PopoverMenu
				context={ buttonActionRef.current }
				isVisible={ isOpen }
				onClose={ closeDropdown }
				position="bottom left"
			>
				{ renderActions( item ) }
			</PopoverMenu>
		</>
	);
}