switch-to-editor-button.tsx 817 B

12345678910111213141516171819202122232425262728293031323334
  1. import { useTranslation } from 'react-i18next'
  2. import MaterialIcon from '@/shared/components/material-icon'
  3. import OLButton from '@/shared/components/ol/ol-button'
  4. import { useLayoutContext } from '../../../shared/context/layout-context'
  5. function SwitchToEditorButton() {
  6. const { pdfLayout, restoreView, detachRole } = useLayoutContext()
  7. const { t } = useTranslation()
  8. if (detachRole) {
  9. return null
  10. }
  11. if (pdfLayout === 'sideBySide') {
  12. return null
  13. }
  14. function handleClick() {
  15. restoreView()
  16. window.setTimeout(() => {
  17. window.dispatchEvent(new Event('editor:focus'))
  18. })
  19. }
  20. return (
  21. <OLButton variant="secondary" size="sm" onClick={handleClick}>
  22. <MaterialIcon type="code" />
  23. {t('switch_to_editor')}
  24. </OLButton>
  25. )
  26. }
  27. export default SwitchToEditorButton