UNPKG

@wordpress/block-library

Version:
89 lines (81 loc) 2.63 kB
import { createElement, Fragment } from "@wordpress/element"; /** * WordPress dependencies */ import { useState } from '@wordpress/element'; import { BlockControls, MediaReplaceFlow, __experimentalBlockAlignmentMatrixControl as BlockAlignmentMatrixControl, __experimentalBlockFullHeightAligmentControl as FullHeightAlignmentControl } from '@wordpress/block-editor'; import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ import { ALLOWED_MEDIA_TYPES } from '../shared'; export default function CoverBlockControls(_ref) { let { attributes, setAttributes, onSelectMedia, currentSettings, toggleUseFeaturedImage } = _ref; const { contentPosition, id, useFeaturedImage, minHeight, minHeightUnit } = attributes; const { hasInnerBlocks, url } = currentSettings; const [prevMinHeightValue, setPrevMinHeightValue] = useState(minHeight); const [prevMinHeightUnit, setPrevMinHeightUnit] = useState(minHeightUnit); const isMinFullHeight = minHeightUnit === 'vh' && minHeight === 100; const toggleMinFullHeight = () => { if (isMinFullHeight) { // If there aren't previous values, take the default ones. if (prevMinHeightUnit === 'vh' && prevMinHeightValue === 100) { return setAttributes({ minHeight: undefined, minHeightUnit: undefined }); } // Set the previous values of height. return setAttributes({ minHeight: prevMinHeightValue, minHeightUnit: prevMinHeightUnit }); } setPrevMinHeightValue(minHeight); setPrevMinHeightUnit(minHeightUnit); // Set full height. return setAttributes({ minHeight: 100, minHeightUnit: 'vh' }); }; return createElement(Fragment, null, createElement(BlockControls, { group: "block" }, createElement(BlockAlignmentMatrixControl, { label: __('Change content position'), value: contentPosition, onChange: nextPosition => setAttributes({ contentPosition: nextPosition }), isDisabled: !hasInnerBlocks }), createElement(FullHeightAlignmentControl, { isActive: isMinFullHeight, onToggle: toggleMinFullHeight, isDisabled: !hasInnerBlocks })), createElement(BlockControls, { group: "other" }, createElement(MediaReplaceFlow, { mediaId: id, mediaURL: url, allowedTypes: ALLOWED_MEDIA_TYPES, accept: "image/*,video/*", onSelect: onSelectMedia, onToggleFeaturedImage: toggleUseFeaturedImage, useFeaturedImage: useFeaturedImage, name: !url ? __('Add Media') : __('Replace') }))); } //# sourceMappingURL=block-controls.js.map