From d47849c324a6769855a383353e5bbd7f4ad92261 Mon Sep 17 00:00:00 2001 From: BFlat Date: Tue, 28 May 2024 03:16:59 +0700 Subject: [PATCH] toast alert styling (#433) - moved toast to inside editor container bounds so it's easier to read - styling and icons fix ![image](https://github.com/storytold/GottaGoFast/assets/46063141/ce380b52-5821-47de-94d4-2dd5a48ef583) --- app/components/signaled/Toaster.tsx | 69 +++++++++++++++++++++-------- app/pages/PageEnigma/PageEditor.tsx | 8 +--- app/root.tsx | 3 +- tailwind.config.ts | 9 ++++ 4 files changed, 62 insertions(+), 27 deletions(-) diff --git a/app/components/signaled/Toaster.tsx b/app/components/signaled/Toaster.tsx index bf575821cc..4fc2415873 100644 --- a/app/components/signaled/Toaster.tsx +++ b/app/components/signaled/Toaster.tsx @@ -1,14 +1,13 @@ import { useSignals } from "@preact/signals-react/runtime"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { - faCircleExclamation, - faSquareCheck, + faHexagonXmark, faTriangleExclamation, faXmark, } from "@fortawesome/pro-solid-svg-icons"; - import { ToastTypes } from "~/enums"; import { toasts, deleteToast } from "~/signals"; +import { useEffect, useRef, useState } from "react"; export const Toaster = () => { useSignals(); @@ -17,46 +16,78 @@ export const Toaster = () => { [ToastTypes.WARNING]: "Warning!", [ToastTypes.SUCCESS]: "Success", }; + const ICONS: Record = { - error: ( - - ), + error: , warning: ( ), success: ( - + + + + ), }; + + const toastTypeToKey: Record = { + [ToastTypes.ERROR]: "error", + [ToastTypes.WARNING]: "warning", + [ToastTypes.SUCCESS]: "success", + }; + + const toastRefs = useRef<(HTMLDivElement | null)[]>([]); + const [heights, setHeights] = useState([]); + + useEffect(() => { + const newHeights = toastRefs.current.map((ref) => ref?.offsetHeight || 0); + setHeights(newHeights); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [toasts.value]); + return ( <> {toasts.value.map((toast, index) => (
(toastRefs.current[index] = el)} + className="absolute z-50 w-[360px] animate-fadeIn rounded-lg border-2 border-[#5E5E7C] bg-ui-controls p-4 shadow-xl" + style={{ + top: heights + .slice(0, index) + .reduce((acc, height) => acc + height + 8, 12), + right: 12, + }} > -
-
-
- {ICONS[toast.type]} +
+
+
+ {ICONS[toastTypeToKey[toast.type]]}
{TITLES[toast.type]}
-
+
{toast.message}
diff --git a/app/pages/PageEnigma/PageEditor.tsx b/app/pages/PageEnigma/PageEditor.tsx index 6ebb4b6071..ddcdf20d5f 100644 --- a/app/pages/PageEnigma/PageEditor.tsx +++ b/app/pages/PageEnigma/PageEditor.tsx @@ -1,9 +1,7 @@ import React, { useEffect } from "react"; import { useSignals } from "@preact/signals-react/runtime"; - -import { LoadingDots, TopBar } from "~/components"; +import { LoadingDots, Toaster, TopBar } from "~/components"; import { SidePanel } from "~/pages/PageEnigma/comps/SidePanel"; - import { Timeline } from "./comps/Timeline"; import { Controls3D } from "./comps/Controls3D"; import { ControlsTopButtons } from "./comps/ControlsTopButtons"; @@ -11,9 +9,7 @@ import { ControlsVideo } from "./comps/ControlsVideo"; import { ControlPanelSceneObject } from "./comps/ControlPanelSceneObject"; import { PreviewEngineCamera } from "./comps/PreviewEngineCamera"; import { PreviewFrameImage } from "./comps/PreviewFrameImage"; - import { pageHeight, pageWidth } from "~/signals"; - import { timelineHeight, sidePanelWidth, @@ -22,7 +18,6 @@ import { dndTimelineHeight, editorLoader, } from "~/pages/PageEnigma/signals"; - import { EditorCanvas } from "./comps/EngineCanvases"; import { SceneContainer } from "./comps/SceneContainer"; @@ -71,6 +66,7 @@ export const PageEditor = () => { }} >
+ diff --git a/app/root.tsx b/app/root.tsx index e974f07ce8..3c27182432 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -29,7 +29,7 @@ import { persistLogin, } from "~/signals"; -import { LoadingDotsBricks, Toaster } from "~/components"; +import { LoadingDotsBricks } from "~/components"; config.autoAddCss = false; /* eslint-disable import/first */ @@ -120,7 +120,6 @@ export default function App() { -
diff --git a/tailwind.config.ts b/tailwind.config.ts index cdd5120c63..d14e174f73 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -12,6 +12,15 @@ export default { fontFamily: { "custom-font": ["Fira Sans", "sans-serif"], }, + keyframes: { + fadeIn: { + "0%": { opacity: "0" }, + "100%": { opacity: "1" }, + }, + }, + animation: { + fadeIn: "fadeIn 0.2s ease-in-out", + }, }, colors: { transparent: "transparent",