UNPKG

@atlaskit/editor-common

Version:

A package that contains common classes and components for editor and renderer

45 lines (44 loc) 1.37 kB
import React, { createContext, useContext, useMemo } from 'react'; import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals'; const EditorToolbarContext = /*#__PURE__*/createContext({ editorView: null, editorAppearance: undefined, editorViewMode: undefined, editorToolbarDockingPreference: undefined }); /** * Access editor specific config and state within a toolbar component */ export const useEditorToolbar = () => { const context = useContext(EditorToolbarContext); if (!context) { throw new Error('useEditorToolbar must be used within EditorToolbarContext'); } return context; }; export const EditorToolbarProvider = ({ children, editorView, editorAppearance, editorViewMode, editorToolbarDockingPreference, isOffline }) => { const memoizedValue = useMemo(() => ({ editorView, editorAppearance, editorViewMode, editorToolbarDockingPreference, isOffline }), [editorView, editorAppearance, editorViewMode, editorToolbarDockingPreference, isOffline]); const contextValue = expValEquals('platform_editor_perf_lint_cleanup', 'isEnabled', true) ? memoizedValue : { editorView, editorAppearance, editorViewMode, editorToolbarDockingPreference, isOffline }; return /*#__PURE__*/React.createElement(EditorToolbarContext.Provider, { value: contextValue }, children); };