added new features (for future versions)

This commit is contained in:
2024-12-02 23:14:44 +01:00
parent aee87fcc0c
commit 4bbb44e04a
5 changed files with 32 additions and 34 deletions
+1
View File
@@ -10,6 +10,7 @@
# Misc # Misc
.DS_Store .DS_Store
**/.DS_Store
.env.local .env.local
.env.development.local .env.development.local
.env.test.local .env.test.local
+5 -6
View File
@@ -37,17 +37,16 @@ fn app() -> Element {
// Create a button with a on_click handler // Create a button with a on_click handler
button { button {
on_click: fn(btn: &mut Button, _, document) { on_click: fn(btn: &mut Button, _, document) {
if let Some(count) = document.get_element_by_id::<DataHolder<u32>>("count") { let count = document.use_state::<u32>("count");
count.data += 1; *count += 1;
btn.children.set_text(&count.data.to_string()); btn.children.set_text(&count.to_string());
}
}, },
"0" "0"
} }
// Store the data (in this case count) // Create a elemental field
data_holder as u32 { id: "count" } @count: u32;
} }
} }
``` ```
+11
View File
@@ -93,4 +93,15 @@ fn app() -> Element {
} }
} }
} }
```
## Variables
Instead of creating a `data_holder as u32` manually you can just define a variable with `@name: type;`
> :::info Put this on the end of the rsx to avoid any conflicts with existing elements
```rust
fn app() -> Element {
rsx! {
@count: u32;
}
}
``` ```
+12 -27
View File
@@ -4,7 +4,8 @@ title: CSS
Along with the `Css` type, This macro provides styling for multiple elements by their class name or struct name. Along with the `Css` type, This macro provides styling for multiple elements by their class name or struct name.
## Style by classname ## Example
In this case we will make a button with the classname `my_btn`. And set `styling`
```rust ```rust
fn app() -> Element { fn app() -> Element {
rsx! { rsx! {
@@ -13,29 +14,19 @@ fn app() -> Element {
button { class: "my_btn", "Click me!" } button { class: "my_btn", "Click me!" }
} }
} }
fn styles() -> Css {
css! {
.my_btn { // style by classname
color: Red,
}
}
}
``` ```
## Style by state ## Style by classname
```rust ```rust
fn app() -> Element {
rsx! {
styling: Some(styles()) // Set the css styling for the div.
button { class: "my_btn", "Click me!" }
}
}
fn styles() -> Css { fn styles() -> Css {
css! { css! {
.my_btn: clicked { // When the element state is clicked "my_btn" { // style by classname
color: Red,
}
// Style by state
"my_btn": clicked { // When the element state is clicked
color: Blue, color: Blue,
} }
} }
@@ -44,20 +35,14 @@ fn styles() -> Css {
## Style by struct name ## Style by struct name
```rust ```rust
fn app() -> Element {
rsx! {
styling: Some(styles()) // Set the css styling for the div.
button { "Click me!" } // No need for classes
}
}
fn styles() -> Css { fn styles() -> Css {
css! { css! {
Button { // style by the struct name Button { // style by the struct name
color: Red, color: Red,
} }
// Style by state
Button: clicked { // When the element state is clicked Button: clicked { // When the element state is clicked
color: Blue, color: Blue,
} }
+3 -1
View File
@@ -25,4 +25,6 @@ Retrieves a mutable reference to a boxed element of type T by its string identif
> :::warn Not recommended to use this function, Use `get_element_by_id` instead > :::warn Not recommended to use this function, Use `get_element_by_id` instead
Retrieves a mutable reference to a boxed element by its string identifier, returning None if no such element exists Retrieves a mutable reference to a boxed element by its string identifier, returning None if no such element exists
### `render()` ### `render()`
Renders/reloads the screen, useful when a element updates Renders/reloads the screen, useful when a element updates
### `use_state<T>(name: &str) -> &mut T`
Gets element (DataHolder) by id and returns the data of it: `&mut T`