/
index.js
67 lines (60 loc) · 1.37 KB
/
index.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* External dependencies
*/
import classnames from 'classnames';
import { isString } from 'lodash';
/**
* WordPress dependencies
*/
import { cloneElement } from '@wordpress/element';
/**
* Internal dependencies
*/
import Button from '../button';
import Shortcut from '../shortcut';
import IconButton from '../icon-button';
/**
* Renders a generic menu item for use inside the more menu.
*
* @return {WPElement} More menu item.
*/
function MenuItem( { children, className, icon, onClick, shortcut, isSelected, role = 'menuitem', ...props } ) {
className = classnames( 'components-menu-item__button', className, {
'has-icon': icon,
} );
if ( icon ) {
if ( ! isString( icon ) ) {
icon = cloneElement( icon, {
className: 'components-menu-items__item-icon',
height: 20,
width: 20,
} );
}
return (
<IconButton
className={ className }
icon={ icon }
onClick={ onClick }
aria-checked={ isSelected }
role={ role }
{ ...props }
>
{ children }
<Shortcut className="components-menu-item__shortcut" shortcut={ shortcut } />
</IconButton>
);
}
return (
<Button
className={ className }
onClick={ onClick }
aria-checked={ isSelected }
role={ role }
{ ...props }
>
{ children }
<Shortcut className="components-menu-item__shortcut" shortcut={ shortcut } />
</Button>
);
}
export default MenuItem;