From 502dd817c79018c84b0a958dd4b2e24781e68ae1 Mon Sep 17 00:00:00 2001
From: crupest <crupest@outlook.com>
Date: Mon, 28 Aug 2023 23:36:38 +0800
Subject: ...

---
 FrontEnd/src/components/Spinner.tsx | 52 ++++++++++++++++++++++---------------
 1 file changed, 31 insertions(+), 21 deletions(-)

(limited to 'FrontEnd/src/components/Spinner.tsx')

diff --git a/FrontEnd/src/components/Spinner.tsx b/FrontEnd/src/components/Spinner.tsx
index ec0c2c35..2752a519 100644
--- a/FrontEnd/src/components/Spinner.tsx
+++ b/FrontEnd/src/components/Spinner.tsx
@@ -1,36 +1,46 @@
-import { CSSProperties } from "react";
-import classnames from "classnames";
-
-import { ThemeColor } from "./common";
+import { CSSProperties, ComponentPropsWithoutRef } from "react";
+import classNames from "classnames";
 
 import "./Spinner.css";
 
-export interface SpinnerProps {
+const sizeMap: Record<string, string> = {
+  sm: "18px",
+  md: "30px",
+  lg: "42px",
+};
+
+function calculateSize(size: SpinnerProps["size"]) {
+  if (size == null) {
+    return "1em";
+  }
+  if (typeof size === "number") {
+    return size;
+  }
+  if (size in sizeMap) {
+    return sizeMap[size];
+  }
+  return size;
+}
+
+export interface SpinnerProps extends ComponentPropsWithoutRef<"span"> {
   size?: "sm" | "md" | "lg" | number | string;
-  color?: ThemeColor;
   className?: string;
   style?: CSSProperties;
 }
 
 export default function Spinner(props: SpinnerProps) {
-  const { size, color, className, style } = props;
-  const calculatedSize =
-    size === "sm"
-      ? "18px"
-      : size === "md"
-      ? "30px"
-      : size === "lg"
-      ? "42px"
-      : typeof size === "number"
-      ? size
-      : size == null
-      ? "20px"
-      : size;
+  const { size, className, style, ...otherProps } = props;
+  const calculatedSize = calculateSize(size);
 
   return (
     <span
-      className={classnames("cru-spinner", color && `cru-${color}`, className)}
-      style={{ width: calculatedSize, height: calculatedSize, ...style }}
+      className={classNames("cru-spinner", className)}
+      style={{
+        width: calculatedSize,
+        height: calculatedSize,
+        ...style,
+      }}
+      {...otherProps}
     />
   );
 }
-- 
cgit v1.2.3

