mirror of
https://github.com/yewstack/yew.git
synced 2025-12-08 21:26:25 +00:00
feat: support arrays for Classes/classes!() (#3393)
* feat: support arrays for Classes/classes!() * style: update
This commit is contained in:
parent
7706bcf3a3
commit
2cbe6cee8a
@ -49,6 +49,11 @@ fn compile_pass() {
|
||||
// single expression
|
||||
::yew::classes!(::std::vec!["one", "two"]);
|
||||
|
||||
// single array
|
||||
::yew::classes!(["one", "two"]);
|
||||
// multiple arrays
|
||||
::yew::classes!(["one"], ["two"]);
|
||||
|
||||
// optional classes
|
||||
::yew::classes!(
|
||||
::std::option::Option::Some("one"),
|
||||
@ -58,7 +63,7 @@ fn compile_pass() {
|
||||
// mixed types
|
||||
{
|
||||
use ::std::borrow::ToOwned;
|
||||
::yew::classes!("one".to_owned(), "two", ::std::vec!["three"]);
|
||||
::yew::classes!("one".to_owned(), "two", ::std::vec!["three"], ["four", "five"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -274,6 +274,12 @@ impl<T: Into<Classes> + Clone> From<&[T]> for Classes {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Into<Classes>, const SIZE: usize> From<[T; SIZE]> for Classes {
|
||||
fn from(t: [T; SIZE]) -> Self {
|
||||
t.into_iter().collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Classes {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.set.len() == other.set.len() && self.set.iter().eq(other.set.iter())
|
||||
|
||||
@ -84,10 +84,8 @@ html! {
|
||||
```rust
|
||||
use yew::{classes, html};
|
||||
|
||||
let my_classes = ["class-1", "class-2"];
|
||||
|
||||
html! {
|
||||
<div class={classes!(my_classes.as_ref())}></div>
|
||||
<div class={classes!(["class-1", "class-2"])}></div>
|
||||
};
|
||||
```
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user