Components participate in event handlers
This commit is contained in:
12 files changed
+86
-54
No files matched your search
+17
-4
@@ -11,22 +11,35 @@ fn app(cx: Scope) -> Element {
|
||||
let class = "class";
|
||||
let id = "id";
|
||||
|
||||
// todo: i'd like it for children to be inferred
|
||||
// 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
|
||||
let children = render! { "Child" };
|
||||
let onclick = move |_| println!("Clicked!");
|
||||
|
||||
render! {
|
||||
div { class, id, {&children} }
|
||||
Component { a, b, c, children }
|
||||
Component { a, ..ComponentProps { a: 1, b: 2, c: 3, children: None } }
|
||||
Component { a, b, c, children, onclick }
|
||||
Component { a, ..ComponentProps { a: 1, b: 2, c: 3, children: None, onclick: Default::default() } }
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn Component<'a>(cx: Scope<'a>, a: i32, b: i32, c: i32, children: Element<'a>) -> Element {
|
||||
fn Component<'a>(
|
||||
cx: Scope<'a>,
|
||||
a: i32,
|
||||
b: i32,
|
||||
c: i32,
|
||||
children: Element<'a>,
|
||||
onclick: EventHandler<'a, ()>,
|
||||
) -> Element {
|
||||
render! {
|
||||
div { "{a}" }
|
||||
div { "{b}" }
|
||||
div { "{c}" }
|
||||
div { {children} }
|
||||
div {
|
||||
onclick: move |_| onclick.call(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user