classes
classes is a lightweight and dependency-free macro that simplifies the process of building class strings for DOM
elements. It accepts a variable number of arguments and combines them into a single class string.
This macro is designed after the popular classnames npm package, which is commonly used in React and other frameworks.
Usage
You can supply string types or types that can be transformed into a string to the macro:
Option<String>/Option<&str>will use the inner value if the option isSome, and ignore the option if it'sNoneString/&strwill be applied as is- The special syntax
string_expr => bool_exprwill use thestring_exprwhenbool_exprevaluates to true
Using the Classes macro can simplify your code by reducing the boilerplate needed to build class strings.
Example
use classes;
Dioxus Example
use classes;