aboutsummaryrefslogtreecommitdiff
path: root/FrontEnd/src/components/Spinner.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'FrontEnd/src/components/Spinner.tsx')
-rw-r--r--FrontEnd/src/components/Spinner.tsx52
1 files changed, 31 insertions, 21 deletions
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}
/>
);
}