blob: 249f3e1d63c49feaa9c7b7757ba3329d28a07c3a (
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
|
import * as React from "react";
import classNames from "classnames";
import { useTranslation } from "react-i18next";
import { I18nText, ThemeColor, convertI18nText } from "../common";
import Spinner from "../Spinner";
interface LoadingButtonProps extends React.ComponentPropsWithoutRef<"button"> {
color?: ThemeColor;
text?: I18nText;
loading?: boolean;
}
function LoadingButton(props: LoadingButtonProps): JSX.Element {
const { t } = useTranslation();
const { color, text, loading, className, children, ...otherProps } = props;
if (text != null && children != null) {
console.warn("You can't set both text and children props.");
}
return (
<button
className={classNames(
"cru-" + (color ?? "primary"),
"cru-button outline",
className,
)}
{...otherProps}
>
{text != null ? convertI18nText(text, t) : children}
{loading && <Spinner />}
</button>
);
}
export default LoadingButton;
|