mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-16 06:42:14 +00:00
loading bar and spinner
This commit is contained in:
1 parent
7bc4cc5168
commit
48fa8115c9
6 files changed
+90
-4
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { createBrowserRouter } from "react-router-dom";
|
||||
import { Login } from "~/pages/login";
|
||||
import { Main } from "~/pages/main";
|
||||
import { Sandbox } from "~/pages/sandbox";
|
||||
|
||||
export const router = createBrowserRouter([
|
||||
{
|
||||
@@ -11,4 +12,8 @@ export const router = createBrowserRouter([
|
||||
path: "/login",
|
||||
element: <Login />,
|
||||
},
|
||||
{
|
||||
path: "/sandbox",
|
||||
element: <Sandbox />,
|
||||
},
|
||||
]);
|
||||
@@ -0,0 +1,67 @@
|
||||
import { Transition } from "@headlessui/react";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { faCheck, faArrowRotateLeft } from "@fortawesome/pro-thin-svg-icons";
|
||||
|
||||
import { Spinner } from "./Spinner";
|
||||
|
||||
export enum LoadingBarStatus {
|
||||
LOADING = "loading",
|
||||
SUCCESS = "success",
|
||||
ERROR = "error",
|
||||
}
|
||||
|
||||
export const LoadingBar = ({
|
||||
progress = 0,
|
||||
status = LoadingBarStatus.SUCCESS,
|
||||
onRetry,
|
||||
isShowing,
|
||||
message,
|
||||
}: {
|
||||
progress: number;
|
||||
status: LoadingBarStatus;
|
||||
isShowing: boolean;
|
||||
message?: string;
|
||||
onRetry?: () => void;
|
||||
}) => {
|
||||
return (
|
||||
<Transition show={isShowing}>
|
||||
<div
|
||||
className={twMerge(
|
||||
// default styles
|
||||
"flex flex-col items-center gap-2",
|
||||
// base transition properties
|
||||
"transition-opacity ease-in-out",
|
||||
// Shared closed styles
|
||||
"data-[closed]:opacity-0",
|
||||
// Entering styles
|
||||
"data-[enter]:duration-100",
|
||||
// Leaving styles
|
||||
"data-[leave]:duration-300",
|
||||
)}
|
||||
>
|
||||
<div className="flex w-full items-center gap-2">
|
||||
<div className="bg-gray-200 h-2.5 flex-grow rounded-full">
|
||||
<div
|
||||
className="h-2.5 rounded-full bg-primary-500"
|
||||
style={{ width: `${progress}%` }}
|
||||
/>
|
||||
</div>
|
||||
{status === LoadingBarStatus.LOADING && (
|
||||
<Spinner className="size-5" />
|
||||
)}
|
||||
{status === LoadingBarStatus.SUCCESS && (
|
||||
<FontAwesomeIcon icon={faCheck} />
|
||||
)}
|
||||
{status === LoadingBarStatus.ERROR && (
|
||||
<button onClick={onRetry}>
|
||||
<FontAwesomeIcon icon={faArrowRotateLeft} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{message && <label>{message}</label>}
|
||||
</div>
|
||||
</Transition>
|
||||
);
|
||||
};
|
||||
@@ -2,7 +2,7 @@ import { Transition } from "@headlessui/react";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
import { Spinner } from "./Spinner";
|
||||
|
||||
export const Loader = ({
|
||||
export const LoadingSpinner = ({
|
||||
isShowing,
|
||||
message,
|
||||
}: {
|
||||
@@ -1,6 +1,7 @@
|
||||
export * from "./Button";
|
||||
export * from "./Input";
|
||||
export * from "./Loader";
|
||||
export * from "./LoadingBar";
|
||||
export * from "./LoadingSpinner";
|
||||
export * from "./PanelBottom";
|
||||
export * from "./PanelRight";
|
||||
export * from "./Spinner";
|
||||
+5
-2
@@ -4,7 +4,7 @@ import { useNavigate, useSearchParams, Link } from "react-router-dom";
|
||||
import { useSignalEffect } from "@preact/signals-react/runtime";
|
||||
|
||||
import { faKey, faUser } from "@fortawesome/pro-thin-svg-icons";
|
||||
import { Button, Input, Loader } from "~/components/ui";
|
||||
import { Button, Input, LoadingSpinner } from "~/components/ui";
|
||||
import { authentication } from "~/signals";
|
||||
|
||||
export const Login = () => {
|
||||
@@ -109,7 +109,10 @@ export const Login = () => {
|
||||
<Button>Login</Button>
|
||||
</form>
|
||||
|
||||
<Loader isShowing={shouldShowLoader} message={authLoaderMessage} />
|
||||
<LoadingSpinner
|
||||
isShowing={shouldShowLoader}
|
||||
message={authLoaderMessage}
|
||||
/>
|
||||
|
||||
{/*
|
||||
<ConfirmationModal
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { LoadingBar } from "~/components/ui";
|
||||
|
||||
export const Sandbox = () => {
|
||||
return (
|
||||
<div>
|
||||
<h1>Sandbox</h1>
|
||||
<LoadingBar progress={50} isShowing={true} message="Loading..." />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user