From ef7d30e3aaf434b3d07b22bdf576b34296c4822c Mon Sep 17 00:00:00 2001 From: Jon Q Date: Wed, 20 May 2020 13:43:55 -0400 Subject: [PATCH 01/27] Add initial support for video in FocalPointPicker --- packages/block-library/src/cover/edit.js | 60 ++++++++++++------- .../src/focal-point-picker/index.js | 38 ++++++++---- .../src/focal-point-picker/utils.js | 10 ++++ 3 files changed, 74 insertions(+), 34 deletions(-) create mode 100644 packages/components/src/focal-point-picker/utils.js diff --git a/packages/block-library/src/cover/edit.js b/packages/block-library/src/cover/edit.js index 63071a0e09142..67d8cea9ed2f5 100644 --- a/packages/block-library/src/cover/edit.js +++ b/packages/block-library/src/cover/edit.js @@ -267,6 +267,9 @@ function CoverEdit( { isDarkElement ); + const isImageBackground = IMAGE_BACKGROUND_TYPE === backgroundType; + const isVideoBackground = VIDEO_BACKGROUND_TYPE === backgroundType; + const [ temporaryMinHeight, setTemporaryMinHeight ] = useState( null ); const { removeAllNotices, createErrorNotice } = noticeOperations; @@ -275,9 +278,7 @@ function CoverEdit( { : minHeight; const style = { - ...( backgroundType === IMAGE_BACKGROUND_TYPE - ? backgroundImageStyles( url ) - : {} ), + ...( isImageBackground ? backgroundImageStyles( url ) : {} ), backgroundColor: overlayColor.color, minHeight: temporaryMinHeight || minHeightWithUnit || undefined, }; @@ -286,9 +287,13 @@ function CoverEdit( { style.background = gradientValue; } + let positionValue; + if ( focalPoint ) { - style.backgroundPosition = `${ focalPoint.x * 100 }% ${ focalPoint.y * - 100 }%`; + positionValue = `${ focalPoint.x * 100 }% ${ focalPoint.y * 100 }%`; + if ( isImageBackground ) { + style.backgroundPosition = positionValue; + } } const hasBackground = !! ( url || overlayColor.color || gradientValue ); @@ -316,28 +321,36 @@ function CoverEdit( { { !! url && ( - { IMAGE_BACKGROUND_TYPE === backgroundType && ( + { isImageBackground && ( ) } - { IMAGE_BACKGROUND_TYPE === backgroundType && - ! hasParallax && ( - - setAttributes( { - focalPoint: newFocalPoint, - } ) - } - /> - ) } - { VIDEO_BACKGROUND_TYPE === backgroundType && ( -