Many questions have been asked about conditionally adding classes or styles to elements, but I want to take it a step further and conditionally style a class.
In my application, users can customize foreground and background colors using a theming system. I want to apply these colors to quill.js toolbar buttons dynamically. If I knew the colors beforehand, a simple CSS rule would do the trick.
.ql-toolbar .ql-stroke {
stroke: #f00;
}
I could even create conditional classes for different color combinations in my stylesheet.
.ql-container.foo {
.ql-toolbar .ql-stroke {
stroke: #f00;
}
}
.ql-container.bar {
.ql-toolbar .ql-stroke {
stroke: #b4c;
}
}
However, since users can choose any RGB color, this approach won't work.
I've attempted adding inline styles to the component template, but encountered compilation issues.
Currently, I'm resorting to using document.querySelector
to access the toolbar and manually change button properties based on user color selections. This is a messy solution that doesn't handle dynamic styles like hover states.
Is there a more elegant way to achieve this?