Skip to content

Commit

Permalink
Mobile - Buttons block - Support content justification and ContentJus…
Browse files Browse the repository at this point in the history
…tificationDropdown (#26166)
  • Loading branch information
Gerardo Pacheco authored and ZebulanStanphill committed Oct 28, 2020
1 parent 0e25493 commit b77c411
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions packages/block-library/src/buttons/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,28 @@ import { View } from 'react-native';
/**
* WordPress dependencies
*/
import { InnerBlocks } from '@wordpress/block-editor';
import { BlockControls, InnerBlocks } from '@wordpress/block-editor';
import { createBlock } from '@wordpress/blocks';
import { useResizeObserver } from '@wordpress/compose';
import { useDispatch, useSelect } from '@wordpress/data';
import { useState, useEffect, useRef } from '@wordpress/element';
import { ToolbarGroup, ToolbarItem } from '@wordpress/components';

/**
* Internal dependencies
*/
import { name as buttonBlockName } from '../button/';
import styles from './editor.scss';
import ContentJustificationDropdown from './content-justification-dropdown';

const ALLOWED_BLOCKS = [ buttonBlockName ];
const BUTTONS_TEMPLATE = [ [ 'core/button' ] ];

export default function ButtonsEdit( {
attributes: { align },
attributes: { contentJustification },
clientId,
isSelected,
setAttributes,
} ) {
const [ resizeObserver, sizes ] = useResizeObserver();
const [ maxWidth, setMaxWidth ] = useState( 0 );
Expand Down Expand Up @@ -85,6 +88,12 @@ export default function ButtonsEdit( {
selectBlock( insertedBlock.clientId );
}, 200 );

function onChangeContentJustification( updatedValue ) {
setAttributes( {
contentJustification: updatedValue,
} );
}

const renderFooterAppender = useRef( () => (
<View style={ styles.appenderContainer }>
<InnerBlocks.ButtonBlockAppender
Expand All @@ -98,6 +107,19 @@ export default function ButtonsEdit( {

return (
<>
<BlockControls>
<ToolbarGroup>
<ToolbarItem>
{ ( toggleProps ) => (
<ContentJustificationDropdown
toggleProps={ toggleProps }
value={ contentJustification }
onChange={ onChangeContentJustification }
/>
) }
</ToolbarItem>
</ToolbarGroup>
</BlockControls>
{ resizeObserver }
<InnerBlocks
allowedBlocks={ ALLOWED_BLOCKS }
Expand All @@ -106,7 +128,7 @@ export default function ButtonsEdit( {
shouldRenderFooterAppender && renderFooterAppender.current
}
orientation="horizontal"
horizontalAlignment={ align }
horizontalAlignment={ contentJustification }
onDeleteBlock={
shouldDelete ? () => removeBlock( clientId ) : undefined
}
Expand Down

0 comments on commit b77c411

Please sign in to comment.