I am adding styles when registering my block:
styles: [
{ name: "my-style-1", label: "Style Name" }
{ name: "my-style-2", label: "Style Name 2" }
],
In the edit() and save() function how can I see which style/classname was selected?
I tried for example:
edit( { attributes, setAttributes, styles } ) {
const blockProps = useBlockProps();
const { quote, name, title } = attributes;
console.log(styles);
console.log(blockProps.styles);
...
But it returns undefined.
I need to use the styles for conditions for example...
if (style == 'my-style-1') {
// do something if style 1 was selected
}
Edit( { className } )
. I can access the prop asuseBlockProps().className
orEdit( { attributes: { className } } )
. The bonus of the latter is it contains only the selected style class. Note: that attribute was generated by the styles API - I have no attributes manually defined. – Cassondracassoulet