-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
index.js
81 lines (73 loc) · 1.71 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// @ts-nocheck
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { cloneElement, forwardRef } from '@wordpress/element';
/**
* Internal dependencies
*/
import Shortcut from '../shortcut';
import Button from '../button';
import Icon from '../icon';
export function MenuItem( props, ref ) {
let {
children,
info,
className,
icon,
iconPosition = 'right',
shortcut,
isSelected,
role = 'menuitem',
suffix,
...buttonProps
} = props;
className = classnames( 'components-menu-item__button', className );
if ( info ) {
children = (
<span className="components-menu-item__info-wrapper">
<span className="components-menu-item__item">{ children }</span>
<span className="components-menu-item__info">{ info }</span>
</span>
);
}
if ( icon && typeof icon !== 'string' ) {
icon = cloneElement( icon, {
className: classnames( 'components-menu-items__item-icon', {
'has-icon-right': iconPosition === 'right',
} ),
} );
}
return (
<Button
ref={ ref }
// Make sure aria-checked matches spec https://www.w3.org/TR/wai-aria-1.1/#aria-checked
aria-checked={
role === 'menuitemcheckbox' || role === 'menuitemradio'
? isSelected
: undefined
}
role={ role }
icon={ iconPosition === 'left' ? icon : undefined }
className={ className }
{ ...buttonProps }
>
<span className="components-menu-item__item">{ children }</span>
{ ! suffix && (
<Shortcut
className="components-menu-item__shortcut"
shortcut={ shortcut }
/>
) }
{ ! suffix && icon && iconPosition === 'right' && (
<Icon icon={ icon } />
) }
{ suffix }
</Button>
);
}
export default forwardRef( MenuItem );