🤖 Merge PR #45656 fix(@wordpress/blocks): add element type to normalized icon by @emilio-martinez

Icon declaration in registerBlockType should also allow for a plain React Element, as noted in the documentation. See https://developer.wordpress.org/block-editor/developers/block-api/block-registration/#icon-optional.
This commit is contained in:
Emilio Martinez 2020-06-23 11:38:25 -07:00 committed by GitHub
parent b42ab79e27
commit 25e743aea3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -7,7 +7,7 @@
import { Dashicon } from '@wordpress/components';
import { dispatch, select } from '@wordpress/data';
import { ComponentType } from 'react';
import { ComponentType, ReactElement } from 'react';
export * from './api';
export { withBlockContentContext } from './block-content-provider';
@ -29,7 +29,7 @@ export interface BlockIconNormalized {
background?: string;
foreground?: string;
shadowColor?: string;
src: Dashicon.Icon | ComponentType;
src: Dashicon.Icon | ReactElement | ComponentType;
}
export type BlockIcon = BlockIconNormalized['src'] | BlockIconNormalized;

View File

@ -311,6 +311,18 @@ blocks.registerBlockType('my/foo', {
category: 'common',
});
// $ExpectType Block<{}> | undefined
blocks.registerBlockType('my/foo', {
attributes: {},
icon: (
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<path fill="none" d="M0 0h24v24H0V0z" />
</svg>
),
title: 'Foo',
category: 'common',
});
// $ExpectType Block<{ foo: string; }> | undefined
blocks.registerBlockType<{ foo: string }>('my/foo', {
attributes: {