pdf-hybrid-theme-button.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import OLTooltip from '@/shared/components/ol/ol-tooltip'
  2. import { useCallback, useId } from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
  5. import OLIconButton from '@/shared/components/ol/ol-icon-button'
  6. export const PdfHybridThemeButton = () => {
  7. const id = useId()
  8. const { t } = useTranslation()
  9. const {
  10. pdfViewer,
  11. darkModePdf,
  12. setDarkModePdf,
  13. activeOverallTheme,
  14. showLogs,
  15. } = useCompileContext()
  16. const onClick = useCallback(() => {
  17. setDarkModePdf(!darkModePdf)
  18. }, [darkModePdf, setDarkModePdf])
  19. if (activeOverallTheme !== 'dark') {
  20. return null
  21. }
  22. if (pdfViewer !== 'pdfjs') {
  23. // We can't affect the theme of the embedded viewer
  24. return null
  25. }
  26. if (showLogs) {
  27. // Don't show the button when logs are shown
  28. return null
  29. }
  30. const tooltipText = darkModePdf
  31. ? t('showing_pdf_preview_with_inverted_colors')
  32. : t('invert_pdf_preview_colors')
  33. return (
  34. <OLTooltip
  35. id={id}
  36. description={tooltipText}
  37. overlayProps={{ placement: 'bottom' }}
  38. >
  39. <OLIconButton
  40. icon="invert_colors"
  41. accessibilityLabel={tooltipText}
  42. variant="link"
  43. active={darkModePdf}
  44. className="pdf-toolbar-btn toolbar-item theme-toggle-btn"
  45. onClick={onClick}
  46. style={{ position: 'relative' }}
  47. />
  48. </OLTooltip>
  49. )
  50. }