class_list
A reactive helper that ensures normalized class list strings in frontend frameworks like Leptos.
Usage
Examples provided will be for the Leptos framework post-{context removal}, but it will work pre-{context removal} and might work in other similar frameworks.
This library is meant to be agnostic and has no runtime dependencies, but it has only been tested with Leptos.
Example
class_list![]
by default wraps itself in a move closure, meaning it will be reactive by default.
let = create_signal;
set_interval;
let count_class = move || format!;
let count_is_even = move || count % 2 == 0;
view!
Options
Each option must be followed by a ;
.
Raw
To generate a non-reactive String, add the raw
option to the beginning.
class_list!
Clone
Rarely, you may need to clone something before passing it in.
The macro makes this easy with the clone
option which clones the variable before it gets moved into the closure.
If possible try to avoid needing this option in the first place.
class_list!
Crate
This should never be needed because it's automatically supplied by a wrapper macro_rules!
.
In a case where the trait imports cannot be resolved--such as when used inside of another library--, the path can be redefined.
The path should lead to the root of this library.
__class_list!
Implementing Traits
If you'd like to simply pass a type to the macro instead of converting it every time, you can implement the ClassList
and ClassToggle
types.
Check out traits.rs to see the default implementations which are good examples of implementing them.
// If you're using a type you don't own,
// you must wrap it in a new struct.
;
// Option, Result, and Fn are implemented in a way which
// allows any new type you implement to be automatically
// passed through.
assert_eq!;