mirror of
https://github.com/ente-io/ente.git
synced 2025-06-08 18:14:12 +00:00
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { FocusVisibleButton } from "@/base/components/mui/FocusVisibleButton";
|
|
import { CircularProgress, type ButtonProps } from "@mui/material";
|
|
import React from "react";
|
|
|
|
/**
|
|
* A button that shows a indeterminate progress indicator if the {@link loading}
|
|
* prop is set.
|
|
*
|
|
* The button is also disabled when in the loading state.
|
|
*/
|
|
export const LoadingButton: React.FC<ButtonProps & { loading?: boolean }> = ({
|
|
loading,
|
|
disabled,
|
|
color,
|
|
sx,
|
|
children,
|
|
...rest
|
|
}) =>
|
|
loading ? (
|
|
<FocusVisibleButton
|
|
{...{ color }}
|
|
disabled
|
|
sx={{
|
|
"&.Mui-disabled": {
|
|
backgroundColor: `${color}.main`,
|
|
color: `${color}.contrastText`,
|
|
},
|
|
...sx,
|
|
}}
|
|
{...rest}
|
|
>
|
|
<CircularProgress size={20} sx={{ color: "inherit" }} />
|
|
</FocusVisibleButton>
|
|
) : (
|
|
<FocusVisibleButton {...{ color, disabled, sx }} {...rest}>
|
|
{children}
|
|
</FocusVisibleButton>
|
|
);
|