From a79329beb579b695349c5396ae66b6b342c4e178 Mon Sep 17 00:00:00 2001 From: Ramon Date: Wed, 24 Aug 2022 12:17:55 +1000 Subject: [PATCH] Social links: add background color block supports (#43293) * Adding background color block supports to the social links block. * Adding background color block supports to the social links block. * Revert emptytheme theme.json * Disable contrast checker for the background color Enable alpha for icons and icon background colors added in #43453 --- docs/reference-guides/core-blocks.md | 2 +- .../block-library/src/social-links/block.json | 9 +++ .../block-library/src/social-links/edit.js | 67 +++++++++++++------ 3 files changed, 57 insertions(+), 21 deletions(-) diff --git a/docs/reference-guides/core-blocks.md b/docs/reference-guides/core-blocks.md index e47f50715148b2..ad67cf4caf4898 100644 --- a/docs/reference-guides/core-blocks.md +++ b/docs/reference-guides/core-blocks.md @@ -761,7 +761,7 @@ Display icons linking to your social media profiles or sites. ([Source](https:// - **Name:** core/social-links - **Category:** widgets -- **Supports:** align (center, left, right), anchor, spacing (blockGap, margin, units) +- **Supports:** align (center, left, right), anchor, color (background, gradients, ~~enableContrastChecker~~, ~~text~~), spacing (blockGap, margin, units) - **Attributes:** customIconBackgroundColor, customIconColor, iconBackgroundColor, iconBackgroundColorValue, iconColor, iconColorValue, openInNewTab, showLabels, size ## Spacer diff --git a/packages/block-library/src/social-links/block.json b/packages/block-library/src/social-links/block.json index 8dd7df80a25253..6ba9f32040ffc9 100644 --- a/packages/block-library/src/social-links/block.json +++ b/packages/block-library/src/social-links/block.json @@ -56,6 +56,15 @@ "type": "flex" } }, + "color": { + "enableContrastChecker": false, + "background": true, + "gradients": true, + "text": false, + "__experimentalDefaultControls": { + "background": false + } + }, "spacing": { "blockGap": [ "horizontal", "vertical" ], "margin": [ "top", "bottom" ], diff --git a/packages/block-library/src/social-links/edit.js b/packages/block-library/src/social-links/edit.js index 64ce714c4fb36d..eb1f83180e6e7f 100644 --- a/packages/block-library/src/social-links/edit.js +++ b/packages/block-library/src/social-links/edit.js @@ -7,15 +7,16 @@ import classNames from 'classnames'; * WordPress dependencies */ import { getBlockSupport } from '@wordpress/blocks'; -import { Fragment, useEffect, useRef } from '@wordpress/element'; +import { useEffect, useRef } from '@wordpress/element'; import { BlockControls, useInnerBlocksProps, useBlockProps, InspectorControls, ContrastChecker, - PanelColorSettings, withColors, + __experimentalColorGradientSettingsDropdown as ColorGradientSettingsDropdown, + __experimentalUseMultipleOriginColorsAndGradients as useMultipleOriginColorsAndGradients, } from '@wordpress/block-editor'; import { MenuGroup, @@ -46,6 +47,7 @@ const getDefaultBlockLayout = ( blockTypeOrName ) => { export function SocialLinksEdit( props ) { const { + clientId, name, attributes, iconBackgroundColor, @@ -137,6 +139,10 @@ export function SocialLinksEdit( props ) { setAttributes( { iconColorValue: colorValue } ); }, label: __( 'Icon color' ), + resetAllFilter: () => { + setIconColor( undefined ); + setAttributes( { iconColorValue: undefined } ); + }, }, ]; @@ -152,11 +158,17 @@ export function SocialLinksEdit( props ) { } ); }, label: __( 'Icon background' ), + resetAllFilter: () => { + setIconBackgroundColor( undefined ); + setAttributes( { iconBackgroundColorValue: undefined } ); + }, } ); } + const colorGradientSettings = useMultipleOriginColorsAndGradients(); + return ( - + <> - - { ! logosOnly && ( - + + { colorSettings.map( + ( { onChange, label, value, resetAllFilter } ) => ( + - ) } - + ) + ) } + { ! logosOnly && ( + + ) }
    - + ); }