UNPKG

@wordpress/editor

Version:
31 lines (27 loc) 921 B
/** * WordPress dependencies */ import { compose, ifCondition } from '@wordpress/compose'; import { withSelect, withDispatch } from '@wordpress/data'; import { privateApis as preferencesPrivateApis } from '@wordpress/preferences'; /** * Internal dependencies */ import { unlock } from '../../lock-unlock'; import { store as editorStore } from '../../store'; const { PreferenceBaseOption } = unlock( preferencesPrivateApis ); export default compose( withSelect( ( select, { panelName } ) => { const { isEditorPanelEnabled, isEditorPanelRemoved } = select( editorStore ); return { isRemoved: isEditorPanelRemoved( panelName ), isChecked: isEditorPanelEnabled( panelName ), }; } ), ifCondition( ( { isRemoved } ) => ! isRemoved ), withDispatch( ( dispatch, { panelName } ) => ( { onChange: () => dispatch( editorStore ).toggleEditorPanelEnabled( panelName ), } ) ) )( PreferenceBaseOption );