[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.

43 lines
1.3 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. import React, { FC, MouseEventHandler } from 'react'
  2. import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
  3. import { faWindowClose } from '@fortawesome/free-solid-svg-icons'
  4. import { useTheme } from '../hooks'
  5. import { NotificationType } from '../types'
  6. interface Props {
  7. id: string
  8. type: NotificationType
  9. auto: boolean
  10. setAuto: (id: string) => void
  11. dismiss: (id: string) => void
  12. }
  13. const Notification: FC<Props> = ({ id, type, auto, setAuto, dismiss, children }) => {
  14. const theme = useTheme()
  15. const handleDismiss: MouseEventHandler = e => {
  16. e.stopPropagation()
  17. dismiss(id)
  18. }
  19. const color = () => {
  20. switch (type) {
  21. case NotificationType.Success: return theme.green
  22. case NotificationType.Error: return theme.red
  23. default: return theme.blue
  24. }
  25. }
  26. return (
  27. <div className="notification" onClick={() => setAuto(id)} style={{ backgroundColor: color(), color: '#fff' }}>
  28. {!auto &&
  29. <button className="delete" onClick={handleDismiss} style={{ backgroundColor: color(), color: '#fff' }}>
  30. <FontAwesomeIcon icon={faWindowClose} />
  31. </button>
  32. }
  33. <div>{children}</div>
  34. </div>
  35. )
  36. }
  37. export default Notification