actions-word-count.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { useState } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import Tooltip from '../../../shared/components/tooltip'
  4. import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
  5. import WordCountModal from '../../word-count-modal/components/word-count-modal'
  6. import LeftMenuButton from './left-menu-button'
  7. export default function ActionsWordCount() {
  8. const [showModal, setShowModal] = useState(false)
  9. const { pdfUrl } = useCompileContext()
  10. const { t } = useTranslation()
  11. return (
  12. <>
  13. {pdfUrl ? (
  14. <LeftMenuButton
  15. onClick={() => setShowModal(true)}
  16. icon={{
  17. type: 'eye',
  18. fw: true,
  19. }}
  20. >
  21. {t('word_count')}
  22. </LeftMenuButton>
  23. ) : (
  24. <Tooltip
  25. id="disabled-word-count"
  26. description={t('please_compile_pdf_before_word_count')}
  27. overlayProps={{
  28. placement: 'top',
  29. }}
  30. >
  31. {/* OverlayTrigger won't fire unless the child is a non-react html element (e.g div, span) */}
  32. <div>
  33. <LeftMenuButton
  34. icon={{
  35. type: 'eye',
  36. fw: true,
  37. }}
  38. disabled
  39. disabledAccesibilityText={t(
  40. 'please_compile_pdf_before_word_count'
  41. )}
  42. >
  43. {t('word_count')}
  44. </LeftMenuButton>
  45. </div>
  46. </Tooltip>
  47. )}
  48. <WordCountModal show={showModal} handleHide={() => setShowModal(false)} />
  49. </>
  50. )
  51. }