-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
43 lines (38 loc) · 936 Bytes
/
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
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { Icon } from '@wordpress/components';
import { blockDefault } from '@wordpress/icons';
import { memo } from '@wordpress/element';
function BlockIcon( { icon, showColors = false, className } ) {
if ( icon?.src === 'block-default' ) {
icon = {
src: blockDefault,
};
}
const renderedIcon = <Icon icon={ icon && icon.src ? icon.src : icon } />;
const style = showColors
? {
backgroundColor: icon && icon.background,
color: icon && icon.foreground,
}
: {};
return (
<span
style={ style }
className={ classnames( 'block-editor-block-icon', className, {
'has-colors': showColors,
} ) }
>
{ renderedIcon }
</span>
);
}
/**
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/block-icon/README.md
*/
export default memo( BlockIcon );