SubmitButton.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import Done from "@mui/icons-material/Done";
  2. import { Button, CircularProgress, type ButtonProps } from "@mui/material";
  3. import React from "react";
  4. export interface SubmitButtonProps {
  5. loading: boolean;
  6. buttonText: string;
  7. disabled?: boolean;
  8. success?: boolean;
  9. }
  10. const SubmitButton: React.FC<ButtonProps<"button", SubmitButtonProps>> = ({
  11. loading,
  12. buttonText,
  13. disabled,
  14. success,
  15. sx,
  16. ...props
  17. }) => {
  18. return (
  19. <Button
  20. size="large"
  21. variant="contained"
  22. color="accent"
  23. type="submit"
  24. disabled={disabled || loading || success}
  25. sx={{
  26. my: 4,
  27. ...(loading
  28. ? {
  29. "&.Mui-disabled": {
  30. backgroundColor: (theme) =>
  31. theme.colors.accent.A500,
  32. color: (theme) => theme.colors.text.base,
  33. },
  34. }
  35. : {}),
  36. ...sx,
  37. }}
  38. {...props}
  39. >
  40. {loading ? (
  41. <CircularProgress size={20} />
  42. ) : success ? (
  43. <Done sx={{ fontSize: 20 }} />
  44. ) : (
  45. buttonText
  46. )}
  47. </Button>
  48. );
  49. };
  50. export default SubmitButton;