import { useEffect, useState } from "react"; import classNames from "classnames"; import { ThemeColor, useC, I18nText } from "../common"; import IconButton from "../button/IconButton"; import { alertService, AlertInfoWithId } from "./AlertService"; import "./alert.css"; interface AutoCloseAlertProps { color: ThemeColor; message: I18nText; onDismiss?: () => void; onIn?: () => void; onOut?: () => void; } function Alert({ color, message, onDismiss, onIn, onOut, }: AutoCloseAlertProps) { const c = useC(); return (
{c(message)}
); } export default function AlertHost() { const [alerts, setAlerts] = useState([]); useEffect(() => { const listener = (alerts: AlertInfoWithId[]) => { setAlerts(alerts); }; alertService.registerListener(listener); return () => { alertService.unregisterListener(listener); }; }, []); return (
{alerts.map((alert) => { return ( { alertService.clearDismissTimer(alert.id); }} onOut={() => { alertService.resetDismissTimer(alert.id); }} onDismiss={() => { alertService.dismiss(alert.id); }} /> ); })}
); }