aboutsummaryrefslogtreecommitdiff
path: root/FrontEnd/src/components/button/LoadingButton.tsx
blob: 7e7d08e6c10111817873bc86f1d728e9429964ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import classNames from "classnames";

import { I18nText, ThemeColor, useC } from "../common";

import Spinner from "../Spinner";

import "./LoadingButton.css";

interface LoadingButtonProps extends React.ComponentPropsWithoutRef<"button"> {
  color?: ThemeColor;
  text?: I18nText;
  loading?: boolean;
}

export default function LoadingButton(props: LoadingButtonProps) {
  const c = useC();

  const { color, text, loading, disabled, className, children, ...otherProps } =
    props;

  if (text != null && children != null) {
    console.warn("You can't set both text and children props.");
  }

  return (
    <button
      disabled={disabled || loading}
      className={classNames(
        "cru-button outline cru-loading-button",
        `cru-clickable-${color ?? "primary"}`,
        loading && "cru-loading-button-loading",
        className,
      )}
      {...otherProps}
    >
      {text != null ? c(text) : children}
      {loading && <Spinner className="cru-loading-button-spinner" />}
    </button>
  );
}