Closed SSeanin closed 9 months ago
I've also tried the bellow syntax of the dynamic classes
<a class=ClassName::BTN class=(ClassName::BTN_CTA, cta)>
</a>
this will again produce an error because it expects a string literal by a struct field is passed.
I axed using of the Leptos view!
macro for using the view builder syntax for now.
I achieved similar behavior using a closure that returns the class name
let (count, set_count) = create_signal(0);
let my_class_name = move || {
if count.get() % 2 == 0 {
ClassName::SOME_CLASS
} else {
""
}
};
view! {
<style>{STYLE_SHEET}</style>
<div class=my_class_name>
</div>
}
We can also create a class String
that is manually and dynamically filled with ClassName values and the format!
macro
let style = format("{} {}", if something_else {ClassName::SOMETHING_ELSE} else {""}, ClassName::SOMETHING);
view! {
<div class=style></div>
}
This can then be used with a closure to be reactive.
However I think this won't be the optimal way.
Of course, this is more on the Leptos and view!
side of things than the turf crate.
There is a problem with the using the Leptos dynamic classes with turf. When using the dynamic classes with the following syntax for example
the
class:(ClassName::BTN_CTA)=cta
part will produce an error because of theview
macro.How can we use turf with Leptos dynamic classes?