diff --git a/packages/block-library/src/cover/block.json b/packages/block-library/src/cover/block.json index 6bd22bc15123c9..957a8264ef6e6e 100644 --- a/packages/block-library/src/cover/block.json +++ b/packages/block-library/src/cover/block.json @@ -28,6 +28,9 @@ }, "focalPoint": { "type": "object" + }, + "minHeight": { + "type": "number" } } } diff --git a/packages/block-library/src/cover/edit.js b/packages/block-library/src/cover/edit.js index 6ba81ed2d96886..9da2e0a9193ce8 100644 --- a/packages/block-library/src/cover/edit.js +++ b/packages/block-library/src/cover/edit.js @@ -16,8 +16,10 @@ import { ToggleControl, Toolbar, withNotices, + ResizableBox, + BaseControl, } from '@wordpress/components'; -import { compose } from '@wordpress/compose'; +import { compose, withInstanceId } from '@wordpress/compose'; import { BlockControls, BlockIcon, @@ -39,6 +41,8 @@ import icon from './icon'; import { IMAGE_BACKGROUND_TYPE, VIDEO_BACKGROUND_TYPE, + COVER_MIN_HEIGHT, + COVER_DEFAULT_HEIGHT, backgroundImageStyles, dimRatioToClass, } from './shared'; @@ -90,8 +94,10 @@ class CoverEdit extends Component { render() { const { + instanceId, attributes, setAttributes, + isSelected, className, noticeUI, overlayColor, @@ -104,6 +110,7 @@ class CoverEdit extends Component { hasParallax, id, url, + minHeight = COVER_DEFAULT_HEIGHT, } = attributes; const onSelectMedia = ( media ) => { if ( ! media || ! media.url ) { @@ -161,7 +168,7 @@ class CoverEdit extends Component { if ( focalPoint ) { style.backgroundPosition = `${ focalPoint.x * 100 }% ${ focalPoint.y * 100 }%`; } - + const inputId = `block-cover-height-input-${ instanceId }`; const controls = ( <> @@ -205,6 +212,28 @@ class CoverEdit extends Component { onChange={ ( value ) => setAttributes( { focalPoint: value } ) } /> ) } + + { + let coverMinHeight = parseInt( event.target.value, 10 ); + this.setState( { coverMinHeight } ); + if ( isNaN( coverMinHeight ) ) { + // Set cover min height to default size and input box to empty string + this.setState( { coverMinHeight: COVER_DEFAULT_HEIGHT } ); + coverMinHeight = COVER_DEFAULT_HEIGHT; + } else if ( coverMinHeight < COVER_MIN_HEIGHT ) { + // Set cover min height to minimum size + coverMinHeight = COVER_MIN_HEIGHT; + } + setAttributes( { minHeight: coverMinHeight } ); + } } + value={ this.state.coverMinHeight || minHeight } + min={ COVER_MIN_HEIGHT } + step="10" + /> + { controls } -
{ + const coverHeight = parseInt( minHeight + delta.height, 10 ); + this.setState( { coverMinHeight: coverHeight } ); + setAttributes( { + minHeight: coverHeight, + } ); + } } > - { IMAGE_BACKGROUND_TYPE === backgroundType && ( + +
+ { IMAGE_BACKGROUND_TYPE === backgroundType && ( // Used only to programmatically check if the image is dark or not - - ) } - { VIDEO_BACKGROUND_TYPE === backgroundType && ( -
+ ); } @@ -372,4 +430,5 @@ class CoverEdit extends Component { export default compose( [ withColors( { overlayColor: 'background-color' } ), withNotices, + withInstanceId, ] )( CoverEdit ); diff --git a/packages/block-library/src/cover/editor.scss b/packages/block-library/src/cover/editor.scss index b368b3ee24c05d..fbfa18bf2b6b4b 100644 --- a/packages/block-library/src/cover/editor.scss +++ b/packages/block-library/src/cover/editor.scss @@ -1,5 +1,7 @@ .wp-block-cover-image, .wp-block-cover { + min-height: auto; + &.components-placeholder h2 { color: inherit; } diff --git a/packages/block-library/src/cover/save.js b/packages/block-library/src/cover/save.js index 1be2d974159c7d..de057122a0f7b7 100644 --- a/packages/block-library/src/cover/save.js +++ b/packages/block-library/src/cover/save.js @@ -30,6 +30,7 @@ export default function save( { attributes } ) { hasParallax, overlayColor, url, + minHeight, } = attributes; const overlayColorClass = getColorClassName( 'background-color', overlayColor ); const style = backgroundType === IMAGE_BACKGROUND_TYPE ? @@ -41,6 +42,7 @@ export default function save( { attributes } ) { if ( focalPoint && ! hasParallax ) { style.backgroundPosition = `${ focalPoint.x * 100 }% ${ focalPoint.y * 100 }%`; } + style.minHeight = minHeight || undefined; const classes = classnames( dimRatioToClass( dimRatio ), diff --git a/packages/block-library/src/cover/shared.js b/packages/block-library/src/cover/shared.js index 1b01b0bf8c24fd..9ee23938e805ba 100644 --- a/packages/block-library/src/cover/shared.js +++ b/packages/block-library/src/cover/shared.js @@ -1,6 +1,7 @@ export const IMAGE_BACKGROUND_TYPE = 'image'; export const VIDEO_BACKGROUND_TYPE = 'video'; - +export const COVER_MIN_HEIGHT = 50; +export const COVER_DEFAULT_HEIGHT = 430; export function backgroundImageStyles( url ) { return url ? { backgroundImage: `url(${ url })` } : diff --git a/packages/block-library/src/cover/style.scss b/packages/block-library/src/cover/style.scss index a0c659e1b93689..c6f358d577c1f5 100644 --- a/packages/block-library/src/cover/style.scss +++ b/packages/block-library/src/cover/style.scss @@ -5,6 +5,7 @@ background-size: cover; background-position: center center; min-height: 430px; + height: 100%; width: 100%; display: flex; justify-content: center;