sileo

The global toast controller. Import it anywhere to fire toasts.

import { sileo } from "sileo";

Methods

MethodDescription
sileo.success(options)Green success toast
sileo.error(options)Red error toast
sileo.warning(options)Amber warning toast
sileo.info(options)Blue info toast
sileo.action(options)Toast with an action button
sileo.show(options)Generic toast (defaults to success state)
sileo.promise(promise, opts)Loading → success/error flow
sileo.dismiss(id)Dismiss a specific toast by id
sileo.clear(position?)Clear all toasts, or only those at a specific position

All shortcut methods return the toast id as a string. promise returns the original promise. dismiss and clear return void.


SileoOptions

Passed to every sileo.*() method.

PropTypeDefaultDescription
titlestringToast heading
descriptionReactNode | stringBody content, supports JSX
positionSileoPositionToaster defaultOverride position for this toast
durationnumber | null6000Auto-dismiss ms. null = sticky
iconReactNode | nullState iconCustom icon in the badge
fillstring"#FFFFFF"SVG fill color for the toast background
stylesSileoStylesClass overrides for sub-elements
roundnessnumber16Border radius in pixels
autopilotboolean | objecttrueAuto expand/collapse timing
buttonSileoButtonAction button config

SileoButton

interface SileoButton {
  title: string;
  onClick: () => void;
}

SileoStyles

Override classes for individual toast sub-elements.

interface SileoStyles {
  title?: string;
  description?: string;
  badge?: string;
  button?: string;
}
sileo.success({
  title: "Custom styled",
  fill: "black",
  styles: {
    title: "text-white!",
    description: "text-white/75!",
    badge: "bg-white/20!",
    button: "bg-white/10!",
  },
});

SileoPromiseOptions

Passed as the second argument to sileo.promise().

interface SileoPromiseOptions<T = unknown> {
  loading: SileoOptions;
  success: SileoOptions | ((data: T) => SileoOptions);
  error: SileoOptions | ((err: unknown) => SileoOptions);
  action?: SileoOptions | ((data: T) => SileoOptions);
  position?: SileoPosition;
}

The success and error fields can be static options or callbacks that receive the resolved/rejected value. The optional action field, when provided, replaces the success toast with an action state instead.

sileo.promise(createUser(data), {
  loading: { title: "Creating account..." },
  success: (user) => ({
    title: `Welcome, ${user.name}!`,
  }),
  error: (err) => ({
    title: "Signup failed",
    description: err.message,
  }),
});