Crates.io | dioxus-toast |
lib.rs | dioxus-toast |
version | |
source | src |
created_at | 2022-03-10 02:47:45.593332 |
updated_at | 2024-12-11 21:40:06.659812 |
description | Add toast support in your dioxus project |
homepage | |
repository | https://github.com/mrxiaozhuox/dioxus-toast |
max_upload_size | |
id | 547287 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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 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<ToastManager> = use_context();
rsx! {
button {
onclick: move |_| {
let _ = toast.write().popup(ToastInfo::simple("hello world"));
}
"Click here!"
}
}
}