dioxus/examples/optional_props.rs

52 lines
918 B
Rust
Raw Normal View History

2022-01-16 20:27:41 +00:00
#![allow(non_snake_case)]
2022-01-10 07:57:03 +00:00
//! Example: README.md showcase
//!
//! The example from the README.md.
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(app);
}
fn app(cx: Scope) -> Element {
cx.render(rsx! {
Button {
a: "asd".to_string(),
c: Some("asd".to_string()),
d: "asd".to_string(),
2022-01-16 20:27:41 +00:00
e: "asd".to_string(),
2022-01-10 07:57:03 +00:00
}
})
}
#[derive(Props, PartialEq)]
struct ButtonProps {
a: String,
#[props(default)]
b: Option<String>,
#[props(default)]
c: Option<String>,
2022-01-10 08:05:49 +00:00
#[props(default, strip_option)]
2022-01-10 07:57:03 +00:00
d: Option<String>,
2022-01-16 20:27:41 +00:00
#[props(optional)]
e: Option<String>,
2022-01-10 07:57:03 +00:00
}
fn Button(cx: Scope<ButtonProps>) -> Element {
2022-01-16 20:27:41 +00:00
cx.render(rsx! {
button {
"{cx.props.a}"
"{cx.props.b:?}"
"{cx.props.c:?}"
"{cx.props.d:?}"
"{cx.props.e:?}"
}
})
2022-01-10 07:57:03 +00:00
}