Skip to content

Commit

Permalink
refactor BlockSwitcher to function component and use the new hook
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Dec 10, 2020
1 parent f0d9db2 commit 2b13593
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 220 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { MenuGroup } from '@wordpress/components';
import { useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import BlockStyles from '../block-styles';
import PreviewBlockPopover from './preview-block-popover';

const BlockStylesMenu = ( { hoveredBlock, onSwitch } ) => {
const [ hoveredClassName, setHoveredClassName ] = useState();
return (
<MenuGroup
label={ __( 'Styles' ) }
className="block-editor-block-switcher__styles__menugroup"
>
{ hoveredClassName && (
<PreviewBlockPopover
hoveredBlock={ hoveredBlock }
hoveredClassName={ hoveredClassName }
/>
) }
<BlockStyles
clientId={ hoveredBlock.clientId }
onSwitch={ onSwitch }
onHoverClassName={ setHoveredClassName }
itemRole="menuitem"
/>
</MenuGroup>
);
};
export default BlockStylesMenu;
Loading

0 comments on commit 2b13593

Please sign in to comment.