UNPKG

@wordpress/block-editor

Version:
84 lines (73 loc) 3.45 kB
import { createElement } from "@wordpress/element"; /** * WordPress dependencies */ import { getBlockSupport } from '@wordpress/blocks'; import { PanelBody } from '@wordpress/components'; import { Platform } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ import InspectorControls from '../components/inspector-controls'; import useEditorFeature from '../components/use-editor-feature'; import { BorderColorEdit } from './border-color'; import { BorderRadiusEdit } from './border-radius'; import { BorderStyleEdit } from './border-style'; import { BorderWidthEdit } from './border-width'; export const BORDER_SUPPORT_KEY = '__experimentalBorder'; export function BorderPanel(props) { const isDisabled = useIsBorderDisabled(props); const isSupported = hasBorderSupport(props.name); const isColorSupported = useEditorFeature('border.customColor') && hasBorderSupport(props.name, 'color'); const isRadiusSupported = useEditorFeature('border.customRadius') && hasBorderSupport(props.name, 'radius'); const isStyleSupported = useEditorFeature('border.customStyle') && hasBorderSupport(props.name, 'style'); const isWidthSupported = useEditorFeature('border.customWidth') && hasBorderSupport(props.name, 'width'); if (isDisabled || !isSupported) { return null; } return createElement(InspectorControls, null, createElement(PanelBody, { title: __('Border settings'), initialOpen: false }, isStyleSupported && createElement(BorderStyleEdit, props), isWidthSupported && createElement(BorderWidthEdit, props), isRadiusSupported && createElement(BorderRadiusEdit, props), isColorSupported && createElement(BorderColorEdit, props))); } /** * Determine whether there is block support for border properties. * * @param {string} blockName Block name. * @param {string} feature Border feature to check support for. * @return {boolean} Whether there is support. */ export function hasBorderSupport(blockName, feature = 'any') { if (Platform.OS !== 'web') { return false; } const support = getBlockSupport(blockName, BORDER_SUPPORT_KEY); if (support === true) { return true; } if (feature === 'any') { return !!(support !== null && support !== void 0 && support.color || support !== null && support !== void 0 && support.radius || support !== null && support !== void 0 && support.width || support !== null && support !== void 0 && support.style); } return !!(support !== null && support !== void 0 && support[feature]); } /** * Check whether serialization of border classes and styles should be skipped. * * @param {string|Object} blockType Block name or block type object. * @return {boolean} Whether serialization of border properties should occur. */ export function shouldSkipSerialization(blockType) { const support = getBlockSupport(blockType, BORDER_SUPPORT_KEY); return support === null || support === void 0 ? void 0 : support.__experimentalSkipSerialization; } /** * Determines if all border support features have been disabled. * * @return {boolean} If border support is completely disabled. */ const useIsBorderDisabled = () => { const configs = [!useEditorFeature('border.customColor'), !useEditorFeature('border.customRadius'), !useEditorFeature('border.customStyle'), !useEditorFeature('border.customWidth')]; return configs.every(Boolean); }; //# sourceMappingURL=border.js.map