Skip to content

Instantly share code, notes, and snippets.

@igmoweb
Last active June 12, 2020 10:13
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 igmoweb/ef3cc57854f8b8515bca711fad573810 to your computer and use it in GitHub Desktop.
Save igmoweb/ef3cc57854f8b8515bca711fad573810 to your computer and use it in GitHub Desktop.
import './style.scss';
const { toggleFormat, registerFormatType } = wp.richText;
const { RichTextToolbarButton } = wp.blockEditor;
const formatName = 'igmoweb/boxed-format';
const formatTitle = 'Boxed';
const BoxedButton = ( { onChange, value, isActive } ) => {
const toggleBoxedFormat = () => {
onChange( toggleFormat(
value,
{
type: formatName,
attributes: {
'data-type': 'box',
},
}
) );
};
return (
<RichTextToolbarButton
icon="archive"
title={ formatTitle }
onClick={ toggleBoxedFormat }
isActive={ isActive }
/>
);
};
registerFormatType( formatName, {
title: formatTitle,
tagName: 'span',
className: 'boxed',
edit: BoxedButton,
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment