-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Blocks: Extract and factorize block alignment controls
- Loading branch information
1 parent
d9e9633
commit 6dd1048
Showing
6 changed files
with
129 additions
and
185 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from 'i18n'; | ||
import { Toolbar } from 'components'; | ||
|
||
const BLOCK_ALIGNMENTS_CONTROLS = { | ||
left: { | ||
icon: 'align-left', | ||
title: __( 'Align left' ), | ||
}, | ||
center: { | ||
icon: 'align-center', | ||
title: __( 'Align center' ), | ||
}, | ||
right: { | ||
icon: 'align-right', | ||
title: __( 'Align right' ), | ||
}, | ||
wide: { | ||
icon: 'align-full-width', | ||
title: wp.i18n.__( 'Wide width' ), | ||
}, | ||
}; | ||
|
||
const DEFAULT_CONTROLS = [ 'left', 'center', 'right' ]; | ||
|
||
export default function BlockAlignmentToolbar( { value, onChange, controls = DEFAULT_CONTROLS } ) { | ||
function applyOrUnset( align ) { | ||
return () => onChange( value === align ? undefined : align ); | ||
} | ||
|
||
return ( | ||
<Toolbar | ||
controls={ | ||
controls.map( control => { | ||
return { | ||
...BLOCK_ALIGNMENTS_CONTROLS[ control ], | ||
isActive: value === control, | ||
onClick: applyOrUnset( control ), | ||
}; | ||
} ) | ||
} | ||
/> | ||
); | ||
} |
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
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.