@wordpress/block-editor
Version:
38 lines (33 loc) • 750 B
JavaScript
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { Icon } from '@wordpress/components';
import { blockDefault } from '@wordpress/icons';
export default 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>
);
}