Merge branch 'master' into eval-stuff
This commit is contained in:
35 files changed
+516
-958
No files matched your search
@@ -41,6 +41,7 @@ These examples are not necessarily meant to be run, but rather serve as a refere
|
||||
| [Anti-patterns](./antipatterns.rs) | A collection of discouraged patterns | ✅ |
|
||||
| [Complete rsx reference](./rsx_usage.rs) | A complete reference for all rsx! usage | ✅ |
|
||||
| [Event Listeners](./listener.rs) | Attach closures to events on elements | ✅ |
|
||||
| [Inline Props](./inlineprops.rs) | Using the `#[inline_props]` macro | ✅ |
|
||||
| [Eval](./eval.rs) | Evaluate dynamic JavaScript code | ✅ |
|
||||
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ fn app(cx: Scope) -> Element {
|
||||
input { r#type: "text", name: "username" }
|
||||
input { r#type: "text", name: "full-name" }
|
||||
input { r#type: "password", name: "password" }
|
||||
input { r#type: "radio", name: "color", value: "red" }
|
||||
input { r#type: "radio", name: "color", value: "blue" }
|
||||
button { r#type: "submit", value: "Submit", "Submit the form" }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
//! Run with `cargo-expand` to see what each one expands to
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[inline_props]
|
||||
fn Thing1<T>(cx: Scope, _a: T) -> Element {
|
||||
cx.render(rsx! { "" })
|
||||
}
|
||||
|
||||
#[inline_props]
|
||||
fn Thing2(cx: Scope, _a: u32) -> Element<'a> {
|
||||
cx.render(rsx! { "" })
|
||||
}
|
||||
|
||||
#[inline_props]
|
||||
fn Thing3<'a, T>(cx: Scope<'a>, _a: &'a T) -> Element<'a> {
|
||||
cx.render(rsx! { "" })
|
||||
}
|
||||
|
||||
#[inline_props]
|
||||
fn Thing4<'a>(cx: Scope<'a>, _a: &'a u32) -> Element<'a> {
|
||||
cx.render(rsx! { "" })
|
||||
}
|
||||
|
||||
fn main() {
|
||||
dioxus::desktop::launch(app);
|
||||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let state = use_state(&cx, || 1);
|
||||
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
Thing1 { _a: 1 },
|
||||
Thing2 { _a: 1 },
|
||||
Thing3 { _a: state },
|
||||
Thing4 { _a: state },
|
||||
}
|
||||
})
|
||||
}
|
||||
+11
-10
@@ -14,37 +14,38 @@ fn app(cx: Scope) -> Element {
|
||||
cx.render(rsx! {
|
||||
Button {
|
||||
a: "asd".to_string(),
|
||||
c: Some("asd".to_string()),
|
||||
d: "asd".to_string(),
|
||||
c: "asd".to_string(),
|
||||
d: Some("asd".to_string()),
|
||||
e: "asd".to_string(),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
type SthElse<T> = Option<T>;
|
||||
|
||||
#[derive(Props, PartialEq)]
|
||||
struct ButtonProps {
|
||||
a: String,
|
||||
|
||||
#[props(default)]
|
||||
b: Option<String>,
|
||||
b: String,
|
||||
|
||||
#[props(default)]
|
||||
c: Option<String>,
|
||||
|
||||
#[props(default, strip_option)]
|
||||
#[props(!optional)]
|
||||
d: Option<String>,
|
||||
|
||||
#[props(optional)]
|
||||
e: Option<String>,
|
||||
e: SthElse<String>,
|
||||
}
|
||||
|
||||
fn Button(cx: Scope<ButtonProps>) -> Element {
|
||||
cx.render(rsx! {
|
||||
button {
|
||||
"{cx.props.a}"
|
||||
"{cx.props.b:?}"
|
||||
"{cx.props.c:?}"
|
||||
"{cx.props.d:?}"
|
||||
"{cx.props.a} | "
|
||||
"{cx.props.b:?} | "
|
||||
"{cx.props.c:?} | "
|
||||
"{cx.props.d:?} | "
|
||||
"{cx.props.e:?}"
|
||||
}
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user