import React from 'react'; import { useOption, useUiTranslator } from '../../core/components/hooks'; import ToggleEdit from './ToggleEdit/index'; import ToggleInsert from './ToggleInsert/index'; import ToggleLayout from './ToggleLayout/index'; import TogglePreview from './TogglePreview/index'; import ToggleResize from './ToggleResize/index'; import UndoRedo from './UndoRedo'; import Zoom from './Zoom'; const getStickyNessstyle = (stickyness?: StickyNess): React.CSSProperties => { if ( !stickyness || (!stickyness.shouldStickToBottom && !stickyness.shouldStickToTop) ) { return { position: 'fixed', right: stickyness?.rightOffsetFixed || 0, }; } return { position: 'absolute', bottom: stickyness.shouldStickToBottom ? 0 : 'auto', top: stickyness.shouldStickToTop ? 0 : 'auto', right: -stickyness.rightOffset || 0, }; }; function notEmpty(value: TValue | null | undefined): value is TValue { return value !== null && value !== undefined; } export type StickyNess = { shouldStickToTop: boolean; shouldStickToBottom: boolean; rightOffset: number; rightOffsetFixed: number; stickyElRef?: React.Ref; }; export const Sidebar: React.FC<{ stickyNess?: StickyNess; }> = ({ stickyNess }) => { const { t } = useUiTranslator(); const zoomEnabled = useOption('zoomEnabled'); const undoRedoEnabled = useOption('undoRedoEnabled'); const editEnabled = useOption('editEnabled'); const insertEnabled = useOption('insertEnabled'); const layoutEnabled = useOption('layoutEnabled'); const resizeEnabled = useOption('resizeEnabled'); const previewEnabled = useOption('previewEnabled'); const defaultLabels = { edit: 'Edit blocks', insert: 'Add blocks', layout: 'Move blocks', resize: 'Resize blocks', preview: 'Preview page', }; const customOptions = useOption('customOptions'); const actions = [ // eslint-disable-next-line react/jsx-key undoRedoEnabled ? { action: } : null, zoomEnabled ? { action: } : null, editEnabled ? { action: } : null, insertEnabled ? { action: } : null, layoutEnabled ? { action: } : null, resizeEnabled ? { action: } : null, previewEnabled ? { action: } : null, ...(customOptions?.map((CustomOption) => ({ action: })) ?? []), ].filter(notEmpty); return (
{actions.map(({ action }, index) => (
<> {action}
))}
); };