import type { ShowToastRequest } from '@yaakapp-internal/plugins'; import classNames from 'classnames'; import * as m from 'motion/react-m'; import type { ReactNode } from 'react'; import { useKey } from 'react-use'; import type { IconProps } from './Icon'; import { Icon } from './Icon'; import { IconButton } from './IconButton'; import { VStack } from './Stacks'; export interface ToastProps { children: ReactNode; open: boolean; onClose: () => void; className?: string; timeout: number | null; action?: (args: { hide: () => void }) => ReactNode; icon?: ShowToastRequest['icon'] | null; color?: ShowToastRequest['color']; } const ICONS: Record, IconProps['icon'] | null> = { custom: null, danger: 'alert_triangle', info: 'info', notice: 'alert_triangle', primary: 'info', secondary: 'info', success: 'check_circle', warning: 'alert_triangle', }; export function Toast({ children, open, onClose, timeout, action, icon, color }: ToastProps) { useKey( 'Escape', () => { if (!open) return; onClose(); }, {}, [open], ); const toastIcon = icon === null ? null : (icon ?? (color && color in ICONS && ICONS[color])); return (
{toastIcon && }
{children}
{action?.({ hide: onClose })}
{timeout != null && (
)}
); }