Install Sileo via npm
mainInstall the sileo package using npm to use the physics-based toast component in your React project.
npm i sileorepository·main·Indexed 23 days ago
https://github.com/hiaaryan/sileoAn opinionated, physics-based toast notification library for React applications. Built with Framer Motion, it features a 'gooey' SVG effect for smooth transitions between states such as success, loading, error, warning, info, and action. It supports automatic expansion/collapse, swipe-to-dismiss functionality, and a promise-based API to manage asynchronous notification lifecycles.
Install the sileo package using npm to use the physics-based toast component in your React project.
npm i sileoTo use Sileo, you must include the Toaster component at the root of your application. The Toaster accepts a position prop to determine where toasts will appear (e.g., top-right). You can then use the sileo function to trigger toasts.
import { sileo, Toaster } from "sileo";
export default function App() {
return (
<>
<Toaster position="top-right" />
<YourApp />
</>
);
}Toasts can be configured with an autopilot setting within their options to control how they behave when they appear or disappear. This is useful for managing how long a toast stays expanded or how quickly it collapses.
autopilot can be a boolean or an object:
autopilot: true: Uses default delays.autopilot: { expand: number, collapse: number }: Sets custom delay durations in milliseconds.Note: If duration is set to null, the toast will not auto-dismiss.
Sileo features two modes of interaction:
description or button is provided, the toast can expand from a small 'pill' into a larger notification. Expansion can be triggered by hovering (onMouseEnter) or automatically via autoExpandDelayMs. When expanded, the component shows the description and any button provided.onDismiss callback is triggered if the swipe distance exceeds the internal threshold (SWIPE_DISMISS).Note on Refreshing: To update the content of an already visible toast (e.g., changing a state from loading to success), use the refreshKey prop. This ensures smooth transitions between different view states.
Sileo provides a set of pre-defined SVG icon components that can be used in your UI, such as within toast notifications. These components accept standard SVGProps<SVGSVGElement> (like className, style, width, height, etc.), allowing you to customize their appearance.
Available icons include:
ArrowRightLifeBuoyLoaderCircleXCircleAlertCheckSileo component is a highly customizable toast/notification component built with React and Framer Motion. It supports various states (success, loading, error, warning, info, action), automatic expansion/collapse, and interactive elements like buttons. It uses an SVG-based 'gooey' effect for smooth transitions between states and can be positioned at the left, center, or right of the viewport.sileo and Toaster from the root package to manage toast notifications in your application. sileo is the primary functional entrypoint, while Toaster is the component responsible for rendering the notifications.The sileo object provides a programmatic API to trigger different types of toast notifications. Most methods return a unique id which can be used to manually dismiss or update the toast later.
show(opts): Triggers a generic toast.success(opts): Triggers a success state toast.error(opts): Triggers an error state toast.warning(opts): Triggers a warning state toast.info(opts): Triggers an info state toast.action(opts): Triggers an action state toast.dismiss(id): Manually removes a specific toast by its ID.clear(position?): Removes all toasts, or all toasts at a specific SileoPosition if provided.The promise method allows you to link the lifecycle of a toast to a JavaScript Promise. It automatically manages a 'loading' state and transitions to 'success', 'error', or 'action' based on the promise outcome.
loading: SileoOptions used while the promise is pending.success: SileoOptions or a callback (data: T) => SileoOptions used when the promise resolves.error: SileoOptions or a callback (err: unknown) => SileoOptions used when the promise rejects.action: (Optional) SileoOptions or a callback (data: T) => SileoOptions used if an action state is desired after resolution.position: The position for the toast lifecycle.The Toaster component is the UI entry point that renders toast notifications. It should be placed at the top level of your application. It accepts configuration for positioning, offsets, global options, and themes.
position: The default position for toasts (e.g., top-right).offset: A number, string, or SileoOffsetConfig object to define the distance from the viewport edges.options: Global SileoOptions applied to all toasts.theme: Sets the color scheme to 'light', 'dark', or 'system' (which follows the user's OS preference).The SileoOptions interface defines the configuration for a Sileo notification. You can customize the content, visual appearance, behavior, and positioning using the following keys:
title: The title of the notification.description: The body text (can be a string or a ReactNode).type: The semantic state of the notification (e.g., success, error).position: Where the notification appears on the screen.duration: How long the notification stays visible (in milliseconds). Set to null to disable auto-dismiss.icon: An optional ReactNode or null to hide the icon.styles: Custom CSS class names for title, description, badge, and button.fill: A string for the background color/fill.roundness: A number representing the border radius.autopilot: Controls automatic expansion/collapse behavior. Can be a boolean or an object { expand?: number; collapse?: number }.button: An optional SileoButton object containing a title and an onClick handler.export interface SileoOptions {
title?: string;
description?: ReactNode | string;
type?: SileoState;
position?: SileoPosition;
duration?: number | null;
icon?: ReactNode | null;
styles?: SileoStyles;
fill?: string;
roundness?: number;
autopilot?: boolean | { expand?: number; collapse?: number };
button?: SileoButton;
}The SileoPosition type defines where the notification is anchored on the screen. The available positions are:
top-lefttop-centertop-rightbottom-leftbottom-centerbottom-rightexport const SILEO_POSITIONS = [
"top-left",
"top-center",
"top-right",
"bottom-left",
"bottom-center",
"bottom-right",
] as const;
export type SileoPosition = (typeof SILEO_POSITIONS)[number];