File size: 1,116 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
import { Gridicon } from '@automattic/components';
import { Button } from '@wordpress/components';
import clsx from 'clsx';
import { useTranslate } from 'i18n-calypso';
import React from 'react';

type Props = {
	showMainButtonLabel: boolean;
	mainButtonLabelText?: string;
	isMenuVisible: boolean;
	toggleMenu: () => void;
	popoverMenuContext: React.RefObject< HTMLButtonElement >;
};

const AddNewSiteButton: React.FC< Props > = ( {
	showMainButtonLabel,
	mainButtonLabelText,
	isMenuVisible,
	toggleMenu,
	popoverMenuContext,
} ) => {
	const translate = useTranslate();
	const mainButtonLabel = mainButtonLabelText || translate( 'Add sites' );

	return (
		<Button
			variant="secondary"
			ref={ popoverMenuContext }
			className="add-new-site__button"
			onClick={ toggleMenu }
		>
			<>
				{ showMainButtonLabel ? mainButtonLabel : null }
				<Gridicon
					className={ clsx(
						{ reverse: showMainButtonLabel && isMenuVisible },
						{ mobile: ! showMainButtonLabel }
					) }
					icon={ showMainButtonLabel ? 'chevron-down' : 'plus' }
				/>
			</>
		</Button>
	);
};

export default AddNewSiteButton;