From a483555a56e697dfb8af714cb9e8101ccc0b1152 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Tue, 28 Jul 2020 09:48:57 +0300 Subject: [PATCH] [Mobile] Cover: Add Media Button when only colour is selected (#23878) Cover: Add Media Button when only colour is selected --- .../block-library/src/cover/edit.native.js | 29 +++++++++++++++++-- .../block-library/src/cover/style.native.scss | 29 +++++++++++++++++++ 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/cover/edit.native.js b/packages/block-library/src/cover/edit.native.js index ca395f17b3a65c..d698791df731d6 100644 --- a/packages/block-library/src/cover/edit.native.js +++ b/packages/block-library/src/cover/edit.native.js @@ -44,7 +44,7 @@ import { import { compose, withPreferredColorScheme } from '@wordpress/compose'; import { withSelect, withDispatch } from '@wordpress/data'; import { useEffect, useState, useRef } from '@wordpress/element'; -import { cover as icon, replace } from '@wordpress/icons'; +import { cover as icon, replace, image } from '@wordpress/icons'; import { getProtocol } from '@wordpress/url'; /** @@ -114,6 +114,8 @@ const Cover = ( { gradientValue ); + const hasOnlyColorBackground = ! url && hasBackground; + const [ isCustomColorPickerShowing, setCustomColorPickerShowing, @@ -250,6 +252,20 @@ const Cover = ( { ); + const addMediaButton = () => ( + + + + + + + + ); + const controls = ( ); + const renderContent = ( getMediaOptions ) => ( + <> + { renderBackground( getMediaOptions ) } + { isParentSelected && hasOnlyColorBackground && addMediaButton() } + + ); + const renderBackground = ( getMediaOptions ) => ( { openMediaOptionsRef.current = open; - return renderBackground( getMediaOptions ); + return renderContent( getMediaOptions ); } } /> diff --git a/packages/block-library/src/cover/style.native.scss b/packages/block-library/src/cover/style.native.scss index 1656dcf33f5271..73a8f82c2415cf 100644 --- a/packages/block-library/src/cover/style.native.scss +++ b/packages/block-library/src/cover/style.native.scss @@ -88,6 +88,35 @@ height: 100%; } +.selectImageContainer { + position: absolute; + padding: 8px; + justify-self: flex-start; + align-self: flex-end; + justify-content: flex-start; + align-items: flex-end; + z-index: 3; + width: $grid-unit-40; + height: $grid-unit-40; +} + +.selectImage { + width: 30px; + height: 30px; + background-color: $gray-dark; + border-radius: 22px; + position: absolute; + top: 5px; + right: 5px; +} + +.selectImageIcon { + fill: $white; + position: absolute; + top: 7px; + left: 7px; +} + .clearMediaButton { color: $alert-red; }