Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

chore: better loading spinner (#812)

Ameer Al Ashhab5b6903b1f097
diff --git a/apps/web/app/(org)/dashboard/spaces/[spaceId]/components/AddVideosDialogBase.tsx b/apps/web/app/(org)/dashboard/spaces/[spaceId]/components/AddVideosDialogBase.tsx
index 840e6b961..988f4fd98 100644
--- a/apps/web/app/(org)/dashboard/spaces/[spaceId]/components/AddVideosDialogBase.tsx
+++ b/apps/web/app/(org)/dashboard/spaces/[spaceId]/components/AddVideosDialogBase.tsx
@@ -19,6 +19,7 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { Search } from "lucide-react";
import clsx from "clsx";
import VirtualizedVideoGrid from "./VirtualizedVideoGrid";
+import { LoadingSpinner } from "@cap/ui";
interface AddVideosDialogBaseProps {
open: boolean;
@@ -237,10 +238,10 @@ const AddVideosDialogBase: React.FC<AddVideosDialogBaseProps> = ({
</div>
</div>
- <div className="flex-1 w-full">
+ <div className="flex-1 w-full h-64">
{isLoading ? (
- <div className="flex justify-center items-center h-64">
- <div className="w-8 h-8 rounded-full border-b-2 border-blue-500 animate-spin"></div>
+ <div className="flex justify-center items-center w-full h-64">
+ <LoadingSpinner size={36} />
</div>
) : filteredVideos.length === 0 ? (
<div className="flex flex-col justify-center items-center h-24 text-center">
diff --git a/packages/ui/src/components/Button.tsx b/packages/ui/src/components/Button.tsx
index d6d39007f..3c6090ff6 100644
--- a/packages/ui/src/components/Button.tsx
+++ b/packages/ui/src/components/Button.tsx
@@ -2,6 +2,7 @@ import { classNames } from "@cap/utils";
import { Slot } from "@radix-ui/react-slot";
import { cva, type VariantProps } from "class-variance-authority";
import * as React from "react";
+import { LoadingSpinner } from "./LoadingSpinner";
const buttonVariants = cva(
"flex items-center justify-center rounded-full disabled:cursor-not-allowed cursor-pointer font-medium px-[1.25rem] ring-offset-transparent relative gap-1",
@@ -71,28 +72,7 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
{...props}
>
{spinner && (
- <svg
- xmlns="http://www.w3.org/2000/svg"
- className="mr-1 size-5"
- viewBox="0 0 24 24"
- >
- <style>
- {"@keyframes spinner_AtaB{to{transform:rotate(360deg)}}"}
- </style>
- <path
- className="dark:fill-gray-12 light:fill-gray-1"
- d="M12 1a11 11 0 1 0 11 11A11 11 0 0 0 12 1Zm0 19a8 8 0 1 1 8-8 8 8 0 0 1-8 8Z"
- opacity={0.25}
- />
- <path
- className="dark:fill-gray-12 light:fill-gray-1"
- d="M10.14 1.16a11 11 0 0 0-9 8.92A1.59 1.59 0 0 0 2.46 12a1.52 1.52 0 0 0 1.65-1.3 8 8 0 0 1 6.66-6.61A1.42 1.42 0 0 0 12 2.69a1.57 1.57 0 0 0-1.86-1.53Z"
- style={{
- transformOrigin: "center",
- animation: "spinner_AtaB .75s infinite linear",
- }}
- />
- </svg>
+ <LoadingSpinner className="mr-1" size={16} />
)}
{icon && icon}
{props.children}
diff --git a/packages/ui/src/components/LoadingSpinner.tsx b/packages/ui/src/components/LoadingSpinner.tsx
new file mode 100644
index 000000000..c70111c02
--- /dev/null
+++ b/packages/ui/src/components/LoadingSpinner.tsx
@@ -0,0 +1,36 @@
+export const LoadingSpinner = ({
+ size = 36,
+ color = 'white',
+ thickness = 3,
+ speed = 1.5,
+ className,
+}: {
+ size?: number;
+ color?: string;
+ thickness?: number;
+ speed?: number;
+ className?: string;
+}) => {
+ const spinnerStyle = {
+ width: `${size}px`,
+ minWidth: `${size}px`,
+ height: `${size}px`,
+ minHeight: `${size}px`,
+ border: `${thickness}px solid rgba(255, 255, 255, 0.2)`,
+ borderTop: `${thickness}px solid ${color}`,
+ borderRadius: '50%',
+ animation: `spin ${1 / speed}s linear infinite`
+ };
+
+ return (
+ <>
+ <style>{`
+ @keyframes spin {
+ 0% { transform: rotate(0deg); }
+ 100% { transform: rotate(360deg); }
+ }
+ `}</style>
+ <div style={spinnerStyle} className={className} />
+ </>
+ );
+};
diff --git a/packages/ui/src/index.tsx b/packages/ui/src/index.tsx
index fc96ca74e..1b358b737 100644
--- a/packages/ui/src/index.tsx
+++ b/packages/ui/src/index.tsx
@@ -8,6 +8,7 @@ export * from "./components/icons/LogoBadge";
// Layout
export * from "./components/LogoSpinner";
+export * from "./components/LoadingSpinner";
export * from "./components/SkeletonPage";
export * from "./components/SkeletonRows";