Pauan / rust-dominator

Zero-cost ultra-high-performance declarative DOM library using FRP signals for Rust!
MIT License
960 stars 62 forks source link

single string multiple class names #38

Closed dakom closed 4 years ago

dakom commented 4 years ago

Can this be supported?

e.g. using TailwindCSS, this:

.class("min-h-screen flex items-center justify-center bg-gray-50 py-12 px-4 sm:px-6 lg:px-8")

instead of this:

.class("min-h-screen")
.class("flex")
.class("items-center")
.class("justify-center")
.class("bg-gray-50")
.class("py-12")
.class("px-4")
.class("sm:px-6")
.class("lg:px-8")
Pauan commented 4 years ago

You can do this:

.class(["min-h-screen", "flex", "items-center", "justify-center", "bg-gray-50", "py-12", "px-4", "sm:px-6", "lg:px-8"])
d4h0 commented 4 years ago

Would there be any significant disadvantage with a string-based interface as mentioned by David?

Besides looking cleaner and being faster to type there probably would be other benefits.

For example, we could use the 'format' macro to generate the string.

Pauan commented 4 years ago

@d4h0 You can use .attribute("class", "foo bar qux") if you really want to use spaces.

But it's easier to use .class (it's also better performance if the classes aren't static):

// Better
.class([
    &*FOO,
    &*BAR,
    &*QUX,
])
// Worse
.attribute("class", &format!("{} {} {}", &*FOO, &*BAR, &*QUX))
d4h0 commented 4 years ago

My thinking was more something like:

.class(format!("{0}-foo {0}-bar {0}-baz", theme))

And conditional activation/deactivation of classes maybe also would be easier (not sure, however, if this all makes sense. I just finished reading the Rust book).

But I guess .attribute("class", ...) would be good enough, if this isn't needed very often.

Pauan commented 4 years ago

@d4h0 That doesn't seem like a good idea to me. If you want themes, you're far better off creating classes using class! and then either putting the classes into a signal or passing them as arguments to render. You can also use a mixin to make this easier, and use a struct to organize the classes.

d4h0 commented 4 years ago

@Pauan: Okay, thanks, I'll keep that in mind.