[ABANDONED] React/Redux front end for the Flexor social network.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.1 KiB

5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
  1. import React, { FC, MouseEventHandler } from 'react'
  2. import noop from 'lodash/noop'
  3. import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
  4. import { faSpinner } from '@fortawesome/free-solid-svg-icons'
  5. import { IconDefinition } from '@fortawesome/fontawesome-common-types'
  6. export interface Props {
  7. text: string
  8. icon?: IconDefinition
  9. loading?: boolean
  10. color: string
  11. backgroundColor: string
  12. onClick?: MouseEventHandler
  13. }
  14. const Button: FC<Props> = ({ text, icon, loading, color, backgroundColor, onClick = noop }) => {
  15. const isLoading = loading === undefined ? false : loading
  16. const content = () => (
  17. <>
  18. {icon &&
  19. <span className="button-icon">
  20. <FontAwesomeIcon icon={icon} />
  21. </span>
  22. }
  23. <span>{text}</span>
  24. </>
  25. )
  26. return (
  27. <button style={{ backgroundColor, color }} disabled={loading} onClick={onClick}>
  28. {isLoading && <FontAwesomeIcon icon={faSpinner} spin />}
  29. {!isLoading && content()}
  30. </button>
  31. )
  32. }
  33. export default Button