UNPKG

@wordpress/block-editor

Version:
86 lines (78 loc) 2.34 kB
import { createElement } from "@wordpress/element"; /** * External dependencies */ import classnames from 'classnames'; /** * WordPress dependencies */ import deprecated from '@wordpress/deprecated'; import { Button } from '@wordpress/components'; import { chevronLeft, chevronRight } from '@wordpress/icons'; import { __, isRTL } from '@wordpress/i18n'; import { useSelect, useDispatch } from '@wordpress/data'; /** * Internal dependencies */ import BlockIcon from '../block-icon'; import { store as blockEditorStore } from '../../store'; function BlockCard({ title, icon, description, blockType, className }) { if (blockType) { deprecated('`blockType` property in `BlockCard component`', { since: '5.7', alternative: '`title, icon and description` properties' }); ({ title, icon, description } = blockType); } const { parentNavBlockClientId } = useSelect(select => { const { getSelectedBlockClientId, getBlockParentsByBlockName } = select(blockEditorStore); const _selectedBlockClientId = getSelectedBlockClientId(); return { parentNavBlockClientId: getBlockParentsByBlockName(_selectedBlockClientId, 'core/navigation', true)[0] }; }, []); const { selectBlock } = useDispatch(blockEditorStore); return createElement("div", { className: classnames('block-editor-block-card', className) }, parentNavBlockClientId && // This is only used by the Navigation block for now. It's not ideal having Navigation block specific code here. createElement(Button, { onClick: () => selectBlock(parentNavBlockClientId), label: __('Go to parent Navigation block'), style: // TODO: This style override is also used in ToolsPanelHeader. // It should be supported out-of-the-box by Button. { minWidth: 24, padding: 0 }, icon: isRTL() ? chevronRight : chevronLeft, isSmall: true }), createElement(BlockIcon, { icon: icon, showColors: true }), createElement("div", { className: "block-editor-block-card__content" }, createElement("h2", { className: "block-editor-block-card__title" }, title), createElement("span", { className: "block-editor-block-card__description" }, description))); } export default BlockCard; //# sourceMappingURL=index.js.map