chat-toggle-button.jsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import PropTypes from 'prop-types'
  2. import classNames from 'classnames'
  3. import { useTranslation } from 'react-i18next'
  4. import Icon from '../../../shared/components/icon'
  5. import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher'
  6. import MaterialIcon from '@/shared/components/material-icon'
  7. import OLBadge from '@/features/ui/components/ol/ol-badge'
  8. function ChatToggleButton({ chatIsOpen, unreadMessageCount, onClick }) {
  9. const { t } = useTranslation()
  10. const classes = classNames(
  11. 'btn',
  12. 'btn-full-height',
  13. 'btn-full-height-no-border',
  14. { active: chatIsOpen }
  15. )
  16. const hasUnreadMessages = unreadMessageCount > 0
  17. return (
  18. <div className="toolbar-item">
  19. <button type="button" className={classes} onClick={onClick}>
  20. <BootstrapVersionSwitcher
  21. bs3={
  22. <Icon
  23. type="comment"
  24. fw
  25. className={classNames({ bounce: hasUnreadMessages })}
  26. />
  27. }
  28. bs5={
  29. <MaterialIcon
  30. type="chat"
  31. className={classNames('align-middle', {
  32. bounce: hasUnreadMessages,
  33. })}
  34. />
  35. }
  36. />
  37. {hasUnreadMessages && <OLBadge bg="info">{unreadMessageCount}</OLBadge>}
  38. <p className="toolbar-label">{t('chat')}</p>
  39. </button>
  40. </div>
  41. )
  42. }
  43. ChatToggleButton.propTypes = {
  44. chatIsOpen: PropTypes.bool,
  45. unreadMessageCount: PropTypes.number.isRequired,
  46. onClick: PropTypes.func.isRequired,
  47. }
  48. export default ChatToggleButton