Repository navigation
How best practice to set multiple static class? #4848
|
i used use tupple class for class with multiple value? (for example) or this one:
that i used features for dynamic class, however the class element are static. I tried to read the documentation, but i did'nt find it. i used tailwind that need class for styling. that any other implementation? |
Replies: 1 comment
|
For classes that never change, you don't need the tuple syntax at all — just use the plain view! {
<h1 class="font-red text-red color-red bg-purple-400">"Welcome to Leptos!"</h1>
}That's the idiomatic way to set static (including static Tailwind) classes. Both of your examples work, but they're using machinery meant for a different job:
The key point: the second element of that tuple is a reactive condition. It exists so a signal can decide whether the classes are applied. When you pass a literal Use the tuple/array form only when something actually toggles, e.g.: // static classes in the string, dynamic ones in the tuple
<div
class="rounded-lg p-4 shadow"
class=(["ring-2", "ring-purple-400"], move || selected())
>One Tailwind-specific caveat worth knowing (it bites people migrating from dynamic class strings): Tailwind's scanner only generates CSS for class names it can find as complete literal strings in your source. Writing them out in a plain So: plain |
For classes that never change, you don't need the tuple syntax at all — just use the plain
classattribute with a normal string:That's the idiomatic way to set static (including static Tailwind) classes. Both of your examples work, but they're using machinery meant for a different job:
class:name=condition— toggles one class reactively, e.g.class:font-red=move || is_active().class=("name", condition)— same idea, for a single class name theview!macro can't parse as an identifier (hyphens, slashes, etc.).class=(["a", "b", "c"], condition)— toggles a list of classes together based on one c…