Last active
June 5, 2023 17:05
-
-
Save phpbits/318e44036e7fcd499198d4ea7bafe948 to your computer and use it in GitHub Desktop.
Add Block Controls Component to the Gutenberg Block https://jeffreycarandang.com/how-to-create-and-extend-block-toolbar-controls-on-wordpress-gutenberg-block-editor/
This file contains hidden or 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
import Controls from './controls'; // Make sure that the import path is correct | |
const { registerBlockType } = wp.blocks; | |
const { useBlockProps } = wp.blockEditor; | |
registerBlockType('gutenberg-examples/example-block-controls', { | |
apiVersion: 3, | |
title: 'Example: Controls', | |
icon: 'align-full-width', | |
attributes: { | |
theme: { | |
type: 'string', | |
default: '', | |
}, | |
}, | |
category: 'design', | |
edit: (props) => { | |
const { attributes } = props; | |
const { theme } = attributes; | |
const blockProps = useBlockProps({ | |
className: `theme-${theme}`, | |
}); | |
return ( | |
<> | |
<Controls {...props} /> | |
<div {...blockProps}>Your Block Content Here</div> | |
</> | |
); | |
}, | |
save: (props) => { | |
const blockProps = useBlockProps.save(); | |
return <div {...blockProps}>Your Block Content Here</div>; | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment