diff --git a/src/hooks/useToastContainer.ts b/src/hooks/useToastContainer.ts index 8fd44db1..0d566fc7 100644 --- a/src/hooks/useToastContainer.ts +++ b/src/hooks/useToastContainer.ts @@ -10,7 +10,6 @@ import { import { parseClassName, canBeRendered, - isBool, isFn, isNum, isStr, @@ -28,8 +27,7 @@ import { Toast, ToastPosition, ClearWaitingQueueParams, - NotValidatedToastProps, - ToastTransition + NotValidatedToastProps } from '../types'; import { getIcon } from '../components/Icons'; @@ -137,57 +135,25 @@ export function useToastContainer(props: ToastContainerProps) { if (isNotAnUpdate) instance.count++; - const toastProps: ToastProps = { + const toastProps = { + ...props, + ...options, toastId, updateId, data, - containerId: options.containerId, - isLoading: options.isLoading, - theme: options.theme || props.theme!, - icon: options.icon ?? props.icon, + closeToast, isIn: false, key: options.key || instance.toastKey++, - type: options.type!, - closeToast: closeToast, - closeButton: options.closeButton, - rtl: props.rtl, - position: options.position || (props.position as ToastPosition), - transition: options.transition || (props.transition as ToastTransition), className: parseClassName(options.className || props.toastClassName), bodyClassName: parseClassName( options.bodyClassName || props.bodyClassName ), - style: options.style || props.toastStyle, - bodyStyle: options.bodyStyle || props.bodyStyle, - onClick: options.onClick || props.onClick, - pauseOnHover: isBool(options.pauseOnHover) - ? options.pauseOnHover - : props.pauseOnHover, - pauseOnFocusLoss: isBool(options.pauseOnFocusLoss) - ? options.pauseOnFocusLoss - : props.pauseOnFocusLoss, - draggable: isBool(options.draggable) - ? options.draggable - : props.draggable, - draggablePercent: - options.draggablePercent || (props.draggablePercent as number), - draggableDirection: - options.draggableDirection || props.draggableDirection, - closeOnClick: isBool(options.closeOnClick) - ? options.closeOnClick - : props.closeOnClick, progressClassName: parseClassName( options.progressClassName || props.progressClassName ), - progressStyle: options.progressStyle || props.progressStyle, autoClose: options.isLoading ? false : getAutoCloseDelay(options.autoClose, props.autoClose), - hideProgressBar: isBool(options.hideProgressBar) - ? options.hideProgressBar - : props.hideProgressBar, - progress: options.progress, - role: options.role || props.role, deleteToast() { const removed = toToastItem(toastToRender.get(toastId)!, 'removed'); toastToRender.delete(toastId); @@ -217,7 +183,7 @@ export function useToastContainer(props: ToastContainerProps) { forceUpdate(); } } - }; + } as ToastProps; toastProps.iconOut = getIcon(toastProps); diff --git a/src/types/index.ts b/src/types/index.ts index be478c40..a62b0a62 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -205,7 +205,7 @@ export interface ToastOptions extends CommonOptions { /** * @deprecated * ⚠️ Will be removed in the next major release. You can rely on `toast.onChange` instead. - * + * * Called when toast is unmounted. */ onClose?: (props: T) => void; diff --git a/src/utils/propValidator.ts b/src/utils/propValidator.ts index 6511ff3e..c81de53a 100644 --- a/src/utils/propValidator.ts +++ b/src/utils/propValidator.ts @@ -3,8 +3,6 @@ import { isValidElement } from 'react'; export const isNum = (v: any): v is Number => typeof v === 'number' && !isNaN(v); -export const isBool = (v: any): v is Boolean => typeof v === 'boolean'; - export const isStr = (v: any): v is String => typeof v === 'string'; export const isFn = (v: any): v is Function => typeof v === 'function';