and there is also another Problem… When I define Block-Support for Colors:
"supports": {
"color": true
},
i can choose the color with the “normal” Picker which allows custom colors and also all available Palettes. The resulting Color-Settings are coded within the Block-Props as classNames and styles for the Block-Container-Tag.
But when I want the color to be set to another Tag within the Container, I have to separate the color settings out of the BlockProps, because most of the Classes are to be set correctly to the Block-Container, but the Colors for Example should be set to the inner Tag. Thats very difficult, because when I set a color from a palette, the this color setting is found within the style prop and also as special Classes like ‘has-green-text-color’ or ‘has-red-background-color’
The useColorProps-Hook gives me the extracted color-Information which I can use for the inner Tag, but the has-xxx classes are still present within the Block-Props className property which sets the colors also to the Block container
Therefore I realized it as follows:
const { style, className, ...blockProps } = useBlockProps();
const containerClass = !!className ? className.replace(/has-.* /g, '') : '';
const borderProps = useBorderProps(attributes);
const colorProps = useColorProps(attributes);
const spacingProps = useSpacingProps(attributes);
const typegraphyProps = useTypographyProps(attributes);
const innerClass = classnames([borderProps.className, colorProps.className, spacingProps.className, typegraphyProps.className, 'tbx-math-box-content']);
const innerStyle = { ...borderProps.style, ...colorProps.style, ...spacingProps.style, ...typegraphyProps.style };
It works, but it’s very unpleasant… but I haven’t found a solution
<figure {...blockProps} className={containerClass}>
<div>
<math
className={innerClass}
style={innerStyle}
dangerouslySetInnerHTML={{
__html: attributes.content
}} />
</div>
)}
-
This reply was modified 1 year, 1 month ago by Jürgen.
-
This reply was modified 1 year, 1 month ago by Jürgen.