-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[Block Library - Social Links]: Use the new flex
layout
#34493
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
72f9f52
[Block Library - Social Links]: Use the new `flex` layout
ntsekouras 63cf506
don't check for theme support in social links edit fn
ntsekouras afafacf
associate `themeSupportsLayout` with `default/flow` layout
ntsekouras 124007d
handle deprecations
ntsekouras 06a2c84
add fixture and fix deprecation handling for default value
ntsekouras 5c732bb
Remove link margin.
jasmussen 3f06877
remove help from control
ntsekouras 482ebe1
make justification work properly with JustifyContentControl - temp co…
ntsekouras cea7307
add `toolBarControls` to layouts
ntsekouras 0bb0f11
fix import
ntsekouras df4f7b4
rename layout.edit to layout.inspectorControls
ntsekouras 5e150d7
pass layoutBlockSupport to edit functions
ntsekouras File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,63 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { __, _x } from '@wordpress/i18n'; | ||
import { | ||
__experimentalToggleGroupControl as ToggleGroupControl, | ||
__experimentalToggleGroupControlOption as ToggleGroupControlOption, | ||
} from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { appendSelectors } from './utils'; | ||
import useSetting from '../components/use-setting'; | ||
import { BlockControls, JustifyContentControl } from '../components'; | ||
|
||
const justifyContentMap = { | ||
left: 'flex-start', | ||
right: 'flex-end', | ||
center: 'center', | ||
'space-between': 'space-between', | ||
}; | ||
|
||
export default { | ||
name: 'flex', | ||
|
||
label: __( 'Flex' ), | ||
|
||
edit() { | ||
return null; | ||
inspectorControls: function FlexLayoutInspectorControls( { | ||
layout = {}, | ||
onChange, | ||
} ) { | ||
return ( | ||
<FlexLayoutJustifyContentControl | ||
layout={ layout } | ||
onChange={ onChange } | ||
/> | ||
); | ||
}, | ||
|
||
save: function FlexLayoutStyle( { selector } ) { | ||
toolBarControls: function FlexLayoutToolbarControls( { | ||
layout = {}, | ||
onChange, | ||
layoutBlockSupport, | ||
} ) { | ||
if ( layoutBlockSupport?.allowSwitching ) { | ||
return null; | ||
} | ||
return ( | ||
<BlockControls group="block" __experimentalExposeToChildren> | ||
<FlexLayoutJustifyContentControl | ||
layout={ layout } | ||
onChange={ onChange } | ||
isToolbar | ||
/> | ||
</BlockControls> | ||
); | ||
}, | ||
save: function FlexLayoutStyle( { selector, layout } ) { | ||
const blockGapSupport = useSetting( 'spacing.blockGap' ); | ||
const hasBlockGapStylesSupport = blockGapSupport !== null; | ||
|
||
const justifyContent = | ||
justifyContentMap[ layout.justifyContent ] || 'flex-start'; | ||
return ( | ||
<style>{ ` | ||
${ appendSelectors( selector ) } { | ||
|
@@ -33,6 +69,8 @@ export default { | |
}; | ||
flex-wrap: wrap; | ||
align-items: center; | ||
flex-direction: row; | ||
justify-content: ${ justifyContent }; | ||
} | ||
|
||
${ appendSelectors( selector, '> *' ) } { | ||
|
@@ -41,12 +79,71 @@ export default { | |
` }</style> | ||
); | ||
}, | ||
|
||
getOrientation() { | ||
return 'horizontal'; | ||
}, | ||
|
||
getAlignments() { | ||
return []; | ||
}, | ||
}; | ||
|
||
function FlexLayoutJustifyContentControl( { | ||
layout, | ||
onChange, | ||
isToolbar = false, | ||
} ) { | ||
const { justifyContent = 'left' } = layout; | ||
if ( isToolbar ) { | ||
return ( | ||
<JustifyContentControl | ||
allowedControls={ [ | ||
'left', | ||
'center', | ||
'right', | ||
'space-between', | ||
] } | ||
value={ justifyContent } | ||
onChange={ ( value ) => { | ||
onChange( { | ||
...layout, | ||
justifyContent: value, | ||
} ); | ||
} } | ||
popoverProps={ { | ||
position: 'bottom right', | ||
isAlternate: true, | ||
} } | ||
/> | ||
); | ||
} | ||
return ( | ||
<ToggleGroupControl | ||
label={ __( 'Justify content' ) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The label seems too close to the buttons in this case, I believe these are probably independent of this PR but could use some improvements separately. |
||
value={ justifyContent } | ||
onChange={ ( value ) => { | ||
onChange( { | ||
...layout, | ||
justifyContent: value, | ||
} ); | ||
} } | ||
isBlock | ||
> | ||
<ToggleGroupControlOption | ||
value="left" | ||
label={ _x( 'Left', 'Justify content option' ) } | ||
/> | ||
<ToggleGroupControlOption | ||
value="center" | ||
label={ _x( 'Center', 'Justify content option' ) } | ||
/> | ||
<ToggleGroupControlOption | ||
value="right" | ||
label={ _x( 'Right', 'Justify content option' ) } | ||
/> | ||
<ToggleGroupControlOption | ||
value="space-between" | ||
label={ _x( 'Space between', 'Justify content option' ) } | ||
/> | ||
</ToggleGroupControl> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@youknowriad 's comment:
The passed
layout
has already checked the existence of default block layout.