Skip to content

Commit 2dc5a90

Browse files
ndiegocbravobernal
authored andcommitted
Social Links block: Add color classes so icon colors correctly reflect changes in Global Styles (#51020)
* Add color classes. * Linting.
1 parent 557e939 commit 2dc5a90

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

packages/block-library/src/social-link/block.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
"usesContext": [
2525
"openInNewTab",
2626
"showLabels",
27+
"iconColor",
2728
"iconColorValue",
29+
"iconBackgroundColor",
2830
"iconBackgroundColorValue"
2931
],
3032
"supports": {

packages/block-library/src/social-link/edit.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,19 @@ const SocialLinkEdit = ( {
9292
clientId,
9393
} ) => {
9494
const { url, service, label, rel } = attributes;
95-
const { showLabels, iconColorValue, iconBackgroundColorValue } = context;
95+
const {
96+
showLabels,
97+
iconColor,
98+
iconColorValue,
99+
iconBackgroundColor,
100+
iconBackgroundColorValue,
101+
} = context;
96102
const [ showURLPopover, setPopover ] = useState( false );
97103
const classes = classNames( 'wp-social-link', 'wp-social-link-' + service, {
98104
'wp-social-link__is-incomplete': ! url,
105+
[ `has-${ iconColor }-color` ]: iconColor,
106+
[ `has-${ iconBackgroundColor }-background-color` ]:
107+
iconBackgroundColor,
99108
} );
100109

101110
// Use internal state instead of a ref to make sure that the component

packages/block-library/src/social-link/index.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function render_block_core_social_link( $attributes, $content, $block ) {
4747
$icon = block_core_social_link_get_icon( $service );
4848
$wrapper_attributes = get_block_wrapper_attributes(
4949
array(
50-
'class' => 'wp-social-link wp-social-link-' . $service,
50+
'class' => 'wp-social-link wp-social-link-' . $service . block_core_social_link_get_color_classes( $block->context ),
5151
'style' => block_core_social_link_get_color_styles( $block->context ),
5252
)
5353
);
@@ -337,3 +337,24 @@ function block_core_social_link_get_color_styles( $context ) {
337337

338338
return implode( '', $styles );
339339
}
340+
341+
/**
342+
* Returns CSS classes for icon and icon background colors.
343+
*
344+
* @param array $context Block context passed to Social Sharing Link.
345+
*
346+
* @return string CSS classes for link's icon and background colors.
347+
*/
348+
function block_core_social_link_get_color_classes( $context ) {
349+
$classes = array();
350+
351+
if ( array_key_exists( 'iconColor', $context ) ) {
352+
$classes[] = 'has-' . $context['iconColor'] . '-color';
353+
}
354+
355+
if ( array_key_exists( 'iconBackgroundColor', $context ) ) {
356+
$classes[] = 'has-' . $context['iconBackgroundColor'] . '-background-color';
357+
}
358+
359+
return ' ' . implode( ' ', $classes );
360+
}

packages/block-library/src/social-links/block.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
"providesContext": {
4242
"openInNewTab": "openInNewTab",
4343
"showLabels": "showLabels",
44+
"iconColor": "iconColor",
4445
"iconColorValue": "iconColorValue",
46+
"iconBackgroundColor": "iconBackgroundColor",
4547
"iconBackgroundColorValue": "iconBackgroundColorValue"
4648
},
4749
"supports": {

0 commit comments

Comments
 (0)