Last active
June 12, 2020 10:13
-
-
Save igmoweb/ef3cc57854f8b8515bca711fad573810 to your computer and use it in GitHub Desktop.
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 './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