-
Notifications
You must be signed in to change notification settings - Fork 58
fix: remove colour label changes to avoid bleeding into other blocks #4703
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
f186960
1c8a490
dc07ebf
d2cd993
35e8c87
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 |
|---|---|---|
|
|
@@ -2,7 +2,17 @@ | |
| * WordPress dependencies | ||
| */ | ||
| import { useContext, useEffect, useMemo, useRef, useState } from '@wordpress/element'; | ||
| import { BlockControls, useBlockProps, useInnerBlocksProps, InspectorControls } from '@wordpress/block-editor'; | ||
| import { | ||
| BlockControls, | ||
| useBlockProps, | ||
| useInnerBlocksProps, | ||
| InspectorControls, | ||
| withColors, | ||
| // eslint-disable-next-line @wordpress/no-unsafe-wp-apis | ||
| __experimentalColorGradientSettingsDropdown as ColorGradientSettingsDropdown, | ||
| // eslint-disable-next-line @wordpress/no-unsafe-wp-apis | ||
| __experimentalUseMultipleOriginColorsAndGradients as useMultipleOriginColorsAndGradients, | ||
| } from '@wordpress/block-editor'; | ||
| import { PanelBody, SelectControl, Button, ToolbarButton, ToolbarGroup, Tooltip } from '@wordpress/components'; | ||
| import { useSelect, useDispatch } from '@wordpress/data'; | ||
| import { __ } from '@wordpress/i18n'; | ||
|
|
@@ -28,91 +38,63 @@ const fetchAllServiceKeys = () => { | |
| return allServiceKeysCache; | ||
| }; | ||
|
|
||
| const presetToVar = value => { | ||
| if ( typeof value !== 'string' ) { | ||
| return value; | ||
| } | ||
| return value.replace( /^var:preset\|([^|]+)\|(.+)$/, 'var(--wp--preset--$1--$2)' ); | ||
| }; | ||
|
|
||
| const resolveColor = ( presetSlug, customValue ) => { | ||
| if ( presetSlug ) { | ||
| return `var(--wp--preset--color--${ presetSlug })`; | ||
| } | ||
| if ( typeof customValue === 'string' ) { | ||
| return presetToVar( customValue ) || customValue; | ||
| } | ||
| return undefined; | ||
| }; | ||
|
|
||
| /** | ||
| * Edit component for the Author Social Links inner block. | ||
| * | ||
| * @param {Object} props Block props. | ||
| * @param {Object} props.attributes Block attributes. | ||
| * @param {Function} props.setAttributes Function to update attributes. | ||
| * @param {string} props.clientId Block client ID. | ||
| * @param {Object} props Block props. | ||
| * @param {Object} props.attributes Block attributes. | ||
| * @param {Function} props.setAttributes Function to update attributes. | ||
| * @param {string} props.clientId Block client ID. | ||
| * @param {Object} props.iconColor Resolved icon color (from withColors). | ||
| * @param {Function} props.setIconColor Setter for icon color (from withColors). | ||
| * @param {Object} props.iconBackgroundColor Resolved icon background color (from withColors). | ||
| * @param {Function} props.setIconBackgroundColor Setter for icon background color (from withColors). | ||
| * @return {JSX.Element} The edit component. | ||
| */ | ||
| export default function Edit( { attributes, setAttributes, clientId } ) { | ||
| function Edit( { attributes, setAttributes, clientId, iconColor, setIconColor, iconBackgroundColor, setIconBackgroundColor } ) { | ||
| const AuthorContext = getSharedAuthorContext(); | ||
| const author = useContext( AuthorContext ); | ||
| const { iconSize, style: styleAttr, textColor, backgroundColor, className } = attributes; | ||
| const { iconSize, iconColorValue, iconBackgroundColorValue, className } = attributes; | ||
| const hasPopulated = useRef( false ); | ||
| const [ allServiceKeys, setAllServiceKeys ] = useState( null ); // null = loading | ||
|
|
||
| const isBrand = ( className || '' ).split( ' ' ).includes( 'is-style-brand' ); | ||
| const iconSizeValue = typeof iconSize === 'number' ? iconSize : parseInt( iconSize ?? 24, 10 ) || 24; | ||
| const iconColor = ! isBrand ? resolveColor( textColor, styleAttr?.color?.text ) : undefined; | ||
| const iconBackground = ! isBrand ? resolveColor( backgroundColor, styleAttr?.color?.background ) : undefined; | ||
|
|
||
| // Hide color panel when "Brand" is active; rename labels when "Default". | ||
| useEffect( () => { | ||
| const sidebar = document.querySelector( '.interface-complementary-area' ); | ||
| if ( ! sidebar ) { | ||
| return; | ||
| } | ||
|
|
||
| const COLOR_LABEL_MAP = { | ||
| Text: __( 'Icon color', 'newspack-plugin' ), | ||
| Background: __( 'Icon background', 'newspack-plugin' ), | ||
| }; | ||
|
|
||
| const updateColorPanel = container => { | ||
| container.querySelectorAll( '.color-block-support-panel' ).forEach( el => { | ||
| el.style.display = isBrand ? 'none' : ''; | ||
| } ); | ||
|
|
||
| if ( isBrand ) { | ||
| return; | ||
| } | ||
|
|
||
| container.querySelectorAll( '.block-editor-panel-color-gradient-settings__color-name' ).forEach( el => { | ||
| if ( COLOR_LABEL_MAP[ el.textContent ] ) { | ||
| el.textContent = COLOR_LABEL_MAP[ el.textContent ]; | ||
| } | ||
| } ); | ||
| container.querySelectorAll( '.components-menu-item__item' ).forEach( el => { | ||
| if ( COLOR_LABEL_MAP[ el.textContent ] ) { | ||
| el.textContent = COLOR_LABEL_MAP[ el.textContent ]; | ||
| } | ||
| } ); | ||
| }; | ||
|
|
||
| updateColorPanel( sidebar ); | ||
|
|
||
| const observer = new MutationObserver( () => updateColorPanel( sidebar ) ); | ||
| observer.observe( sidebar, { childList: true, subtree: true } ); | ||
|
|
||
| return () => observer.disconnect(); | ||
| }, [ isBrand ] ); | ||
| const resolvedIconColor = ! isBrand ? iconColor?.color || iconColorValue : undefined; | ||
| const resolvedIconBackground = ! isBrand ? iconBackgroundColor?.color || iconBackgroundColorValue : undefined; | ||
|
laurelfulford marked this conversation as resolved.
|
||
|
|
||
| // Color panel is hidden entirely when the "Brand" style is active — | ||
| // brand uses each service's own colors, so neither icon nor background | ||
| // apply. The settings render as ToolsPanelItems directly inside the | ||
| // Styles tab's Color slot, so they integrate with WP's native panel | ||
| // (no nested panel-in-a-panel). | ||
| const colorGradientSettings = useMultipleOriginColorsAndGradients(); | ||
| const colorSettings = [ | ||
| { | ||
| colorValue: iconColor?.color || iconColorValue, | ||
| onColorChange: value => { | ||
| setIconColor( value ); | ||
| setAttributes( { iconColorValue: value } ); | ||
| }, | ||
| label: __( 'Icon color', 'newspack-plugin' ), | ||
| }, | ||
| { | ||
| colorValue: iconBackgroundColor?.color || iconBackgroundColorValue, | ||
| onColorChange: value => { | ||
| setIconBackgroundColor( value ); | ||
| setAttributes( { iconBackgroundColorValue: value } ); | ||
| }, | ||
| label: __( 'Icon background', 'newspack-plugin' ), | ||
| }, | ||
| ]; | ||
|
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. Suggestion: Worth manually confirming that picking a theme preset colour writes to
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. Good call! Looks like it does -- I got both |
||
|
|
||
| const blockProps = useBlockProps( { | ||
| className: 'author-profile-social__list', | ||
| style: { | ||
| '--icon-size': `${ roundIconSize( iconSizeValue ) }px`, | ||
| ...( iconColor && { '--icon-color': iconColor } ), | ||
| ...( iconBackground && { '--icon-background': iconBackground } ), | ||
| ...( resolvedIconColor && { '--icon-color': resolvedIconColor } ), | ||
| ...( resolvedIconBackground && { '--icon-background': resolvedIconBackground } ), | ||
| }, | ||
| } ); | ||
|
|
||
|
|
@@ -201,7 +183,17 @@ export default function Edit( { attributes, setAttributes, clientId } ) { | |
| ) } | ||
| </PanelBody> | ||
| </InspectorControls> | ||
| { ! isBrand && ( | ||
| <InspectorControls group="color"> | ||
| <ColorGradientSettingsDropdown settings={ colorSettings } panelId={ clientId } { ...colorGradientSettings } /> | ||
| </InspectorControls> | ||
| ) } | ||
| <ul { ...innerBlocksProps } /> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| export default withColors( { | ||
| iconColor: 'icon-color', | ||
| iconBackgroundColor: 'icon-background-color', | ||
| } )( Edit ); | ||
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.
Blocker: Removing
color.text/color.backgroundsupports without adeprecatedregistration is a silent-data-loss path for the ~30 days of posts (production since v6.37.0 / 2026-04-13) that have been savingtextColor/backgroundColor/style.color.text/style.color.backgroundunder the previous schema. Becausesave: () => <InnerBlocks.Content />returns no attribute markup, block validation won't fail loudly — the old keys are dropped from parsed attributes on first load, and on the frontend the new PHPresolve_color()never reads them, so the configured colours disappear silently and the data is gone on next resave. Verified in-env by saving a post with the old shape and loading the frontend: no--icon-color/--icon-backgroundset despite the saved attrs.Needs a
deprecatedentry registering the previous attribute shape with amigrate(attrs)mappingtextColor → iconColor,style.color.text → iconColorValue,backgroundColor → iconBackgroundColor,style.color.background → iconBackgroundColorValue(and stripping the emptystyle.color).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.
@adekbadek I previously poo-poo'd this when Copilot suggested it because this version of the Author Profile block (and this issue) won't show up unless you're using a block theme. It is possible it's used with either our block theme or another theme, but the odds seem very low.
I think we should be safe without a fallback, but I'm willing to talk it out further! I might be being too laissez-faire about it 😅