Skip to content

Commit

Permalink
Update BlockMover for native to hide if locked or if it's the only block
Browse files Browse the repository at this point in the history
  • Loading branch information
Tug committed Aug 8, 2019
1 parent ea77a0b commit bf6e976
Showing 1 changed file with 46 additions and 36 deletions.
82 changes: 46 additions & 36 deletions packages/block-editor/src/components/block-mover/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,59 @@ import { withInstanceId, compose } from '@wordpress/compose';
const BlockMover = ( {
isFirst,
isLast,
isLocked,
onMoveDown,
onMoveUp,
firstIndex,
} ) => (
<>
<ToolbarButton
title={ ! isFirst ?
sprintf(
/* translators: accessibility text. %1: current block position (number). %2: next block position (number) */
__( 'Move block up from row %1$s to row %2$s' ),
firstIndex + 1,
firstIndex
) :
__( 'Move block up' )
}
isDisabled={ isFirst }
onClick={ onMoveUp }
icon="arrow-up-alt"
extraProps={ { hint: __( 'Double tap to move the block up' ) } }
/>
rootClientId,
} ) => {
if ( isLocked || ( isFirst && isLast && ! rootClientId ) ) {
return null;
}

<ToolbarButton
title={ ! isLast ?
sprintf(
/* translators: accessibility text. %1: current block position (number). %2: next block position (number) */
__( 'Move block down from row %1$s to row %2$s' ),
firstIndex + 1,
firstIndex + 2
) :
__( 'Move block down' )
}
isDisabled={ isLast }
onClick={ onMoveDown }
icon="arrow-down-alt"
extraProps={ { hint: __( 'Double tap to move the block down' ) } }
/>
</>
);
return (
<>
<ToolbarButton
title={ ! isFirst ?
sprintf(
/* translators: accessibility text. %1: current block position (number). %2: next block position (number) */
__( 'Move block up from row %1$s to row %2$s' ),
firstIndex + 1,
firstIndex
) :
__( 'Move block up' )
}
isDisabled={ isFirst }
onClick={ onMoveUp }
icon="arrow-up-alt"
extraProps={ { hint: __( 'Double tap to move the block up' ) } }
/>

<ToolbarButton
title={ ! isLast ?
sprintf(
/* translators: accessibility text. %1: current block position (number). %2: next block position (number) */
__( 'Move block down from row %1$s to row %2$s' ),
firstIndex + 1,
firstIndex + 2
) :
__( 'Move block down' )
}
isDisabled={ isLast }
onClick={ onMoveDown }
icon="arrow-down-alt"
extraProps={ { hint: __( 'Double tap to move the block down' ) } }
/>
</>
);
};

export default compose(
withSelect( ( select, { clientIds } ) => {
const { getBlockIndex, getBlockRootClientId, getBlockOrder } = select( 'core/block-editor' );
const { getBlockIndex, getTemplateLock, getBlockRootClientId, getBlockOrder } = select( 'core/block-editor' );
const normalizedClientIds = castArray( clientIds );
const firstClientId = first( normalizedClientIds );
const rootClientId = getBlockRootClientId( first( normalizedClientIds ) );
const rootClientId = getBlockRootClientId( firstClientId );
const blockOrder = getBlockOrder( rootClientId );
const firstIndex = getBlockIndex( firstClientId, rootClientId );
const lastIndex = getBlockIndex( last( normalizedClientIds ), rootClientId );
Expand All @@ -67,6 +75,8 @@ export default compose(
firstIndex,
isFirst: firstIndex === 0,
isLast: lastIndex === blockOrder.length - 1,
isLocked: getTemplateLock( rootClientId ) === 'all',
rootClientId,
};
} ),
withDispatch( ( dispatch, { clientIds, rootClientId } ) => {
Expand Down

0 comments on commit bf6e976

Please sign in to comment.