UNPKG

@lifespikes/ui

Version:
54 lines (53 loc) 1.59 kB
import * as React from 'react'; import type { ToastActionElement, ToastProps, ToastVariantType } from './toast'; type ToasterToast = ToastProps & { id: string; title?: React.ReactNode; description?: React.ReactNode; action?: ToastActionElement; }; declare const actionTypes: { readonly ADD_TOAST: "ADD_TOAST"; readonly UPDATE_TOAST: "UPDATE_TOAST"; readonly DISMISS_TOAST: "DISMISS_TOAST"; readonly REMOVE_TOAST: "REMOVE_TOAST"; }; type ActionType = typeof actionTypes; type Action = { type: ActionType['ADD_TOAST']; toast: ToasterToast; } | { type: ActionType['UPDATE_TOAST']; toast: Partial<ToasterToast>; } | { type: ActionType['DISMISS_TOAST']; toastId?: ToasterToast['id']; } | { type: ActionType['REMOVE_TOAST']; toastId?: ToasterToast['id']; }; interface State { toasts: ToasterToast[]; } export declare const reducer: (state: State, action: Action) => State; type Toast = Omit<ToasterToast, 'id'>; declare const toast: (props: Toast) => { id: string; dismiss: () => void; update: (props: ToasterToast) => void; }; declare const useToaster: () => { toast: (props: Toast) => { id: string; dismiss: () => void; update: (props: ToasterToast) => void; }; dismiss: (toastId?: string) => void; toasts: ToasterToast[]; }; export type UseToasterReturn = ReturnType<typeof useToaster>; export type UseToastReturn = { [variant in ToastVariantType]: (props: Toast) => UseToasterReturn; }; declare const useToast: () => UseToastReturn; export { useToaster, toast, useToast };