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 Items Justification to Social Links #28980

Merged
merged 4 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/block-library/src/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,20 @@
.aligncenter {
clear: both;
}

// Justification.
.items-justified-left {
justify-content: flex-start;
}

.items-justified-center {
justify-content: center;
}

.items-justified-right {
justify-content: flex-end;
}

.items-justified-space-between {
justify-content: space-between;
}
19 changes: 19 additions & 0 deletions packages/block-library/src/social-links/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
__experimentalUseInnerBlocksProps as useInnerBlocksProps,
useBlockProps,
InspectorControls,
JustifyToolbar,
ContrastChecker,
PanelColorSettings,
withColors,
Expand Down Expand Up @@ -52,6 +53,7 @@ export function SocialLinksEdit( props ) {
const {
iconBackgroundColorValue,
iconColorValue,
itemsJustification,
openInNewTab,
size,
} = attributes;
Expand Down Expand Up @@ -86,6 +88,7 @@ export function SocialLinksEdit( props ) {
'has-icon-color': iconColor.color || iconColorValue,
'has-icon-background-color':
iconBackgroundColor.color || iconBackgroundColorValue,
[ `items-justified-${ itemsJustification }` ]: itemsJustification,
} );

const style = {
Expand All @@ -111,6 +114,22 @@ export function SocialLinksEdit( props ) {
return (
<Fragment>
<BlockControls>
<JustifyToolbar
allowedControls={ [
'left',
'center',
'right',
'space-between',
] }
value={ itemsJustification }
onChange={ ( value ) =>
setAttributes( { itemsJustification: value } )
}
popoverProps={ {
position: 'bottom right',
isAlternate: true,
} }
/>
<ToolbarGroup>
<ToolbarItem>
{ ( toggleProps ) => (
Expand Down
8 changes: 7 additions & 1 deletion packages/block-library/src/social-links/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';

export default function save( props ) {
const {
attributes: { iconBackgroundColorValue, iconColorValue, size },
attributes: {
iconBackgroundColorValue,
iconColorValue,
itemsJustification,
size,
},
} = props;

const className = classNames( size, {
'has-icon-color': iconColorValue,
'has-icon-background-color': iconBackgroundColorValue,
[ `items-justified-${ itemsJustification }` ]: itemsJustification,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we discuss the naming of this CSS class? I seem to vaguely recall that we did, but can't recall where we ended. I would've probably preferred something like has-justification-left — but maybe there was already an existing CSS class out in the wild?

} );

const style = {
Expand Down
1 change: 0 additions & 1 deletion packages/block-library/src/social-links/style.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.wp-block-social-links {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
padding-left: 0;
padding-right: 0;
// Some themes set text-indent on all <ul>
Expand Down