leptos_toaster

Crates.ioleptos_toaster
lib.rsleptos_toaster
version0.1.7
sourcesrc
created_at2024-02-06 19:26:54.342465
updated_at2024-05-20 16:06:50.106789
descriptionA Toaster component for Leptos
homepage
repositoryhttps://github.com/SorenHolstHansen/leptos_toaster
max_upload_size
id1129371
size537,457
Søren Hansen (SorenHolstHansen)

documentation

README

Example

leptos_toaster

A Toaster component for Leptos heavily inspired by sonner

SSR

If using SSR don't forget to set the features in your own Project correctly

[features]
ssr = ["leptos_toaster/ssr"]
hydrate = ["leptos_toaster/hydrate"]

Usage

Somewhere, probably near the top of your component tree, add the Toaster component

view! {
	<Toaster
	    position=toaster::ToasterPosition::BottomCenter
	>
		// ...
	</Toaster>
}

and then whenever you need a toast, do

let toast_context = expect_context::<Toasts>();

let create_toast = move || {
	let toast_id = ToastId::new();
	toast_context.toast(
		// This uses the built in toast component that requires the `builtin_toast` feature.
		// You can use your own components here
		view! { 
			<Toast 
				toast_id 
				variant=ToastVariant::Info 
				title=view! {"My toast"}.into_view() 
			/> 
		},
		Some(toast_id),
		None // options
	);
}
Commit count: 56

cargo fmt