pdf-hybrid-theme-button.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. import { useIsNewEditorEnabled } from '@/features/ide-redesign/utils/new-editor-utils'
  7. export const PdfHybridThemeButton = () => {
  8. const id = useId()
  9. const { t } = useTranslation()
  10. const usesNewEditor = useIsNewEditorEnabled()
  11. const {
  12. pdfViewer,
  13. darkModePdf,
  14. setDarkModePdf,
  15. activeOverallTheme,
  16. showLogs,
  17. } = useCompileContext()
  18. const onClick = useCallback(() => {
  19. setDarkModePdf(!darkModePdf)
  20. }, [darkModePdf, setDarkModePdf])
  21. if (!usesNewEditor) {
  22. // The old editor does not support dark mode PDF, so don't show the button
  23. return null
  24. }
  25. if (activeOverallTheme !== 'dark') {
  26. return null
  27. }
  28. if (pdfViewer !== 'pdfjs') {
  29. // We can't affect the theme of the embedded viewer
  30. return null
  31. }
  32. if (showLogs) {
  33. // Don't show the button when logs are shown
  34. return null
  35. }
  36. const tooltipText = darkModePdf
  37. ? t('showing_pdf_preview_with_inverted_colors')
  38. : t('invert_pdf_preview_colors')
  39. return (
  40. <OLTooltip
  41. id={id}
  42. description={tooltipText}
  43. overlayProps={{ placement: 'bottom' }}
  44. >
  45. <OLIconButton
  46. icon="invert_colors"
  47. accessibilityLabel={tooltipText}
  48. variant="link"
  49. active={darkModePdf}
  50. className="pdf-toolbar-btn toolbar-item theme-toggle-btn"
  51. onClick={onClick}
  52. style={{ position: 'relative' }}
  53. />
  54. </OLTooltip>
  55. )
  56. }