import React, { FC } from 'react'; import { Transition } from '@headlessui/react'; import cx from 'classnames'; import Close from '../icons/Close'; import Button from './Button'; import { useTranslation } from 'react-i18next'; export type AlertType = 'success' | 'warning' | 'error' | 'info'; export interface Props { open?: boolean; onClose: (value: boolean) => void; className?: string; title?: string | JSX.Element | React.ReactNode; description?: string | JSX.Element | React.ReactNode; children?: JSX.Element | React.ReactNode; type?: AlertType; icon?: JSX.Element | React.ReactNode; closable?: boolean; duration?: number | null; action?: JSX.Element | React.ReactNode; width?: string; } const Alert: FC = ({ open = false, onClose, className, title, description, children, type = 'info', icon, closable = true, duration = null, action, width = '400px', }: Props) => { const { t } = useTranslation(); // Auto-close functionality React.useEffect(() => { if (duration && open) { const timer = setTimeout(() => { onClose(false); }, duration); return () => clearTimeout(timer); } }, [duration, open, onClose]); const getTypeStyles = (type: AlertType) => { switch (type) { case 'success': return 'memori-alert--success'; case 'warning': return 'memori-alert--warning'; case 'error': return 'memori-alert--error'; default: return 'memori-alert--info'; } }; return (