feat: add optional spinner into toast message
This commit is contained in:
parent
e1ff9791f2
commit
ef190ebf30
@ -2377,6 +2377,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
toast: {
|
toast: {
|
||||||
message: string;
|
message: string;
|
||||||
closable?: boolean;
|
closable?: boolean;
|
||||||
|
spinner?: boolean;
|
||||||
duration?: number;
|
duration?: number;
|
||||||
} | null,
|
} | null,
|
||||||
) => {
|
) => {
|
||||||
|
@ -25,6 +25,17 @@
|
|||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.Toast__message--spinner {
|
||||||
|
padding: 0 3rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.Toast__spinner {
|
||||||
|
position: absolute;
|
||||||
|
left: 1.5rem;
|
||||||
|
top: 50%;
|
||||||
|
margin-top: -8px;
|
||||||
|
}
|
||||||
|
|
||||||
.close {
|
.close {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
import clsx from "clsx";
|
||||||
import { useCallback, useEffect, useRef } from "react";
|
import { useCallback, useEffect, useRef } from "react";
|
||||||
import { CloseIcon } from "./icons";
|
import { CloseIcon } from "./icons";
|
||||||
|
import Spinner from "./Spinner";
|
||||||
import "./Toast.scss";
|
import "./Toast.scss";
|
||||||
import { ToolButton } from "./ToolButton";
|
import { ToolButton } from "./ToolButton";
|
||||||
|
|
||||||
@ -9,12 +11,14 @@ export const Toast = ({
|
|||||||
message,
|
message,
|
||||||
onClose,
|
onClose,
|
||||||
closable = false,
|
closable = false,
|
||||||
|
spinner = true,
|
||||||
// To prevent autoclose, pass duration as Infinity
|
// To prevent autoclose, pass duration as Infinity
|
||||||
duration = DEFAULT_TOAST_TIMEOUT,
|
duration = DEFAULT_TOAST_TIMEOUT,
|
||||||
}: {
|
}: {
|
||||||
message: string;
|
message: string;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
closable?: boolean;
|
closable?: boolean;
|
||||||
|
spinner?: boolean;
|
||||||
duration?: number;
|
duration?: number;
|
||||||
}) => {
|
}) => {
|
||||||
const timerRef = useRef<number>(0);
|
const timerRef = useRef<number>(0);
|
||||||
@ -44,7 +48,18 @@ export const Toast = ({
|
|||||||
onMouseEnter={onMouseEnter}
|
onMouseEnter={onMouseEnter}
|
||||||
onMouseLeave={onMouseLeave}
|
onMouseLeave={onMouseLeave}
|
||||||
>
|
>
|
||||||
<p className="Toast__message">{message}</p>
|
{spinner && (
|
||||||
|
<div className="Toast__spinner">
|
||||||
|
<Spinner />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<p
|
||||||
|
className={clsx("Toast__message", {
|
||||||
|
"Toast__message--spinner": spinner,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{message}
|
||||||
|
</p>
|
||||||
{closable && (
|
{closable && (
|
||||||
<ToolButton
|
<ToolButton
|
||||||
icon={CloseIcon}
|
icon={CloseIcon}
|
||||||
|
@ -343,6 +343,7 @@ class Collab extends PureComponent<Props, CollabState> {
|
|||||||
this.excalidrawAPI.setToast({
|
this.excalidrawAPI.setToast({
|
||||||
message: t("toast.reconnectRoomServer"),
|
message: t("toast.reconnectRoomServer"),
|
||||||
duration: Infinity,
|
duration: Infinity,
|
||||||
|
spinner: true,
|
||||||
closable: false,
|
closable: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user