Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mrxiaozhuox/dioxus-toast
dioxus-toast
https://github.com/mrxiaozhuox/dioxus-toast
Last synced: 18 days ago
JSON representation
dioxus-toast
- Host: GitHub
- URL: https://github.com/mrxiaozhuox/dioxus-toast
- Owner: mrxiaozhuox
- License: mit
- Created: 2022-02-24T10:47:41.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-16T15:27:11.000Z (about 2 months ago)
- Last Synced: 2024-10-11T01:51:05.514Z (about 1 month ago)
- Language: Rust
- Size: 11.1 MB
- Stars: 16
- Watchers: 1
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Dioxus Toast
Add toast support for your dioxus project.
```rust
use dioxus::prelude::*;
use dioxus_toast::{ToastInfo, ToastManager};fn main() {
launch(app)
}fn app() -> Element {
std::panic::set_hook(Box::new(|info| {
println!("Panic: {}", info);
}));let mut toast = use_signal(|| ToastManager::default());
rsx! {
dioxus_toast::ToastFrame {
manager: toast
}
div {
button {
onclick: move |_| {
let _id = toast.write().popup(ToastInfo::simple("hello world"));
println!("New Toast ID: {}", _id);
},
"Normal Toast"
}
button {
onclick: move |_| {
let _id = toast.write().popup(ToastInfo::success("Hello World!", "Success"));
println!("New Toast ID: {}", _id);
},
"Success Toast"
}
button {
onclick: move |_| {
let _id = toast.write().popup(ToastInfo {
heading: Some("top-right".into()),
context: "Top Right Toast".into(),
allow_toast_close: true,
position: dioxus_toast::Position::TopRight,
icon: None,
hide_after: None
});
},
"Top Right"
}
}
}
}```
## Use Toast for different component.
```rust
use dioxus::prelude::*;fn main() {
launch(app)
}fn app() -> Element {
let toast = use_context_provider(|| Signal::new(ToastManager::default()));
rsx! {
ToastFrame { manager: toast }
div {
hello {}
}
}
}#[component]
fn hello() -> Element {
// use_context can help you pass toast-manager to different components
let mut toast: Signal = use_context();
rsx! {
button {
onclick: move |_| {
let _ = toast.write().popup(ToastInfo::simple("hello world"));
}
"Click here!"
}
}
}
```