fix: Image object-fit (#195)

This commit is contained in:
luoxiaozero 2024-05-18 16:08:44 +08:00 committed by GitHub
parent 9259bdc723
commit ab3ea810de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 2 deletions

View file

@ -3,7 +3,7 @@
```rust demo
view! {
<Image src="https://s3.bmp.ovh/imgs/2021/10/2c3b013418d55659.jpg" width="500px"/>
<Image width="200px" height="200px"/>
<Image src="https://s3.bmp.ovh/imgs/2021/10/2c3b013418d55659.jpg" width="200px" height="200px" object_fit="cover"/>
}
```

View file

@ -29,6 +29,12 @@ pub fn Image(
style.push_str(&format!("border-radius: {border_radius};"))
}
if let Some(object_fit) = object_fit.as_ref().map(|object_fit| object_fit.get()) {
if !object_fit.is_empty() {
style.push_str(&format!("object-fit: {object_fit};"))
}
}
style
};
@ -38,7 +44,6 @@ pub fn Image(
src=src.map(|s| move || s.get())
alt=alt.map(|a| move || a.get())
style=style
object_fit=object_fit.map(|o| move || o.get())
/>
}
}