Last active
July 4, 2023 12:26
-
-
Save mattwatsoncodes/28c9b86db3e8d3134420332651f44ca2 to your computer and use it in GitHub Desktop.
Force Block Style to use Default
This file contains 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
// TODO: We should make a little function that handles this by reading the defaults from the block.json. | |
let blockProps = useBlockProps( { | |
className: 'my-block-name', | |
} ); | |
let style = blockProps['className'].split( ' ' ).filter( className => className.startsWith( 'is-style-' ) )[0] || ''; | |
// The default style does not automatically apply. Fix that. | |
if ( ! style ) { | |
style = 'is-style-default'; | |
blockProps['className'] += ' ' + style; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment