diff options
author | crupest <crupest@outlook.com> | 2021-07-01 19:59:22 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-07-01 19:59:22 +0800 |
commit | 47175cf9afcd86b0b92f7121ce0c3d85b948b6dd (patch) | |
tree | 58573f98df9815fe677f2345c5ce944fe4a65c11 /FrontEnd/src/views/common/alert/AlertHost.tsx | |
parent | e5af20ffe6a1091a022f97c65f3091f245dfd1d7 (diff) | |
download | timeline-47175cf9afcd86b0b92f7121ce0c3d85b948b6dd.tar.gz timeline-47175cf9afcd86b0b92f7121ce0c3d85b948b6dd.tar.bz2 timeline-47175cf9afcd86b0b92f7121ce0c3d85b948b6dd.zip |
...
Diffstat (limited to 'FrontEnd/src/views/common/alert/AlertHost.tsx')
-rw-r--r-- | FrontEnd/src/views/common/alert/AlertHost.tsx | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/FrontEnd/src/views/common/alert/AlertHost.tsx b/FrontEnd/src/views/common/alert/AlertHost.tsx index 21b9882d..ba6d6a0f 100644 --- a/FrontEnd/src/views/common/alert/AlertHost.tsx +++ b/FrontEnd/src/views/common/alert/AlertHost.tsx @@ -1,15 +1,13 @@ import React from "react"; import without from "lodash/without"; import { useTranslation } from "react-i18next"; +import classNames from "classnames"; -import { - alertService, - AlertInfoEx, - kAlertHostId, - AlertInfo, -} from "@/services/alert"; +import { alertService, AlertInfoEx, AlertInfo } from "@/services/alert"; import { convertI18nText } from "@/common"; +import "./alert.css"; + interface AutoCloseAlertProps { alert: AlertInfo; close: () => void; @@ -51,14 +49,29 @@ export const AutoCloseAlert: React.FC<AutoCloseAlertProps> = (props) => { }; return ( - <div className="m-3" onClick={cancelTimer}> - {(() => { - const { message } = alert; - if (typeof message === "function") { - const Message = message; - return <Message />; - } else return convertI18nText(message, t); - })()} + <div + className={classNames( + "m-3 cru-alert", + "cru-" + (alert.type ?? "primary") + )} + onClick={cancelTimer} + > + <div className="cru-alert-content"> + {(() => { + const { message, customMessage } = alert; + if (customMessage != null) { + return customMessage; + } else { + return convertI18nText(message, t); + } + })()} + </div> + <div className="cru-alert-close-button-container"> + <i + className={classNames("icon-button bi-x cru-alert-close-button")} + onClick={close} + /> + </div> </div> ); }; @@ -66,8 +79,6 @@ export const AutoCloseAlert: React.FC<AutoCloseAlertProps> = (props) => { const AlertHost: React.FC = () => { const [alerts, setAlerts] = React.useState<AlertInfoEx[]>([]); - // react guarantee that state setters are stable, so we don't need to add it to dependency list - React.useEffect(() => { const consume = (alert: AlertInfoEx): void => { setAlerts((old) => [...old, alert]); @@ -80,7 +91,7 @@ const AlertHost: React.FC = () => { }, []); return ( - <div id={kAlertHostId} className="alert-container"> + <div className="alert-container"> {alerts.map((alert) => { return ( <AutoCloseAlert |