-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathLoadingButton.tsx
More file actions
57 lines (53 loc) · 1.46 KB
/
Copy pathLoadingButton.tsx
File metadata and controls
57 lines (53 loc) · 1.46 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import React, { CSSProperties } from "react";
import { useVulcanComponents } from "../VulcanComponents/Consumer";
import type { ButtonProps } from "./typings";
export interface LoadingButtonProps extends ButtonProps {
loading?: boolean;
label?: string | React.ReactNode;
onClick?: any;
children?: React.ReactNode;
className?: string;
components?: any[]
}
export const LoadingButton = ({
loading,
label,
onClick,
children,
className = "",
components,
...rest
}: LoadingButtonProps & any) => {
const Components = useVulcanComponents(components);
const wrapperStyle: CSSProperties = {
position: "relative",
};
const labelStyle = loading ? { opacity: 0.5 } : {};
const loadingStyle: CSSProperties = loading
? {
position: "absolute",
top: 0,
bottom: 0,
left: 0,
right: 0,
display: "flex",
justifyContent: "center",
alignItems: "center",
}
: { display: "none" };
return (
<Components.Button
className={`loading-button ${loading ? "loading-button-loading" : "loading-button-notloading"
} ${className}`}
onClick={onClick}
{...rest}
>
<span style={wrapperStyle} className="loading-button-inner">
<span style={labelStyle} className="loading-button-label">{label || children}</span>
<span style={loadingStyle} className="loading-button-loader">
<Components.Loading />
</span>
</span>
</Components.Button>
);
};