dioxus-toast

Crates.iodioxus-toast
lib.rsdioxus-toast
version0.4.0
sourcesrc
created_at2022-03-10 02:47:45.593332
updated_at2024-09-09 16:10:03.071034
descriptionAdd toast support in your dioxus project
homepage
repositoryhttps://github.com/mrxiaozhuox/dioxus-toast
max_upload_size
id547287
size147,495
YuKun Liu (mrxiaozhuox)

documentation

README

Dioxus Toast

Add toast support for your dioxus project.

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"
            }
        }
    }
}

Commit count: 54

cargo fmt