some nice dynamic stuff

This commit is contained in:
2024-12-12 17:14:48 +01:00
parent 250528950a
commit b4c4e32aba
7 changed files with 129 additions and 135 deletions
+16 -40
View File
@@ -1,55 +1,31 @@
use crate::prelude::*;
pub fn examples() -> Element {
rsx! {
styling: Some(styling()),
button { class: "btn", on_click: fn(btn: &mut Button, _, document) {
let count = document.use_state::<u32>("count");
*count += 1;
btn.children.set_text(&count.to_string());
if *count == 10 {
document.exit();
}
}, "Click me!" }
text { "Welcome!" }
@count: i32;
}
}
pub fn todo_app() -> Element {
let count = State::new(0);
rsx! {
styling: Some(styling()),
class: "root",
div {
class: "tab",
text { class: "title", "not started" }
text { class: "todo", "TODO: Something" }
}
div {
class: "tab",
text { class: "title", "completed" }
}
button { on_click: fn(_, _, _) @count {
let mut count = count.use_state();
*count += 1;
}, class: "btn", "Count: {count}" }
}
}
pub fn styling() -> Css {
css! {
"tab" {
x: Auto,
width: 50%,
outline: true,
}
"title" {
width: Auto,
color: Red,
}
"todo" {
x: 0 px,
y: Auto,
color: Green,
x: Center,
}
"container" {
width: 50%,
}
"btn": "clicked" {
color: Red
}
}
}