Skip to content

Instantly share code, notes, and snippets.

@phpbits
Last active June 5, 2023 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpbits/318e44036e7fcd499198d4ea7bafe948 to your computer and use it in GitHub Desktop.
Save phpbits/318e44036e7fcd499198d4ea7bafe948 to your computer and use it in GitHub Desktop.
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