UNPKG

@buun_group/brutalist-ui

Version:
116 lines (115 loc) 3.29 kB
/** * @module Toast * @description A notification system with support for different types, positioning, and actions. Provides both hook-based and imperative APIs for showing temporary messages to users. */ import React, { CSSProperties } from 'react'; /** * Available toast notification types */ export type ToastType = 'info' | 'success' | 'warning' | 'error'; /** * Available positions for toast notifications */ export type ToastPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right'; /** * Data structure for a toast notification */ export interface ToastData { /** * Unique identifier for the toast */ id: string; /** * Type of the notification affecting appearance and icon */ type: ToastType; /** * Optional title displayed above the message */ title?: string; /** * Main message content of the toast */ message: string; /** * Duration in milliseconds before auto-dismissal (0 = no auto-dismiss) * @default 5000 */ duration?: number; /** * Whether the toast can be manually dismissed by the user * @default true */ dismissible?: boolean; /** * Optional action button configuration */ action?: { /** * Text label for the action button */ label: string; /** * Callback function when action button is clicked */ onClick: () => void; }; } /** * Context value interface for toast management */ interface ToastContextValue { /** * Array of currently active toasts */ toasts: ToastData[]; /** * Function to display a new toast notification */ showToast: (toast: Omit<ToastData, 'id'>) => string; /** * Function to hide a specific toast by ID */ hideToast: (id: string) => void; /** * Function to hide all active toasts */ hideAllToasts: () => void; } /** * Props for the ToastProvider component */ export interface ToastProviderProps { /** * Child components that will have access to toast functionality */ children: React.ReactNode; /** * Position where toasts should appear on screen * @default 'bottom-right' */ position?: ToastPosition; /** * Maximum number of toasts to display at once * @default 5 */ maxToasts?: number; /** * Additional CSS classes to apply to the toast container */ className?: string; /** * Custom styles to apply to the toast container */ style?: CSSProperties; } export declare const ToastProvider: React.FC<ToastProviderProps>; export declare const useToast: () => ToastContextValue; export declare const registerToastStore: (store: ToastContextValue) => void; export declare const toast: { info: (message: string, options?: Partial<Omit<ToastData, "id" | "type" | "message">>) => string; success: (message: string, options?: Partial<Omit<ToastData, "id" | "type" | "message">>) => string; warning: (message: string, options?: Partial<Omit<ToastData, "id" | "type" | "message">>) => string; error: (message: string, options?: Partial<Omit<ToastData, "id" | "type" | "message">>) => string; }; export {};