dioxus/examples/optional_props.rs

65 lines
1.2 KiB
Rust
Raw Normal View History

2022-01-16 15:27:41 -05:00
#![allow(non_snake_case)]
2022-01-10 02:57:03 -05:00
//! Example: README.md showcase
//!
//! The example from the README.md.
use dioxus::prelude::*;
fn main() {
2024-01-20 00:11:55 -08:00
launch(app);
2022-01-10 02:57:03 -05:00
}
fn app() -> Element {
2024-01-16 13:18:46 -06:00
rsx! {
Button {
a: "asd".to_string(),
c: "asd".to_string(),
d: Some("asd".to_string()),
e: Some("asd".to_string()),
}
2022-01-10 02:57:03 -05:00
Button {
a: "asd".to_string(),
b: "asd".to_string(),
c: "asd".to_string(),
d: Some("asd".to_string()),
2022-01-16 15:27:41 -05:00
e: "asd".to_string(),
2022-01-10 02:57:03 -05:00
}
Button {
a: "asd".to_string(),
c: "asd".to_string(),
d: Some("asd".to_string()),
}
2024-01-13 21:12:21 -08:00
}
2022-01-10 02:57:03 -05:00
}
#[derive(Props, PartialEq, Clone)]
2022-01-10 02:57:03 -05:00
struct ButtonProps {
a: String,
#[props(default)]
b: String,
2022-01-10 02:57:03 -05:00
c: Option<String>,
#[props(!optional)]
2022-01-10 02:57:03 -05:00
d: Option<String>,
2022-01-16 15:27:41 -05:00
#[props(optional)]
e: SthElse<String>,
2022-01-10 02:57:03 -05:00
}
2024-01-18 03:03:17 -08:00
type SthElse<T> = Option<T>;
fn Button(props: ButtonProps) -> Element {
2024-01-16 13:18:46 -06:00
rsx! {
2022-01-16 15:27:41 -05:00
button {
"{props.a} | "
"{props.b:?} | "
"{props.c:?} | "
"{props.d:?} | "
"{props.e:?}"
2022-01-16 15:27:41 -05:00
}
2024-01-13 21:12:21 -08:00
}
2022-01-10 02:57:03 -05:00
}