SubmitButton.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import Done from '@mui/icons-material/Done';
  2. import { Button, ButtonProps, CircularProgress } from '@mui/material';
  3. import React, { FC } from 'react';
  4. export interface SubmitButtonProps {
  5. loading: boolean;
  6. buttonText: string;
  7. disabled?: boolean;
  8. success?: boolean;
  9. }
  10. const SubmitButton: 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.palette.accent.main,
  32. color: (theme) => theme.palette.text.primary,
  33. },
  34. }
  35. : {}),
  36. ...sx,
  37. }}
  38. {...props}>
  39. {loading ? (
  40. <CircularProgress size={20} />
  41. ) : success ? (
  42. <Done sx={{ fontSize: 20 }} />
  43. ) : (
  44. buttonText
  45. )}
  46. </Button>
  47. );
  48. };
  49. export default SubmitButton;