-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3458 from WordPress/update/added-block-transforms…
…-to-block-side-menu Show transformations in the ellipsis menu
- Loading branch information
Showing
7 changed files
with
333 additions
and
35 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
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
73 changes: 73 additions & 0 deletions
73
editor/components/block-settings-menu/block-transformations.js
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,73 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { connect } from 'react-redux'; | ||
import { noop } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import { IconButton, withContext } from '@wordpress/components'; | ||
import { getPossibleBlockTransformations, switchToBlockType } from '@wordpress/blocks'; | ||
import { compose } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './style.scss'; | ||
import { getBlock } from '../../selectors'; | ||
import { replaceBlocks } from '../../actions'; | ||
|
||
function BlockTransformations( { blocks, small = false, onTransform, onClick = noop, isLocked } ) { | ||
const possibleBlockTransformations = getPossibleBlockTransformations( blocks ); | ||
if ( isLocked || ! possibleBlockTransformations.length ) { | ||
return null; | ||
} | ||
return ( | ||
<div className="editor-block-settings-menu__block-transformations"> | ||
{ possibleBlockTransformations.map( ( { name, title, icon } ) => { | ||
/* translators: label indicating the transformation of a block into another block */ | ||
const shownText = sprintf( __( 'Turn into %s' ), title ); | ||
return ( | ||
<IconButton | ||
key={ name } | ||
className="editor-block-settings-menu__control" | ||
onClick={ ( event ) => { | ||
onTransform( blocks, name ); | ||
onClick( event ); | ||
} } | ||
icon={ icon } | ||
label={ small ? shownText : undefined } | ||
> | ||
{ ! small && shownText } | ||
</IconButton> | ||
); | ||
} ) } | ||
</div> | ||
); | ||
} | ||
export default compose( | ||
connect( | ||
( state, ownProps ) => { | ||
return { | ||
blocks: ownProps.uids.map( ( uid ) => getBlock( state, uid ) ), | ||
}; | ||
}, | ||
( dispatch, ownProps ) => ( { | ||
onTransform( blocks, name ) { | ||
dispatch( replaceBlocks( | ||
ownProps.uids, | ||
switchToBlockType( blocks, name ) | ||
) ); | ||
}, | ||
} ) | ||
), | ||
withContext( 'editor' )( ( settings ) => { | ||
const { templateLock } = settings; | ||
|
||
return { | ||
isLocked: !! templateLock, | ||
}; | ||
} ), | ||
)( BlockTransformations ); |
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.