Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ Insert an SVG icon. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/
- **Experimental:** true
- **Category:** media
- **Supports:** align (center, left, right), anchor, ariaLabel, color (background, text), dimensions (width), interactivity (clientNavigation), spacing (margin, padding), ~~html~~
- **Attributes:** icon, style
- **Attributes:** icon

## Image

Expand Down
5 changes: 5 additions & 0 deletions lib/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,11 @@
}
}
},
"core/icon": {
"dimensions": {
"width": "24px"
}
},
"core/site-logo": {
"variations": {
"rounded": {
Expand Down
8 changes: 0 additions & 8 deletions packages/block-library/src/icon/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@
"icon": {
"type": "string",
"role": "content"
},
"style": {
"type": "object",
"default": {
"dimensions": {
"width": "24px"
}
}
}
},
"supports": {
Expand Down
27 changes: 23 additions & 4 deletions packages/block-library/src/icon/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
ToolbarGroup,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
Placeholder,
} from '@wordpress/components';
import {
BlockControls,
Expand All @@ -29,6 +28,7 @@ import {
import { useSelect } from '@wordpress/data';
import { store as coreDataStore } from '@wordpress/core-data';
import { useState } from '@wordpress/element';
import { SVG, Rect, Path } from '@wordpress/primitives';

/**
* Internal dependencies
Expand All @@ -38,6 +38,26 @@ import HtmlRenderer from '../utils/html-renderer';
import { CustomInserterModal } from './components';
import { unlock } from '../lock-unlock';

const IconPlaceholder = ( { className, style } ) => (
<SVG
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 60 60"
preserveAspectRatio="none"
fill="none"
aria-hidden="true"
className={ clsx( 'wp-block-icon__placeholder', className ) }
style={ style }
>
<Rect width="60" height="60" fill="currentColor" fillOpacity={ 0.1 } />
<Path
vectorEffect="non-scaling-stroke"
stroke="currentColor"
strokeOpacity={ 0.25 }
d="M60 60 0 0"
/>
</SVG>
);

export function Edit( { attributes, setAttributes } ) {
const { icon, ariaLabel } = attributes;

Expand Down Expand Up @@ -165,8 +185,7 @@ export function Edit( { attributes, setAttributes } ) {
} }
/>
) : (
<Placeholder
withIllustration
<IconPlaceholder
className={ clsx(
borderProps.className,
spacingProps.className,
Expand All @@ -176,7 +195,7 @@ export function Edit( { attributes, setAttributes } ) {
...borderProps.style,
...spacingProps.style,
...dimensionsProps.style,
aspectRatio: '1',
height: 'auto',
Comment on lines 188 to +198

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Looking at packages/components/src/placeholder/index.tsx I don't see any benefit <Placeholder /> has given the props passed to it.

Kapture.2026-02-18.at.16.37.28.mp4

@andrewserong andrewserong Feb 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, my gut feeling is that the generalised Placeholder is a good component for more complex use cases than this block. But I imagine we can also iterate on the placeholder state further in follow-ups if need be.

} }
/>
) }
Expand Down
10 changes: 2 additions & 8 deletions packages/block-library/src/icon/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@
width: 250px;
}

// Provide special styling for the placeholder.
// @todo this particular minimal style of placeholder could be componentized further.
.wp-block-icon .components-placeholder {
padding: 0;
min-height: $grid-unit-30;
min-width: $grid-unit-30;
height: 100%;
width: 100%;
.wp-block-icon__placeholder {
backdrop-filter: blur(100px);
}
9 changes: 7 additions & 2 deletions packages/block-library/src/icon/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@

svg {
box-sizing: border-box;
width: 100%;
height: 100%;
fill: currentColor;
}
}

// Use :where() so these defaults have zero specificity and can be overridden
// by global styles, which target `.wp-block-icon svg` at higher specificity.
:where(.wp-block-icon) svg {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering what to do with the placeholder. I'm thinking it should behave similarly.

I don't have a good suggestion sorry.

Setting the width of .wp-block-icon .components-placeholder to 24px in editor.scss works for me. In a perfect world, we'd want to inherit from the global style .wp-block-icon svg, but I'm not sure that's doable unless we add a placeholder selector to block.json?

Image does this I believe

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually wondering if Placeholder is more complex than we need for this use case. I.e. we might be able to get away with just the svg of the placeholder rather than all its styles... I'll have a play

width: 100%;
height: 100%;
}
8 changes: 1 addition & 7 deletions test/integration/fixtures/blocks/core__icon.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
{
"name": "core/icon",
"isValid": true,
"attributes": {
"style": {
"dimensions": {
"width": "24px"
}
}
},
"attributes": {},
"innerBlocks": []
}
]
Loading