-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
index.tsx
63 lines (56 loc) · 1.33 KB
/
index.tsx
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
/**
* External dependencies
*/
import clsx from 'clsx';
/**
* WordPress dependencies
*/
import { Children } from '@wordpress/element';
import { useInstanceId } from '@wordpress/compose';
/**
* Internal dependencies
*/
import type { MenuGroupProps } from './types';
/**
* `MenuGroup` wraps a series of related `MenuItem` components into a common
* section.
*
* ```jsx
* import { MenuGroup, MenuItem } from '@wordpress/components';
*
* const MyMenuGroup = () => (
* <MenuGroup label="Settings">
* <MenuItem>Setting 1</MenuItem>
* <MenuItem>Setting 2</MenuItem>
* </MenuGroup>
* );
* ```
*/
export function MenuGroup( props: MenuGroupProps ) {
const { children, className = '', label, hideSeparator } = props;
const instanceId = useInstanceId( MenuGroup );
if ( ! Children.count( children ) ) {
return null;
}
const labelId = `components-menu-group-label-${ instanceId }`;
const classNames = clsx( className, 'components-menu-group', {
'has-hidden-separator': hideSeparator,
} );
return (
<div className={ classNames }>
{ label && (
<div
className="components-menu-group__label"
id={ labelId }
aria-hidden="true"
>
{ label }
</div>
) }
<div role="group" aria-labelledby={ label ? labelId : undefined }>
{ children }
</div>
</div>
);
}
export default MenuGroup;