diff --git a/packages/block-library/src/social-link/editor.scss b/packages/block-library/src/social-link/editor.scss index e938b8d74ee749..1d9bde20f72436 100644 --- a/packages/block-library/src/social-link/editor.scss +++ b/packages/block-library/src/social-link/editor.scss @@ -1,9 +1,20 @@ -.wp-block-social-links .wp-social-link button { - color: currentColor; - padding: 6px; +// The editor uses the button component, the frontend uses a link. +// Therefore we unstyle the button component to make it more like the frontend. +.wp-block-social-links .wp-social-link { + line-height: 0; + + button { + font-size: inherit; + color: currentColor; + height: auto; + line-height: 0; + + // This rule is duplicated from the style.scss and needs to be the same as there. + padding: 0.25em; + } } .wp-block-social-links.is-style-pill-shape .wp-social-link button { - padding-left: 16px; - padding-right: 16px; + padding-left: calc((2/3) * 1em); + padding-right: calc((2/3) * 1em); } diff --git a/packages/block-library/src/social-links/block.json b/packages/block-library/src/social-links/block.json index d0ed132031b912..47147dee69c89b 100644 --- a/packages/block-library/src/social-links/block.json +++ b/packages/block-library/src/social-links/block.json @@ -6,6 +6,9 @@ "openInNewTab": { "type": "boolean", "default": false + }, + "size": { + "type": "string" } }, "providesContext": { diff --git a/packages/block-library/src/social-links/edit.js b/packages/block-library/src/social-links/edit.js index 13ce364c83561b..b8b9136a6fdcdb 100644 --- a/packages/block-library/src/social-links/edit.js +++ b/packages/block-library/src/social-links/edit.js @@ -1,3 +1,8 @@ +/** + * External dependencies + */ +import classNames from 'classnames'; + /** * WordPress dependencies */ @@ -5,30 +10,48 @@ import { Fragment } from '@wordpress/element'; import { + BlockControls, __experimentalUseInnerBlocksProps as useInnerBlocksProps, useBlockProps, InspectorControls, } from '@wordpress/block-editor'; -import { ToggleControl, PanelBody } from '@wordpress/components'; +import { + DropdownMenu, + MenuGroup, + MenuItem, + PanelBody, + ToggleControl, + ToolbarItem, + ToolbarGroup, +} from '@wordpress/components'; import { __ } from '@wordpress/i18n'; +import { check } from '@wordpress/icons'; const ALLOWED_BLOCKS = [ 'core/social-link' ]; +const sizeOptions = [ + { name: __( 'Small' ), value: 'has-small-icon-size' }, + { name: __( 'Normal' ), value: 'has-normal-icon-size' }, + { name: __( 'Large' ), value: 'has-large-icon-size' }, + { name: __( 'Huge' ), value: 'has-huge-icon-size' }, +]; + export function SocialLinksEdit( props ) { const { - attributes: { openInNewTab }, + attributes: { size, openInNewTab }, setAttributes, } = props; const SocialPlaceholder = (
-
-
-
+
+
+
); - const blockProps = useBlockProps(); + const className = classNames( size ); + const blockProps = useBlockProps( { className } ); const innerBlocksProps = useInnerBlocksProps( blockProps, { allowedBlocks: ALLOWED_BLOCKS, orientation: 'horizontal', @@ -36,8 +59,61 @@ export function SocialLinksEdit( props ) { templateLock: false, __experimentalAppenderTagName: 'li', } ); + + const POPOVER_PROPS = { + position: 'bottom right', + isAlternate: true, + }; + return ( + + + + { ( toggleProps ) => ( + + { ( { onClose } ) => ( + + { sizeOptions.map( ( entry ) => { + return ( + { + setAttributes( { + size: entry.value, + } ); + } } + onClose={ onClose } + role="menuitemradio" + > + { entry.name } + + ); + } ) } + + ) } + + ) } + + + +
); diff --git a/packages/block-library/src/social-links/style.scss b/packages/block-library/src/social-links/style.scss index cfd5375654b362..cc93e45a113619 100644 --- a/packages/block-library/src/social-links/style.scss +++ b/packages/block-library/src/social-links/style.scss @@ -16,19 +16,59 @@ border-bottom: 0; box-shadow: none; } + + // Vertically balance the margin of each icon. + .wp-social-link { + // This needs specificity to override some themes. + &.wp-social-link.wp-social-link { + margin: 4px 8px 4px 0; + } + + // By setting the font size, we can scale icons and paddings consistently based on that. + // This also allows themes to override this, if need be. + a { + padding: 0.25em; + } + + svg { + width: 1em; + height: 1em; + } + } + + // Icon sizes. + // Small. + &.has-small-icon-size { + font-size: 16px; // 16 makes for a quarter-padding that keeps the icon centered. + } + + // Normal/default. + &, + &.has-normal-icon-size { + font-size: 24px; + } + + // Large. + &.has-large-icon-size { + font-size: 36px; + } + + // Huge. + &.has-huge-icon-size { + font-size: 48px; + } } .wp-social-link { display: block; - width: 36px; - height: 36px; border-radius: 9999px; // This makes it pill-shaped instead of oval, in cases where the image fed is not perfectly sized. - margin: 0 8px 8px 0; transition: transform 0.1s ease; @include reduce-motion("transition"); + // Dimensions. + height: auto; + a { - padding: 6px; display: block; line-height: 0; transition: transform 0.1s ease; @@ -69,10 +109,6 @@ // Make these bigger. padding: 4px; - svg { - width: 28px; - height: 28px; - } } @import "../social-link/socials-without-bg.scss"; @@ -85,7 +121,7 @@ } .wp-social-link a { - padding-left: 16px; - padding-right: 16px; + padding-left: calc((2/3) * 1em); + padding-right: calc((2/3) * 1em); } }