import classNames from 'classnames'; import { motion } from 'framer-motion'; import type { ReactNode } from 'react'; import React 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?: ReactNode; variant?: 'custom' | 'copied' | 'success' | 'info' | 'warning' | 'error'; } const ICONS: Record, IconProps['icon'] | null> = { custom: null, copied: 'copyCheck', warning: 'alert', error: 'alert', info: 'info', success: 'checkCircle', }; export function Toast({ children, className, open, onClose, timeout, action, variant = 'info', }: ToastProps) { useKey( 'Escape', () => { if (!open) return; onClose(); }, {}, [open], ); const icon = variant in ICONS && ICONS[variant]; return (
{icon && ( )}
{children}
{action}
{timeout != null && (
)}
); }