-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Buttons block: overhaul alignment/justification controls #23168
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
165c240
Buttons block: overhaul alignment/justification controls.
ZebulanStanphill b7bf3c1
Make icon names consistent with CSS terminology.
ZebulanStanphill 0e25493
Move onClick function inline.
ZebulanStanphill b77c411
Mobile - Buttons block - Support content justification and ContentJus…
4fb29cb
Fix control title inconsistency.
ZebulanStanphill 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 hidden or 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 hidden or 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
73 changes: 73 additions & 0 deletions
73
packages/block-library/src/buttons/content-justification-dropdown.js
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { DropdownMenu } from '@wordpress/components'; | ||
| import { __ } from '@wordpress/i18n'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { | ||
| contentJustificationCenterIcon, | ||
| contentJustificationLeftIcon, | ||
| contentJustificationRightIcon, | ||
| } from './icons'; | ||
|
|
||
| const DEFAULT_ALLOWED_VALUES = [ 'left', 'center', 'right' ]; | ||
|
|
||
| const CONTROLS = { | ||
| left: { | ||
| icon: contentJustificationLeftIcon, | ||
| title: __( 'Justify content left' ), | ||
| }, | ||
| center: { | ||
| icon: contentJustificationCenterIcon, | ||
| title: __( 'Justify content center' ), | ||
| }, | ||
| right: { | ||
| icon: contentJustificationRightIcon, | ||
| title: __( 'Justify content right' ), | ||
| }, | ||
| }; | ||
|
|
||
| const DEFAULT_ICON = CONTROLS.center.icon; | ||
|
|
||
| /** | ||
| * Dropdown for selecting a content justification option. | ||
| * | ||
| * @param {Object} props Component props. | ||
| * @param {string[]} [props.allowedValues] List of options to include. Default: | ||
| * ['left', 'center', 'right']. | ||
| * @param {()=>void} props.onChange Callback to run when an option is | ||
| * selected in the dropdown. | ||
| * @param {Object} props.toggleProps Props to pass to the dropdown toggle. | ||
| * @param {string} props.value The current content justification | ||
| * value. | ||
| * | ||
| * @return {WPComponent} The component. | ||
| */ | ||
| export default function ContentJustificationDropdown( { | ||
| onChange, | ||
| allowedValues = DEFAULT_ALLOWED_VALUES, | ||
| toggleProps, | ||
| value, | ||
| } ) { | ||
| return ( | ||
| <DropdownMenu | ||
| icon={ CONTROLS[ value ]?.icon ?? DEFAULT_ICON } | ||
| label={ __( 'Change content justification' ) } | ||
| controls={ allowedValues.map( ( allowedValue ) => { | ||
| return { | ||
| ...CONTROLS[ allowedValue ], | ||
| isActive: value === allowedValue, | ||
| role: 'menuitemradio', | ||
| onClick: () => | ||
| onChange( | ||
| value === allowedValue ? undefined : allowedValue | ||
| ), | ||
| }; | ||
| } ) } | ||
| toggleProps={ toggleProps } | ||
| /> | ||
| ); | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { InnerBlocks } from '@wordpress/block-editor'; | ||
|
|
||
| const deprecated = [ | ||
| { | ||
| supports: { | ||
| align: [ 'center', 'left', 'right' ], | ||
| anchor: true, | ||
| }, | ||
| save() { | ||
| return ( | ||
| <div> | ||
| <InnerBlocks.Content /> | ||
| </div> | ||
| ); | ||
| }, | ||
| isEligible( { align } ) { | ||
| return align && [ 'center', 'left', 'right' ].includes( align ); | ||
| }, | ||
| migrate( attributes ) { | ||
| return { | ||
| ...attributes, | ||
| align: undefined, | ||
| // Floating Buttons blocks shouldn't have been supported in the | ||
| // first place. Most users using them probably expected them to | ||
| // act like content justification controls, so these blocks are | ||
| // migrated to use content justification. | ||
| // As for center-aligned Buttons blocks, the content justification | ||
| // equivalent will create an identical end result in most cases. | ||
| contentJustification: attributes.align, | ||
| }; | ||
| }, | ||
| }, | ||
| ]; | ||
|
|
||
| export default deprecated; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { Path, SVG } from '@wordpress/components'; | ||
|
|
||
| export const contentJustificationLeftIcon = ( | ||
| <SVG | ||
| width="20" | ||
| height="20" | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| viewBox="0 0 24 24" | ||
| > | ||
| <Path d="M11 16v-3h10v-2H11V8l-4 4 4 4zM5 4H3v16h2V4z" /> | ||
| </SVG> | ||
| ); | ||
|
|
||
| export const contentJustificationCenterIcon = ( | ||
| <SVG | ||
| width="20" | ||
| height="20" | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| viewBox="0 0 24 24" | ||
| > | ||
| <Path d="M5 8v3H1v2h4v3l4-4-4-4zm14 8v-3h4v-2h-4V8l-4 4 4 4zM13 4h-2v16h2V4z" /> | ||
| </SVG> | ||
| ); | ||
|
|
||
| export const contentJustificationRightIcon = ( | ||
| <SVG | ||
| width="20" | ||
| height="20" | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| viewBox="0 0 24 24" | ||
| > | ||
| <Path d="M13 8v3H3v2h10v3l4-4-4-4zm8-4h-2v16h2V4z" /> | ||
| </SVG> | ||
| ); |
This file contains hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.