diff --git a/src/toast.tsx b/src/toast.tsx index 4801a82..f5ef2e9 100644 --- a/src/toast.tsx +++ b/src/toast.tsx @@ -310,15 +310,15 @@ export const Toast = React.forwardRef( styles?.closeButtonIcon, ]); - return ( - { + const toastSwipeHandlerProps = React.useMemo( + () => ({ + onRemove: () => { onDismiss?.(id); - }} - onBegin={() => { + }, + onBegin: () => { isDragging.current = true; - }} - onFinalize={() => { + }, + onFinalize: () => { isDragging.current = false; const timeElapsed = Date.now() - timerStart.current!; @@ -329,155 +329,179 @@ export const Toast = React.forwardRef( } else { onDismiss?.(id); } - }} - onPress={() => onPress?.()} - enabled={!promiseOptions && dismissible} - style={[toastContainerStyleCtx, styles?.toastContainer]} - className={cn( + }, + onPress: () => onPress?.(), + enabled: !promiseOptions && dismissible, + style: [toastContainerStyleCtx, styles?.toastContainer], + className: cn( classNamesCtx?.toastContainer, classNames?.toastContainer - )} - unstyled={unstyled} - important={important} - position={position} - > - {jsx ? ( + ), + unstyled: unstyled, + important: important, + position: position, + }), + [ + onDismiss, + id, + duration, + dismissible, + promiseOptions, + onPress, + toastContainerStyleCtx, + styles?.toastContainer, + classNamesCtx?.toastContainer, + classNames?.toastContainer, + unstyled, + important, + position, + cn, + ] + ); + + if (jsx) { + return ( + {jsx} - ) : ( - + ); + } + + return ( + + + - - {promiseOptions || variant === 'loading' ? ( - 'loading' in icons ? ( - icons.loading - ) : ( - - ) - ) : icon ? ( - {icon} - ) : variant in icons ? ( - icons[variant] + {promiseOptions || variant === 'loading' ? ( + 'loading' in icons ? ( + icons.loading ) : ( - - )} - + + ) + ) : icon ? ( + {icon} + ) : variant in icons ? ( + icons[variant] + ) : ( + + )} + + + {title} + + {description ? ( - {title} + {description} - {description ? ( - + {isToastAction(action) ? ( + - {description} - - ) : null} - - {isToastAction(action) ? ( - - - {action.label} - - - ) : ( - action || undefined - )} - {isToastAction(cancel) ? ( - { - cancel.onClick(); - onDismiss?.(id); - }} - className={cancelButtonClassName} + {action.label} + + + ) : ( + action || undefined + )} + {isToastAction(cancel) ? ( + { + cancel.onClick(); + onDismiss?.(id); + }} + className={cancelButtonClassName} + style={[ + defaultStyles.cancelButton, + cancelButtonStyleCtx, + cancelButtonStyle, + ]} + > + - - {cancel.label} - - - ) : ( - cancel || undefined - )} - + {cancel.label} + + + ) : ( + cancel || undefined + )} - {renderCloseButton} - - )} + {renderCloseButton} + + ); }