From 888d015bf6e179f0caadb47e5ff15b86053c7433 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Wed, 28 May 2025 21:57:00 +0400 Subject: [PATCH 1/4] Social: Allow custom link icons using block variations --- .../block-library/src/social-link/edit.js | 23 ++++++++---- .../src/social-link/social-list.js | 35 ++++++++----------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/packages/block-library/src/social-link/edit.js b/packages/block-library/src/social-link/edit.js index 7ed423b54edc42..830ea4970acf3e 100644 --- a/packages/block-library/src/social-link/edit.js +++ b/packages/block-library/src/social-link/edit.js @@ -7,8 +7,7 @@ import clsx from 'clsx'; * WordPress dependencies */ import { DELETE, BACKSPACE, ENTER } from '@wordpress/keycodes'; -import { useDispatch } from '@wordpress/data'; - +import { useDispatch, useSelect } from '@wordpress/data'; import { BlockControls, InspectorControls, @@ -20,6 +19,7 @@ import { } from '@wordpress/block-editor'; import { useState, useRef } from '@wordpress/element'; import { + Icon, Button, Dropdown, TextControl, @@ -31,11 +31,12 @@ import { import { useMergeRefs } from '@wordpress/compose'; import { __ } from '@wordpress/i18n'; import { keyboardReturn } from '@wordpress/icons'; +import { store as blocksStore } from '@wordpress/blocks'; /** * Internal dependencies */ -import { getIconBySite, getNameBySite } from './social-list'; +import { getSocialService } from './social-list'; import { useToolsPanelDropdownMenuProps } from '../utils/hooks'; const SocialLinkURLPopover = ( { @@ -108,6 +109,7 @@ const SocialLinkEdit = ( { isSelected, setAttributes, clientId, + name, } ) => { const { url, service, label = '', rel } = attributes; const dropdownMenuProps = useToolsPanelDropdownMenuProps(); @@ -138,8 +140,17 @@ const SocialLinkEdit = ( { const [ popoverAnchor, setPopoverAnchor ] = useState( null ); const isContentOnlyMode = useBlockEditingMode() === 'contentOnly'; - const IconComponent = getIconBySite( service ); - const socialLinkName = getNameBySite( service ); + const { activeVariation } = useSelect( + ( select ) => { + const { getActiveBlockVariation } = select( blocksStore ); + return { + activeVariation: getActiveBlockVariation( name, attributes ), + }; + }, + [ name, attributes ] + ); + + const { icon, label: socialLinkName } = getSocialService( activeVariation ); // The initial label (ie. the link text) is an empty string. // We want to prevent empty links so that the link text always fallbacks to // the social name, even when users enter and save an empty string or only @@ -258,7 +269,7 @@ const SocialLinkEdit = ( { */ /* eslint-disable jsx-a11y/no-redundant-roles */ }