Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Dependency-free rust macro that simplifies the process of building class strings for DOM elements for usage in frameworks like Dioxus

NotificationsYou must be signed in to change notification settings

sparten11740/classes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CI

classes

classes is a lightweight and dependency-free macro that simplifies the process of building class strings for DOMelements. It accepts a variable number of arguments and combines them into a single class string.This macro is designed after the popularclassnames 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 ifit'sNone
  • String /&str will be applied as is
  • The special syntaxstring_expr => bool_expr will use thestring_expr whenbool_expr evaluates to true

Using the Classes macro can simplify your code by reducing the boilerplate needed to build class strings.

Example

use classes::classes;fnmain(){let optional =Some("lumos");let is_night =true;let class =classes!["hogwarts", optional,"hogwarts--at-night" => is_night,"wingardium-leviosa" =>false];println!("{class}");// => 'hogwarts lumos hogwarts--at-night'}

Dioxus Example

use classes::classes;pubfnButton<'a>(cx:Scope<'a,ButtonProps<'a>>) ->Element{let class =classes!["button","button--disabled" => cx.props.disabled, cx.props.class];    cx.render(rsx!{      button{ class}})}

About

Dependency-free rust macro that simplifies the process of building class strings for DOM elements for usage in frameworks like Dioxus

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp