Skip to content

Commit

Permalink
Social links: add background color block supports (#43293)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ramonjd committed Aug 24, 2022
1 parent a7f1c92 commit a79329b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions packages/block-library/src/social-links/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" ],
Expand Down
67 changes: 47 additions & 20 deletions packages/block-library/src/social-links/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -46,6 +47,7 @@ const getDefaultBlockLayout = ( blockTypeOrName ) => {

export function SocialLinksEdit( props ) {
const {
clientId,
name,
attributes,
iconBackgroundColor,
Expand Down Expand Up @@ -137,6 +139,10 @@ export function SocialLinksEdit( props ) {
setAttributes( { iconColorValue: colorValue } );
},
label: __( 'Icon color' ),
resetAllFilter: () => {
setIconColor( undefined );
setAttributes( { iconColorValue: undefined } );
},
},
];

Expand All @@ -152,11 +158,17 @@ export function SocialLinksEdit( props ) {
} );
},
label: __( 'Icon background' ),
resetAllFilter: () => {
setIconBackgroundColor( undefined );
setAttributes( { iconBackgroundColorValue: undefined } );
},
} );
}

const colorGradientSettings = useMultipleOriginColorsAndGradients();

return (
<Fragment>
<>
<BlockControls group="other">
<ToolbarDropdownMenu
label={ __( 'Size' ) }
Expand Down Expand Up @@ -211,26 +223,41 @@ export function SocialLinksEdit( props ) {
}
/>
</PanelBody>
<PanelColorSettings
__experimentalHasMultipleOrigins
__experimentalIsRenderedInSidebar
title={ __( 'Color' ) }
colorSettings={ colorSettings }
enableAlpha
>
{ ! logosOnly && (
<ContrastChecker
{ ...{
textColor: iconColorValue,
backgroundColor: iconBackgroundColorValue,
} }
isLargeText={ false }
</InspectorControls>
<InspectorControls __experimentalGroup="color">
{ colorSettings.map(
( { onChange, label, value, resetAllFilter } ) => (
<ColorGradientSettingsDropdown
key={ `social-links-color-${ label }` }
__experimentalHasMultipleOrigins
__experimentalIsRenderedInSidebar
settings={ [
{
colorValue: value,
label,
onColorChange: onChange,
isShownByDefault: true,
resetAllFilter,
enableAlpha: true,
},
] }
panelId={ clientId }
{ ...colorGradientSettings }
/>
) }
</PanelColorSettings>
)
) }
{ ! logosOnly && (
<ContrastChecker
{ ...{
textColor: iconColorValue,
backgroundColor: iconBackgroundColorValue,
} }
isLargeText={ false }
/>
) }
</InspectorControls>
<ul { ...innerBlocksProps } />
</Fragment>
</>
);
}

Expand Down

0 comments on commit a79329b

Please sign in to comment.