LoadingButton.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import clsx from "clsx";
  2. import LoadingDots from "../icons/LoadingDots";
  3. interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
  4. className?: string;
  5. title: string;
  6. loading?: boolean;
  7. disabled?: boolean;
  8. type?: "button" | "submit" | "reset";
  9. }
  10. export function Button({
  11. className = "",
  12. title,
  13. loading = false,
  14. disabled = false,
  15. type,
  16. ...rest
  17. }: ButtonProps) {
  18. const buttonClasses = clsx(
  19. "relative flex w-full text-lg cursor-pointer font-outfit font-semibold items-center justify-center rounded-xl bg-blue-600 p-3 tracking-wide text-white",
  20. "hover:opacity-90",
  21. {
  22. "opacity-50 cursor-wait ": loading || disabled,
  23. },
  24. className
  25. );
  26. return (
  27. <button
  28. aria-disabled={loading || disabled}
  29. aria-label={title}
  30. className={buttonClasses}
  31. disabled={loading || disabled}
  32. type={type ?? "reset"}
  33. {...rest}
  34. >
  35. <div className="mx-2 flex items-center justify-center gap-2">
  36. {loading ? (
  37. <>
  38. <LoadingDots className="bg-white" />
  39. <span>loading</span>
  40. </>
  41. ) : (
  42. <span>{title}</span>
  43. )}
  44. </div>
  45. </button>
  46. );
  47. }