fix: some examples

This commit is contained in:
Jonathan Kelley committed 2022-03-05 15:25:09 -05:00
1 parent f98c3f161f
commit 35b22923b2
7 files changed
+63 -44

No files matched your search

+1 -1
View File
@@ -12,7 +12,7 @@ fn main() {
fn app(cx: Scope) -> Element { fn app(cx: Scope) -> Element {
cx.render(rsx!( cx.render(rsx!(
div { div {
h1 { "drag an file here" } h1 { "drag a file here and check your console" }
} }
)) ))
} }
-3
View File
@@ -104,7 +104,6 @@ fn app(cx: Scope) -> Element {
// elements with driven values will preventdefault automatically. // elements with driven values will preventdefault automatically.
// you can disable this override with preventdefault: false // you can disable this override with preventdefault: false
div { div {
input { input {
id: "pdf", id: "pdf",
@@ -121,8 +120,6 @@ fn app(cx: Scope) -> Element {
} }
} }
FIELDS.iter().map(|(field, value)| rsx!( FIELDS.iter().map(|(field, value)| rsx!(
div { div {
input { input {
+14 -2
View File
@@ -10,7 +10,7 @@ fn app(cx: Scope) -> Element {
p { p {
a { a {
href: "http://dioxuslabs.com/", href: "http://dioxuslabs.com/",
"default link" "Default link - links outside of your app"
} }
} }
p { p {
@@ -20,7 +20,19 @@ fn app(cx: Scope) -> Element {
onclick: |_| { onclick: |_| {
println!("Hello Dioxus"); println!("Hello Dioxus");
}, },
"custom event link", "Custom event link - links inside of your app",
}
}
}
div {
Router {
Route { to: "/", h1 { "Home" } },
Route { to: "/settings", h1 { "settings" } },
p { "----"}
ul {
Link { to: "/", li { "Router link to home" } },
Link { to: "/settings", li { "Router link to settings" } },
} }
} }
} }
+3 -1
View File
@@ -14,6 +14,8 @@ fn app(cx: Scope) -> Element {
cx.render(rsx! { cx.render(rsx! {
div { div {
onclick: move |_| println!("clicked! top"), onclick: move |_| println!("clicked! top"),
"- div"
button { button {
onclick: move |_| println!("clicked! bottom propoate"), onclick: move |_| println!("clicked! bottom propoate"),
"Propogate" "Propogate"
@@ -26,7 +28,7 @@ fn app(cx: Scope) -> Element {
"Dont propogate" "Dont propogate"
} }
button { button {
"Does not handle clicks" "Does not handle clicks - only propogate"
} }
} }
}) })
+9 -10
View File
@@ -13,18 +13,17 @@ fn app(cx: Scope) -> Element {
Router { Router {
ul { ul {
Link { to: "/", li { "Go home!" } } Link { to: "/", li { "Go home!" } }
Link { to: "users", li { "List all users" } } Link { to: "/users", li { "List all users" } }
Link { to: "blog", li { "Blog posts" } } Link { to: "/blog", li { "Blog posts" } }
Link { to: "/users/bill", li { "List all users" } }
Link { to: "/blog/5", li { "Blog post 5" } }
} }
Route { to: "/", "Home" } Route { to: "/", "Home" }
Route { to: "users", Route { to: "/users", "User list" }
Route { to: "/", "User list" } Route { to: "/users/:name", User {} }
Route { to: ":name", User {} } Route { to: "/blog", "Blog list" }
} Route { to: "/blog/:post", BlogPost {} }
Route { to: "blog"
Route { to: "/", "Blog list" }
Route { to: ":post", BlogPost {} }
}
Route { to: "", "Err 404 Route Not Found" } Route { to: "", "Err 404 Route Not Found" }
} }
}) })
+35 -26
View File
@@ -118,34 +118,43 @@ pub fn todo_entry<'a>(cx: Scope<'a, TodoEntryProps<'a>>) -> Element {
let completed = if todo.checked { "completed" } else { "" }; let completed = if todo.checked { "completed" } else { "" };
let editing = if **is_editing { "editing" } else { "" }; let editing = if **is_editing { "editing" } else { "" };
rsx!(cx, li { cx.render(rsx!{
class: "{completed} {editing}", li {
div { class: "view", class: "{completed} {editing}",
input { class: "toggle", r#type: "checkbox", id: "cbg-{todo.id}", checked: "{todo.checked}", div { class: "view",
onchange: move |evt| {
cx.props.todos.make_mut()[&cx.props.id].checked = evt.value.parse().unwrap(); input {
class: "toggle",
r#type: "checkbox",
id: "cbg-{todo.id}",
checked: "{todo.checked}",
oninput: move |evt| {
cx.props.todos.make_mut()[&cx.props.id].checked = evt.value.parse().unwrap();
}
}
label {
r#for: "cbg-{todo.id}",
onclick: move |_| is_editing.set(true),
prevent_default: "onclick",
"{todo.contents}"
} }
} }
label { is_editing.then(|| rsx!{
r#for: "cbg-{todo.id}", input {
onclick: move |_| is_editing.set(true), class: "edit",
"{todo.contents}" value: "{todo.contents}",
} oninput: move |evt| cx.props.todos.make_mut()[&cx.props.id].contents = evt.value.clone(),
autofocus: "true",
onfocusout: move |_| is_editing.set(false),
onkeydown: move |evt| {
match evt.key.as_str() {
"Enter" | "Escape" | "Tab" => is_editing.set(false),
_ => {}
}
},
}
})
} }
is_editing.then(|| rsx!{
input {
class: "edit",
value: "{todo.contents}",
oninput: move |evt| cx.props.todos.make_mut()[&cx.props.id].contents = evt.value.clone(),
autofocus: "true",
onfocusout: move |_| is_editing.set(false),
onkeydown: move |evt| {
match evt.key.as_str() {
"Enter" | "Escape" | "Tab" => is_editing.set(false),
_ => {}
}
},
}
})
}) })
} }
+1 -1
View File
@@ -33,7 +33,7 @@ pub mod prelude {
pub use dioxus_html as dioxus_elements; pub use dioxus_html as dioxus_elements;
#[cfg(feature = "router")] #[cfg(feature = "router")]
pub use dioxus_router::{use_route, use_router, Link, Redirect, Router, UseRoute}; pub use dioxus_router::{use_route, use_router, Link, Redirect, Router, UseRoute, Route};
#[cfg(feature = "fermi")] #[cfg(feature = "fermi")]
pub use fermi::{use_atom_ref, use_init_atom_root, use_read, use_set, Atom, AtomRef}; pub use fermi::{use_atom_ref, use_init_atom_root, use_read, use_set, Atom, AtomRef};