-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
menu-items.js
46 lines (42 loc) · 985 Bytes
/
menu-items.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
/**
* WordPress dependencies
*/
import { MenuItem, __experimentalText as Text } from '@wordpress/components';
import { check } from '@wordpress/icons';
/**
* Internal dependencies
*/
import useStylesForBlocks from './use-styles-for-block';
const noop = () => {};
export default function BlockStylesMenuItems( { clientId, onSwitch = noop } ) {
const { onSelect, stylesToRender, activeStyle } = useStylesForBlocks( {
clientId,
onSwitch,
} );
if ( ! stylesToRender || stylesToRender.length === 0 ) {
return null;
}
return (
<>
{ stylesToRender.map( ( style ) => {
const menuItemText = style.label || style.name;
return (
<MenuItem
key={ style.name }
icon={ activeStyle.name === style.name ? check : null }
onClick={ () => onSelect( style ) }
>
<Text
as="span"
limit={ 18 }
ellipsizeMode="tail"
truncate
>
{ menuItemText }
</Text>
</MenuItem>
);
} ) }
</>
);
}