examples on how to connect trait to css property? #5581
-
I'm trying to follow this tutorial https://grapesjs.com/docs/modules/Traits.html#define-new-trait-type to trying to make a css property a custom trait ( not the default however I'm having a hard time understanding the example. I messed with it for a while and finally getting completely lost... Let's say I have a custom component, a custom trait, and wants the trait to bind with css property ( or more broadly I may want to add more custom logic let's say invert the background color values)
I guess this is already resolved in https://studio.grapesjs.com/ ? But IDK if it is resolvable thru the interfaces without modifying the source code. And I have also read about |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Why did you need this instead of using the background in styles? |
Beta Was this translation helpful? Give feedback.
-
I'd suggest following what @ronaldohoch already mentioned as Traits are designed to handle mainly attribute and property values (eg. which don't depend on media queries) and Style Manager is designed to handle responsive styles. Though you can still make a fully custom traits logic to handle specific values (definitely useful only for advanced use cases) you just need to indicate how to get/set your custom value. traits: [
{
name: 'custom-trait-update-html'
getValue: ({ component }) => {
// The value is the inner HTML content
return component.getInnerHTML();
},
setValue: ({ component, value }) => {
// Update the inner HTML with a new value
component.components(value);
}
}
] |
Beta Was this translation helpful? Give feedback.
I'd suggest following what @ronaldohoch already mentioned as Traits are designed to handle mainly attribute and property values (eg. which don't depend on media queries) and Style Manager is designed to handle responsive styles.
Though you can still make a fully custom traits logic to handle specific values (definitely useful only for advanced use cases) you just need to indicate how to get/set your custom value.