Skip to content

Commit

Permalink
Page List: Update the icon to demonstrate that the pages are automati…
Browse files Browse the repository at this point in the history
…cally updated (#46438)

* Page List: Update the icon to demonstrate that the pages are automatically updated

* Allow a context to be passed to the block icon
  • Loading branch information
scruffian authored and dmsnell committed Dec 15, 2022
1 parent fefdd30 commit dd72ca6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
6 changes: 4 additions & 2 deletions packages/block-editor/src/components/block-icon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ import { Icon } from '@wordpress/components';
import { blockDefault } from '@wordpress/icons';
import { memo } from '@wordpress/element';

function BlockIcon( { icon, showColors = false, className } ) {
function BlockIcon( { icon, showColors = false, className, context } ) {
if ( icon?.src === 'block-default' ) {
icon = {
src: blockDefault,
};
}

const renderedIcon = <Icon icon={ icon && icon.src ? icon.src : icon } />;
const renderedIcon = (
<Icon icon={ icon && icon.src ? icon.src : icon } context={ context } />
);
const style = showColors
? {
backgroundColor: icon && icon.background,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ function ListViewBlockSelectButton(
aria-hidden={ true }
>
<ListViewExpander onClick={ onToggleExpanded } />
<BlockIcon icon={ blockInformation?.icon } showColors />
<BlockIcon
icon={ blockInformation?.icon }
showColors
context="list-view"
/>
<HStack
alignment="center"
className="block-editor-list-view-block-select-button__label-wrapper"
Expand Down
10 changes: 8 additions & 2 deletions packages/block-library/src/page-list/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { pages as icon } from '@wordpress/icons';
import { pages, update } from '@wordpress/icons';

/**
* Internal dependencies
Expand All @@ -15,7 +15,13 @@ const { name } = metadata;
export { metadata, name };

export const settings = {
icon,
icon: ( { context } ) => {
if ( context === 'list-view' ) {
return update;
}

return pages;
},
example: {},
edit,
};
Expand Down

0 comments on commit dd72ca6

Please sign in to comment.