-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Use color panel for contentOnly pattern editing #71982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2b1d23f
a2c05bd
2ddd2f4
b095cbe
02794d2
9c9b8b9
133a9a9
0364031
e864e25
ffa1529
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,19 +3,69 @@ | |
| */ | ||
| import { PanelBody } from '@wordpress/components'; | ||
| import { __ } from '@wordpress/i18n'; | ||
| import { useDispatch, useSelect } from '@wordpress/data'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import BlockStyles from '../block-styles'; | ||
| import InspectorControls from '../inspector-controls'; | ||
| import { useBorderPanelLabel } from '../../hooks/border'; | ||
| import { useBlockSettings } from '../../hooks/utils'; | ||
| import { store as blockEditorStore } from '../../store'; | ||
| import { ColorEdit } from '../../hooks/color'; | ||
| import { ColorToolsPanel } from '../global-styles/color-panel'; | ||
|
|
||
| function SectionBlockColorControls( { | ||
| blockName, | ||
| clientId, | ||
| contentClientIds, | ||
| } ) { | ||
| const settings = useBlockSettings( blockName ); | ||
| const { updateBlockAttributes } = useDispatch( blockEditorStore ); | ||
|
|
||
| const { hasButton, hasHeading } = useSelect( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice touch. I was initially thinking to just show a defined subset, but it's fancier to detect the block! |
||
| ( select ) => { | ||
| const blockNames = | ||
| select( blockEditorStore ).getBlockNamesByClientId( | ||
| contentClientIds | ||
| ); | ||
| return { | ||
| hasButton: blockNames.includes( 'core/button' ), | ||
| hasHeading: blockNames.includes( 'core/heading' ), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about removing the control and the style when the element is deleted? From what I can see, if the element is deleted inside the pattern, the style control persists when a value is set. Kapture.2025-10-24.at.11.02.48.mp4I'm not sure it's a huge problem, so more of a UX question.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure we should be allowing deletion of elements in contentOnly!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
My understanding was also that things wouldn't be able to be deleted.
Either way, if we can delete, we should be able to undo to add it back. If we remove the set value, then they undo the change, I'd want the style to still be applied. So, I think leaving the value set is fine rather than removing it in this case. |
||
| }; | ||
| }, | ||
| [ contentClientIds ] | ||
| ); | ||
|
|
||
| const setAttributes = ( newAttributes ) => { | ||
| updateBlockAttributes( clientId, newAttributes ); | ||
| }; | ||
|
|
||
| return ( | ||
| <ColorEdit | ||
| clientId={ clientId } | ||
| name={ blockName } | ||
| settings={ settings } | ||
| setAttributes={ setAttributes } | ||
| asWrapper={ ColorToolsPanel } | ||
| label={ __( 'Color' ) } | ||
| defaultControls={ { | ||
| text: true, | ||
| background: true, | ||
| button: hasButton, | ||
| heading: hasHeading, | ||
| } } | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| const StylesTab = ( { | ||
| blockName, | ||
| clientId, | ||
| hasBlockStyles, | ||
| isSectionBlock, | ||
| contentClientIds, | ||
| } ) => { | ||
| const borderPanelLabel = useBorderPanelLabel( { blockName } ); | ||
|
|
||
|
|
@@ -28,6 +78,14 @@ const StylesTab = ( { | |
| </PanelBody> | ||
| </div> | ||
| ) } | ||
| { isSectionBlock && | ||
| window?.__experimentalContentOnlyPatternInsertion && ( | ||
| <SectionBlockColorControls | ||
| blockName={ blockName } | ||
| clientId={ clientId } | ||
| contentClientIds={ contentClientIds } | ||
| /> | ||
| ) } | ||
| { ! isSectionBlock && ( | ||
| <> | ||
| <InspectorControls.Slot | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,8 +4,8 @@ | |
| "isValid": true, | ||
| "attributes": { | ||
| "tagName": "div", | ||
| "className": "wp-block-comments-query-loop comments-post-extra", | ||
| "textColor": "luminous-vivid-orange" | ||
| "textColor": "luminous-vivid-orange", | ||
| "className": "wp-block-comments-query-loop comments-post-extra" | ||
|
Comment on lines
+7
to
+8
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These values all match, but are reordered. I'm not sure what caused this to be different. |
||
| }, | ||
| "innerBlocks": [ | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| <!-- wp:pullquote {"className":"has-background is-style-default","textColor":"subtle-background","style":{"border":{"color":"#2207d0"}}} --> | ||
| <!-- wp:pullquote {"textColor":"subtle-background","className":"has-background is-style-default","style":{"border":{"color":"#2207d0"}}} --> | ||
| <figure class="wp-block-pullquote has-background is-style-default has-border-color has-subtle-background-color has-text-color" style="border-color:#2207d0"><blockquote><p>Pullquote custom color</p><cite>my citation</cite></blockquote></figure> | ||
| <!-- /wp:pullquote --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linting