1. framework components
  2. toast

Toast

Display brief messages to users.

Usage

This component acts as a Singleton. Implement a single instance of <Toast.Group> in the root scope your application, then trigger it anywhere on demand using a shared createToaster() instance.

tsx
import { toaster } from '/some/path/toaster.ts';
import { Toast } from '@skeletonlabs/skeleton-react';
import type { PropsWithChildren } from 'react';

export default function Layout(props: PropsWithChildren) {
	return (
		<>
			{props.children}
			<Toast.Group toaster={toaster}>
				{(toast) => (
					<Toast toast={toast} key={toast.id}>
						<Toast.Message>
						<Toast.Title>{toast.title}</Toast.Title>
						<Toast.Description>{toast.description}</Toast.Description>
						</Toast.Message>
						<Toast.CloseTrigger />
					</Toast>
				)}
			</Toast.Group>
		</>
	);
}
tsx
import { toaster } from '/some/path/toaster.ts';

export default function Page() {
	function onClickHandler() {
		toaster.info({ title: 'Example', description: 'This is a toast message.' });
	}
	return ();
}

Triggers

Shorthand methods are available for toast triggers, including: info(), success(), warning(), and error().

Or use the generic create() method to trigger toasts of any type: info|success|warning|error.

ts
toaster.create({
	type: 'info',
	title: 'This is a toast',
	description: 'This is a toast description.',
});

Placement

Set the placement value in your createToaster instance to define the global screen position.

Action

Use the action to define a custom button for each toast instance.

Closable

Use the closable prop to toggle display of the close button.

Meta

Use the meta key to pass arbitrary data along with the toast instance. This can be used to display an icon for example.

Promise

Toasts support asynchronous updates using promises.

API Reference

Root

txt
card p-3 w-full md:w-md ring flex items-center gap-2 preset-filled-surface-50-950 ring-surface-200-800 data-[type=success]:preset-filled-success-500 data-[type=warning]:preset-filled-warning-500 data-[type=error]:preset-filled-error-500
PropDefaultType
toastOmit<Options<any>, "id" | "parent">

element((attributes: HTMLAttributes<"div">) => Element) | undefined

Render the element yourself

Context

PropDefaultType
children(toast: ToastApi<PropTypes, any>) => ReactNode

Group

PropDefaultType
toasterToastStore<any>

children((toast: ToastProps<any>) => Element | null) | undefined

element((attributes: HTMLAttributes<"div">) => Element) | undefined

Render the element yourself

Message

txt
flex-1
PropDefaultType
element((attributes: HTMLAttributes<"div">) => Element) | undefined

Render the element yourself

Title

txt
font-medium text-sm
PropDefaultType
element((attributes: HTMLAttributes<"div">) => Element) | undefined

Render the element yourself

Description

txt
text-sm
PropDefaultType
element((attributes: HTMLAttributes<"div">) => Element) | undefined

Render the element yourself

ActionTrigger

txt
btn preset-filled
PropDefaultType
element((attributes: HTMLAttributes<"button">) => Element) | undefined

Render the element yourself

CloseTrigger

txt
btn-icon hover:preset-tonal
PropDefaultType
element((attributes: HTMLAttributes<"button">) => Element) | undefined

Render the element yourself

View page on GitHub