2021-03-11 17:27:01 +00:00
|
|
|
#![allow(non_snake_case)]
|
2021-03-02 05:14:28 +00:00
|
|
|
use dioxus_core as dioxus;
|
2021-03-11 17:27:01 +00:00
|
|
|
use dioxus::prelude::*;
|
2021-03-02 05:14:28 +00:00
|
|
|
use dioxus_web::WebsysRenderer;
|
|
|
|
|
|
|
|
fn main() {
|
2021-03-11 17:27:01 +00:00
|
|
|
wasm_logger::init(wasm_logger::Config::new(log::Level::Trace));
|
|
|
|
console_error_panic_hook::set_once();
|
2021-03-13 15:02:57 +00:00
|
|
|
|
|
|
|
wasm_bindgen_futures::spawn_local(async {
|
|
|
|
WebsysRenderer::new_with_props(Example, ExampleProps { initial_name: "..?", blarg: Vec::new()})
|
|
|
|
.run()
|
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
});
|
2021-03-02 05:14:28 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 22:21:06 +00:00
|
|
|
#[derive(PartialEq, Props)]
|
|
|
|
struct ExampleProps {
|
2021-03-13 15:02:57 +00:00
|
|
|
initial_name: &'static str,
|
|
|
|
blarg: Vec<String>
|
2021-03-12 22:21:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static Example: FC<ExampleProps> = |ctx, props| {
|
|
|
|
let (name, set_name) = use_state(&ctx, move || props.initial_name);
|
2021-03-02 05:14:28 +00:00
|
|
|
|
2021-03-13 15:02:57 +00:00
|
|
|
let sub = props.blarg.last().unwrap();
|
|
|
|
|
2021-03-02 05:14:28 +00:00
|
|
|
ctx.render(rsx! {
|
2021-03-02 06:24:53 +00:00
|
|
|
div {
|
|
|
|
class: "py-12 px-4 text-center w-full max-w-2xl mx-auto"
|
|
|
|
span {
|
2021-03-02 05:14:28 +00:00
|
|
|
class: "text-sm font-semibold"
|
2021-03-02 06:24:53 +00:00
|
|
|
"Dioxus Example: Jack and Jill"
|
2021-03-02 05:14:28 +00:00
|
|
|
}
|
2021-03-02 06:24:53 +00:00
|
|
|
h2 {
|
2021-03-02 05:14:28 +00:00
|
|
|
class: "text-5xl mt-2 mb-6 leading-tight font-semibold font-heading"
|
2021-03-02 06:24:53 +00:00
|
|
|
"Hello, {name}"
|
2021-03-02 05:14:28 +00:00
|
|
|
}
|
2021-03-13 15:02:57 +00:00
|
|
|
|
|
|
|
CustomButton { name: sub, set_name: Box::new(move || set_name("jack")) }
|
|
|
|
// CustomButton { name: "Jack!", set_name: Box::new(move || set_name("jack")) }
|
|
|
|
// CustomButton { name: "Jill!", set_name: Box::new(move || set_name("jill")) }
|
|
|
|
// CustomButton { name: "Reset!", set_name: Box::new(move || set_name(props.initial_name)) }
|
2021-03-02 05:14:28 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
};
|
2021-03-12 22:21:06 +00:00
|
|
|
|
2021-03-13 15:02:57 +00:00
|
|
|
#[derive(Props)]
|
|
|
|
struct ButtonProps<'src> {
|
|
|
|
name: &'src String,
|
|
|
|
// name: &'src str,
|
|
|
|
set_name: Box< dyn Fn() + 'src>
|
|
|
|
}
|
|
|
|
impl PartialEq for ButtonProps<'_> {
|
|
|
|
fn eq(&self, other: &Self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn CustomButton<'a>(ctx: Context<'a>, props: &'a ButtonProps<'a>) -> DomTree {
|
2021-03-12 22:21:06 +00:00
|
|
|
ctx.render(rsx!{
|
2021-03-13 15:02:57 +00:00
|
|
|
button {
|
|
|
|
class: "inline-block py-4 px-8 mr-6 leading-none text-white bg-indigo-600 hover:bg-indigo-900 font-semibold rounded shadow"
|
|
|
|
onmouseover: move |_| (props.set_name)()
|
|
|
|
"{props.name}"
|
2021-03-12 22:21:06 +00:00
|
|
|
}
|
|
|
|
})
|
2021-03-13 15:02:57 +00:00
|
|
|
}
|
2021-03-12 22:21:06 +00:00
|
|
|
|