2024-02-14 21:48:58 +00:00
|
|
|
//! Dioxus supports shorthand syntax for creating elements and components.
|
|
|
|
|
2024-01-11 06:41:40 +00:00
|
|
|
use dioxus::prelude::*;
|
|
|
|
|
|
|
|
fn main() {
|
2024-10-10 23:00:58 +00:00
|
|
|
dioxus::launch(app);
|
2024-01-11 06:41:40 +00:00
|
|
|
}
|
|
|
|
|
2024-01-14 04:51:37 +00:00
|
|
|
fn app() -> Element {
|
2024-01-11 06:41:40 +00:00
|
|
|
let a = 123;
|
|
|
|
let b = 456;
|
|
|
|
let c = 789;
|
2024-01-11 06:52:41 +00:00
|
|
|
let class = "class";
|
|
|
|
let id = "id";
|
2024-01-11 06:41:40 +00:00
|
|
|
|
2024-01-11 20:11:27 +00:00
|
|
|
// todo: i'd like it for children on elements to be inferred as the children of the element
|
|
|
|
// also should shorthands understand references/dereferences?
|
|
|
|
// ie **a, *a, &a, &mut a, etc
|
2024-01-16 19:18:46 +00:00
|
|
|
let children = rsx! { "Child" };
|
2024-01-11 20:11:27 +00:00
|
|
|
let onclick = move |_| println!("Clicked!");
|
2024-01-11 07:42:36 +00:00
|
|
|
|
2024-01-16 19:18:46 +00:00
|
|
|
rsx! {
|
2024-01-11 07:52:38 +00:00
|
|
|
div { class, id, {&children} }
|
2024-01-11 20:11:27 +00:00
|
|
|
Component { a, b, c, children, onclick }
|
2024-07-02 03:50:36 +00:00
|
|
|
Component { a, ..ComponentProps { a: 1, b: 2, c: 3, children: VNode::empty(), onclick: Default::default() } }
|
2024-01-11 06:41:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[component]
|
2024-06-11 01:47:07 +00:00
|
|
|
fn Component(
|
|
|
|
a: i32,
|
|
|
|
b: i32,
|
|
|
|
c: i32,
|
|
|
|
children: Element,
|
|
|
|
onclick: EventHandler<MouseEvent>,
|
|
|
|
) -> Element {
|
2024-01-16 19:18:46 +00:00
|
|
|
rsx! {
|
2024-01-11 06:41:40 +00:00
|
|
|
div { "{a}" }
|
|
|
|
div { "{b}" }
|
|
|
|
div { "{c}" }
|
2024-01-11 07:52:38 +00:00
|
|
|
div { {children} }
|
2024-06-11 01:47:07 +00:00
|
|
|
div { onclick }
|
2024-01-11 06:41:40 +00:00
|
|
|
}
|
|
|
|
}
|