Download webui/src/components/ui/Toast.tsx from xjackkx/rg: direct link, hf CLI and curl.
- Browser
- Download file 1.21 kB
-
https://huggingface.co/spaces/xjackkx/rg/resolve/main/webui/src/components/ui/Toast.tsx
- Command line
-
hf download hf://spaces/xjackkx/rg/webui/src/components/ui/Toast.tsx
-
curl -L -o Toast.tsx https://huggingface.co/spaces/xjackkx/rg/resolve/main/webui/src/components/ui/Toast.tsx
1.21 kB
| import { createPortal } from "react-dom"; | |
| import { X } from "lucide-react"; | |
| import type { ToastItem } from "../../hooks/useToast"; | |
| import { useI18n } from "../../i18n"; | |
| interface ToastContainerProps { | |
| toasts: ToastItem[]; | |
| onDismiss: (id: number) => void; | |
| } | |
| export function ToastContainer({ toasts, onDismiss }: ToastContainerProps) { | |
| const { t } = useI18n(); | |
| if (toasts.length === 0) { | |
| return null; | |
| } | |
| return createPortal( | |
| <div className="toast-container" aria-live="polite"> | |
| {toasts.map((toast) => ( | |
| <div | |
| key={toast.id} | |
| className={`toast-item toast-${toast.tone}${toast.exiting ? " toast-exit" : ""}`} | |
| > | |
| <span className="toast-text">{t(toast.text)}</span> | |
| <button | |
| type="button" | |
| className="toast-close" | |
| aria-label={t("关闭")} | |
| onClick={() => onDismiss(toast.id)} | |
| > | |
| <X size={14} /> | |
| </button> | |
| </div> | |
| ))} | |
| </div>, | |
| document.body, | |
| ); | |
| } | |