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.tsx46
1 files changed, 46 insertions, 0 deletions
diff --git a/FrontEnd/src/components/Spinner.tsx b/FrontEnd/src/components/Spinner.tsx
new file mode 100644
index 00000000..50ccf0b2
--- /dev/null
+++ b/FrontEnd/src/components/Spinner.tsx
@@ -0,0 +1,46 @@
+import { CSSProperties, ComponentPropsWithoutRef } from "react";
+import classNames from "classnames";
+
+import "./Spinner.css";
+
+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?: number | string;
+ className?: string;
+ style?: CSSProperties;
+}
+
+export default function Spinner(props: SpinnerProps) {
+ const { size, className, style, ...otherProps } = props;
+ const calculatedSize = calculateSize(size);
+
+ return (
+ <span
+ className={classNames("cru-spinner", className)}
+ style={{
+ width: calculatedSize,
+ height: calculatedSize,
+ ...style,
+ }}
+ {...otherProps}
+ />
+ );
+}