switch-to-editor-button.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { useTranslation } from 'react-i18next'
  2. import Icon from '../../../shared/components/icon'
  3. import MaterialIcon from '@/shared/components/material-icon'
  4. import OLButton from '@/features/ui/components/ol/ol-button'
  5. import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher'
  6. import { useLayoutContext } from '../../../shared/context/layout-context'
  7. function SwitchToEditorButton() {
  8. const { pdfLayout, setView, detachRole } = useLayoutContext()
  9. const { t } = useTranslation()
  10. if (detachRole) {
  11. return null
  12. }
  13. if (pdfLayout === 'sideBySide') {
  14. return null
  15. }
  16. function handleClick() {
  17. setView('editor')
  18. window.setTimeout(() => {
  19. window.dispatchEvent(new Event('editor:focus'))
  20. })
  21. }
  22. return (
  23. <OLButton
  24. variant="secondary"
  25. size="sm"
  26. onClick={handleClick}
  27. bs3Props={{
  28. bsSize: 'xsmall',
  29. className: 'switch-to-editor-btn toolbar-btn-secondary',
  30. }}
  31. >
  32. <BootstrapVersionSwitcher
  33. bs3={<Icon type="code" className="toolbar-btn-secondary-icon" />}
  34. bs5={<MaterialIcon type="code" />}
  35. />
  36. {t('switch_to_editor')}
  37. </OLButton>
  38. )
  39. }
  40. export default SwitchToEditorButton