use crate::{mount_style::mount_style, types::dismiss_toast, ToastId}; use leptos::*; #[component] fn SuccessIcon() -> impl IntoView { view! { } } #[component] fn WarningIcon() -> impl IntoView { view! { } } #[component] fn InfoIcon() -> impl IntoView { view! { } } #[component] fn ErrorIcon() -> impl IntoView { view! { } } #[derive(PartialEq, Clone, Copy)] pub enum ToastVariant { Normal, Success, Info, Warning, Error, } impl ToString for ToastVariant { fn to_string(&self) -> String { match self { ToastVariant::Normal => "normal".to_string(), ToastVariant::Success => "success".to_string(), ToastVariant::Info => "info".to_string(), ToastVariant::Warning => "warning".to_string(), ToastVariant::Error => "error".to_string(), } } } #[derive(Clone)] pub enum Theme { Light, Dark, } impl std::fmt::Display for Theme { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Theme::Light => write!(f, "light"), Theme::Dark => write!(f, "dark"), } } } /// Built in toast component to use with the toast() function if you don't want to roll your own #[component] pub fn Toast( #[prop(default = ToastVariant::Normal)] variant: ToastVariant, title: View, #[prop(default = None)] description: Option, toast_id: ToastId, #[prop(default = true)] close_button: bool, #[prop(default = Theme::Light)] theme: Theme, #[prop(default = false)] invert: bool, #[prop(default = false)] rich_colors: bool, ) -> impl IntoView { mount_style("builtin_toast", include_str!("./builtin_toast.css")); view! {
{match variant { ToastVariant::Normal => view! {}.into_view(), ToastVariant::Success => view! { }.into_view(), ToastVariant::Info => view! { }.into_view(), ToastVariant::Warning => view! { }.into_view(), ToastVariant::Error => view! { }.into_view(), }}
{title}
{description}
} }