ente/apps/photos/src/components/EnteButton.tsx

48 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-03-31 09:32:51 +00:00
import Done from '@mui/icons-material/Done';
import {
Button,
ButtonProps,
CircularProgress,
PaletteColor,
} from '@mui/material';
2023-03-31 09:32:51 +00:00
interface Iprops extends ButtonProps {
loading?: boolean;
success?: boolean;
2023-03-31 09:32:51 +00:00
}
export default function EnteButton({
children,
loading,
success,
disabled,
sx,
...props
}: Iprops) {
2023-03-31 09:32:51 +00:00
return (
<Button
disabled={disabled}
sx={{
...sx,
...((loading || success) && {
'&.Mui-disabled': (theme) => ({
backgroundColor: (
theme.palette[props.color] as PaletteColor
).main,
color: (theme.palette[props.color] as PaletteColor)
.contrastText,
}),
}),
}}
{...props}>
2023-03-31 09:32:51 +00:00
{loading ? (
<CircularProgress size={20} sx={{ color: 'inherit' }} />
2023-03-31 09:32:51 +00:00
) : success ? (
<Done sx={{ fontSize: 20 }} />
) : (
children
)}
</Button>
);
}