Skip to content
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

Add custom social link icons and use variations #59368

Draft
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Draft
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
22 changes: 17 additions & 5 deletions packages/block-library/src/social-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import classNames from 'classnames';
* WordPress dependencies
*/
import { DELETE, BACKSPACE } from '@wordpress/keycodes';
import { useDispatch } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';

import {
InspectorControls,
Expand All @@ -22,14 +22,16 @@ import {
PanelBody,
PanelRow,
TextControl,
Icon,
} from '@wordpress/components';
import { __, sprintf } 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';

const SocialLinkURLPopover = ( {
url,
Expand Down Expand Up @@ -111,8 +113,18 @@ const SocialLinkEdit = ( {
// re-renders when the popover's anchor updates.
const [ popoverAnchor, setPopoverAnchor ] = useState( null );

const IconComponent = getIconBySite( service );
const socialLinkName = getNameBySite( service );
const activeVariation = useSelect(
( select ) => {
return select( blocksStore ).getActiveBlockVariation(
'core/social-link',
attributes
);
},
[ attributes ]
);

const { icon, label: socialLinkName } = getSocialService( activeVariation );

const socialLinkLabel = label ?? socialLinkName;
const blockProps = useBlockProps( {
className: classes,
Expand Down Expand Up @@ -162,7 +174,7 @@ const SocialLinkEdit = ( {
ref={ setPopoverAnchor }
onClick={ () => setPopover( true ) }
>
<IconComponent />
<Icon icon={ icon } />
<span
className={ classNames( 'wp-block-social-link-label', {
'screen-reader-text': ! showLabels,
Expand Down
Loading
Loading