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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: [Block Library - Social Icons]: Make the block use the new flex layout #33987

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 7 additions & 23 deletions packages/block-editor/src/hooks/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,6 @@ import { getLayoutType, getLayoutTypes } from '../layouts';

const layoutBlockSupportKey = '__experimentalLayout';

const getLayoutBlockSettings = ( blockTypeOrName ) => {
const layoutBlockSupportConfig = getBlockSupport(
blockTypeOrName,
layoutBlockSupportKey
);

const {
allowSwitching: canBlockSwitchLayout,
default: defaultBlockLayout,
} = layoutBlockSupportConfig || {}; // TODO: check if this is needed based on the value return by `getBlockSupport`.

return {
canBlockSwitchLayout,
defaultBlockLayout,
};
};

function LayoutPanel( { setAttributes, attributes, name: blockName } ) {
const { layout } = attributes;
// TODO: check if a theme should provide default values per `layoutType`.
Expand All @@ -66,23 +49,24 @@ function LayoutPanel( { setAttributes, attributes, name: blockName } ) {
return null;
}

const { allowLayoutSwitching, defaultBlockLayout } = getLayoutBlockSettings(
blockName
);
const {
allowSwitching: canBlockSwitchLayout,
default: defaultBlockLayout,
} = getBlockSupport( blockName, layoutBlockSupportKey ) || {};

const usedLayout = layout ? layout : defaultBlockLayout || {};
const { inherit = false, type = 'default' } = usedLayout;
const layoutType = getLayoutType( type );

const onChangeType = ( newType ) =>
setAttributes( { layout: { type: newType } } );
setAttributes( { layout: { type: newType } } ); // TODO needs checking with block defaults.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you clarify this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure yet 馃槃 . I'm adding some comments to check it more when the time comes. I just thought I should check if we would need to add the defaultBlockLayout props if exist as well, because this line will trigger a rerender and the logic is if layout is truthy. Therefore I'm not sure it will behave properly.

const onChangeLayout = ( newLayout ) =>
setAttributes( { layout: newLayout } );

return (
<InspectorControls>
<PanelBody title={ __( 'Layout' ) }>
{ layoutType.canInherit && !! defaultThemeLayout && (
{ inherit && !! defaultThemeLayout && (
<ToggleControl
label={ __( 'Inherit default layout' ) }
checked={ !! inherit }
Expand All @@ -91,7 +75,7 @@ function LayoutPanel( { setAttributes, attributes, name: blockName } ) {
}
/>
) }
{ ! inherit && allowLayoutSwitching && (
{ ! inherit && canBlockSwitchLayout && (
<LayoutTypeSwitcher
type={ type }
onChange={ onChangeType }
Expand Down
1 change: 0 additions & 1 deletion packages/block-editor/src/layouts/flex.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,4 @@ export default {
getAlignments() {
return [];
},
canInherit: false,
};
1 change: 0 additions & 1 deletion packages/block-editor/src/layouts/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,4 @@ export default {
? [ 'wide', 'full', 'left', 'center', 'right' ]
: [ 'left', 'center', 'right' ];
},
canInherit: true,
};
1 change: 1 addition & 0 deletions packages/block-library/src/social-links/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"anchor": true,
"__experimentalLayout": {
"allowSwitching": false,
"inherit": false,
"default": {
"type": "flex",
"justifyContent": "flex-start",
Expand Down
2 changes: 0 additions & 2 deletions packages/block-library/src/social-links/style.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.wp-block-social-links {
// display: flex;
// flex-wrap: wrap;
padding-left: 0;
padding-right: 0;
// Some themes set text-indent on all <ul>
Expand Down