EnteButton.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import Done from "@mui/icons-material/Done";
  2. import {
  3. Button,
  4. ButtonProps,
  5. CircularProgress,
  6. PaletteColor,
  7. } from "@mui/material";
  8. interface Iprops extends ButtonProps {
  9. loading?: boolean;
  10. success?: boolean;
  11. }
  12. export default function EnteButton({
  13. children,
  14. loading,
  15. success,
  16. disabled,
  17. sx,
  18. ...props
  19. }: Iprops) {
  20. return (
  21. <Button
  22. disabled={disabled}
  23. sx={{
  24. ...sx,
  25. ...((loading || success) && {
  26. "&.Mui-disabled": (theme) => ({
  27. backgroundColor: (
  28. theme.palette[props.color] as PaletteColor
  29. ).main,
  30. color: (theme.palette[props.color] as PaletteColor)
  31. .contrastText,
  32. }),
  33. }),
  34. }}
  35. {...props}
  36. >
  37. {loading ? (
  38. <CircularProgress size={20} sx={{ color: "inherit" }} />
  39. ) : success ? (
  40. <Done sx={{ fontSize: 20 }} />
  41. ) : (
  42. children
  43. )}
  44. </Button>
  45. );
  46. }