From af55ccb256e5c872d3a7b9b4f4f79e3288ae82c0 Mon Sep 17 00:00:00 2001 From: jasmussen Date: Wed, 6 Oct 2021 13:26:35 +0200 Subject: [PATCH 01/12] Initial work. --- packages/block-library/src/site-logo/edit.js | 2 - .../block-library/src/site-logo/editor.scss | 81 +++++++++++++++---- .../block-library/src/site-logo/style.scss | 5 +- 3 files changed, 70 insertions(+), 18 deletions(-) diff --git a/packages/block-library/src/site-logo/edit.js b/packages/block-library/src/site-logo/edit.js index a2d3515aefbe4..a10e4536a8cb5 100644 --- a/packages/block-library/src/site-logo/edit.js +++ b/packages/block-library/src/site-logo/edit.js @@ -24,7 +24,6 @@ import { import { useViewportMatch } from '@wordpress/compose'; import { BlockControls, - BlockIcon, InspectorControls, MediaPlaceholder, MediaReplaceFlow, @@ -452,7 +451,6 @@ export default function LogoEdit( { ) } { ! logoUrl && canUserEdit && ( } labels={ { title: label, instructions: __( diff --git a/packages/block-library/src/site-logo/editor.scss b/packages/block-library/src/site-logo/editor.scss index 6c420268aa36b..003c58273a668 100644 --- a/packages/block-library/src/site-logo/editor.scss +++ b/packages/block-library/src/site-logo/editor.scss @@ -24,7 +24,6 @@ } } - .custom-logo-link { cursor: inherit; @@ -42,24 +41,24 @@ height: auto; max-width: 100%; } +} - // Placeholder improvements. +// Provide special styling for the placeholder. +// Mostly a proof of concept. We likely need to extract these styles +// to a separate component that more intrinsically inherits block styles +// and provides the on-hover upload button. +// That would also let it work with with less specificity. +.wp-block-site-logo.wp-block-site-logo { .components-placeholder { - justify-content: flex-start; + justify-content: center; + align-items: center; min-height: auto; + box-shadow: none; height: 120px; - padding: $grid-unit-15; + padding: 0; - // Massage the label. - .components-placeholder__label { - margin-top: $grid-unit-15; - white-space: nowrap; - } - - .components-placeholder__label .block-editor-block-icon, - .components-placeholder__label > svg { - margin-right: $grid-unit-05; - } + // Inherit border radius from style variations. + border-radius: inherit; // Hide the upload button, as it's also available in the media library. .components-form-file-upload { @@ -79,9 +78,61 @@ justify-content: center; } - // Hide drag and drop text. + // Hide items. + .components-placeholder__label, .components-drop-zone__content-text { display: none; } + + // Draw the dashed outline. + &::before { + content: ""; + display: block; + position: absolute; + top: 0; + right: 0; + bottom: 0; + left: 0; + border: $border-width dashed currentColor; + opacity: 0.5; + pointer-events: none; + + // Inherit border radius from style variations. + border-radius: inherit; + } + + // Style the upload button. + .components-placeholder__fieldset { + width: auto; + } + + color: currentColor; + .components-button.components-button { + color: inherit; + padding: 0; + margin: 0; + display: flex; + justify-content: center; + align-items: center; + width: $grid-unit-60; + height: $grid-unit-60; + border-radius: 50%; + + // @todo: needs to be icon button. + text-indent: 100%; + overflow: hidden; + } } + + // Show upload button on focus/hover. + &.is-selected .components-button, + .components-placeholder:focus .components-button, + .components-placeholder:hover .components-button { + background: var(--wp-admin-theme-color); + border-color: var(--wp-admin-theme-color); + border-style: solid; + color: $white; + opacity: 1; + } + } diff --git a/packages/block-library/src/site-logo/style.scss b/packages/block-library/src/site-logo/style.scss index dd8a883238f56..f5c86fedbbeb2 100644 --- a/packages/block-library/src/site-logo/style.scss +++ b/packages/block-library/src/site-logo/style.scss @@ -9,6 +9,9 @@ &.is-default-size img { width: 120px; height: auto; + + // Inherit border radius from style variations. + border-radius: inherit; } .aligncenter { @@ -16,7 +19,7 @@ } // Style variations - &.is-style-rounded img { + &.is-style-rounded { // We use an absolute pixel to prevent the oval shape that a value of 50% would give // to rectangular images. A pill-shape is better than otherwise. border-radius: 9999px; From daba47ccf90b814883e2289ee2360f10452273c9 Mon Sep 17 00:00:00 2001 From: jasmussen Date: Wed, 6 Oct 2021 13:42:21 +0200 Subject: [PATCH 02/12] Add illustration. --- packages/block-library/src/site-logo/edit.js | 15 ++++++++++++++- .../block-library/src/site-logo/editor.scss | 18 ++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/site-logo/edit.js b/packages/block-library/src/site-logo/edit.js index a10e4536a8cb5..cb89c21a9eada 100644 --- a/packages/block-library/src/site-logo/edit.js +++ b/packages/block-library/src/site-logo/edit.js @@ -35,6 +35,7 @@ import { import { useSelect, useDispatch } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; import { crop, siteLogo as icon } from '@wordpress/icons'; +import { SVG, Path } from '@wordpress/primitives'; /** * Internal dependencies @@ -469,7 +470,19 @@ export default function LogoEdit( { ) } onError={ onUploadError } - /> + > + + + + ) } ); diff --git a/packages/block-library/src/site-logo/editor.scss b/packages/block-library/src/site-logo/editor.scss index 003c58273a668..ed28f37efc71f 100644 --- a/packages/block-library/src/site-logo/editor.scss +++ b/packages/block-library/src/site-logo/editor.scss @@ -94,7 +94,7 @@ bottom: 0; left: 0; border: $border-width dashed currentColor; - opacity: 0.5; + opacity: 0.3; pointer-events: none; // Inherit border radius from style variations. @@ -117,11 +117,26 @@ width: $grid-unit-60; height: $grid-unit-60; border-radius: 50%; + position: relative; + z-index: 1; // @todo: needs to be icon button. text-indent: 100%; overflow: hidden; } + + // Style the placeholder illustration. + .components-placeholder__illustration { + position: absolute; + top: 0; + right: 0; + bottom: 0; + left: 0; + z-index: 0; + stroke: currentColor; + stroke-dasharray: 3; + opacity: 0.3; + } } // Show upload button on focus/hover. @@ -134,5 +149,4 @@ color: $white; opacity: 1; } - } From 1fc459659fcb93a3e515a7bab3ec50b600335c39 Mon Sep 17 00:00:00 2001 From: jasmussen Date: Wed, 6 Oct 2021 13:44:13 +0200 Subject: [PATCH 03/12] Add animation. --- packages/block-library/src/site-logo/editor.scss | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/block-library/src/site-logo/editor.scss b/packages/block-library/src/site-logo/editor.scss index ed28f37efc71f..a48eb7efa3623 100644 --- a/packages/block-library/src/site-logo/editor.scss +++ b/packages/block-library/src/site-logo/editor.scss @@ -120,6 +120,11 @@ position: relative; z-index: 1; + // Animation. + background: transparent; + transition: all 0.1s linear; + @include reduce-motion("transition"); + // @todo: needs to be icon button. text-indent: 100%; overflow: hidden; From 197fa4f9fe0b0c77842ecfacf57ced9cef2af13e Mon Sep 17 00:00:00 2001 From: jasmussen Date: Wed, 6 Oct 2021 13:55:27 +0200 Subject: [PATCH 04/12] Border radius. --- packages/block-library/src/site-logo/editor.scss | 8 ++++++-- packages/block-library/src/site-logo/style.scss | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/site-logo/editor.scss b/packages/block-library/src/site-logo/editor.scss index a48eb7efa3623..c38dabc3e116e 100644 --- a/packages/block-library/src/site-logo/editor.scss +++ b/packages/block-library/src/site-logo/editor.scss @@ -49,6 +49,12 @@ // and provides the on-hover upload button. // That would also let it work with with less specificity. .wp-block-site-logo.wp-block-site-logo { + // Inherit border radius from style variations. + .components-placeholder, + .components-resizable-box__container { + border-radius: inherit; + } + .components-placeholder { justify-content: center; align-items: center; @@ -57,8 +63,6 @@ height: 120px; padding: 0; - // Inherit border radius from style variations. - border-radius: inherit; // Hide the upload button, as it's also available in the media library. .components-form-file-upload { diff --git a/packages/block-library/src/site-logo/style.scss b/packages/block-library/src/site-logo/style.scss index f5c86fedbbeb2..ce94819156283 100644 --- a/packages/block-library/src/site-logo/style.scss +++ b/packages/block-library/src/site-logo/style.scss @@ -9,8 +9,11 @@ &.is-default-size img { width: 120px; height: auto; + } - // Inherit border radius from style variations. + // Inherit border radius from style variations. + &.is-default-size a, + &.is-default-size img { border-radius: inherit; } From c252863fa429baab54c4d100893cc8df90a341e0 Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Wed, 6 Oct 2021 10:49:33 -0700 Subject: [PATCH 05/12] Site Logo: use custom media logo button --- .../src/components/media-placeholder/index.js | 27 ++++++++++--------- packages/block-library/src/site-logo/edit.js | 14 +++++++++- .../block-library/src/site-logo/editor.scss | 5 ++++ 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/packages/block-editor/src/components/media-placeholder/index.js b/packages/block-editor/src/components/media-placeholder/index.js index d156138b96676..bd4afa193424d 100644 --- a/packages/block-editor/src/components/media-placeholder/index.js +++ b/packages/block-editor/src/components/media-placeholder/index.js @@ -76,6 +76,7 @@ export function MediaPlaceholder( { onFilesPreUpload = noop, onHTMLDrop = noop, children, + customMediaLibraryButton, } ) { const mediaUpload = useSelect( ( select ) => { const { getSettings } = select( blockEditorStore ); @@ -304,6 +305,19 @@ export function MediaPlaceholder( { }; const renderMediaUploadChecked = () => { + const defaultButton = ( { open } ) => { + return ( + + ); + }; + const libraryButton = customMediaLibraryButton ?? defaultButton; const mediaLibraryButton = ( id ) : value.id } - render={ ( { open } ) => { - return ( - - ); - } } + render={ libraryButton } /> ); diff --git a/packages/block-library/src/site-logo/edit.js b/packages/block-library/src/site-logo/edit.js index cb89c21a9eada..6959e13b84d44 100644 --- a/packages/block-library/src/site-logo/edit.js +++ b/packages/block-library/src/site-logo/edit.js @@ -20,6 +20,7 @@ import { ToggleControl, ToolbarButton, Placeholder, + Button, } from '@wordpress/components'; import { useViewportMatch } from '@wordpress/compose'; import { @@ -34,7 +35,7 @@ import { } from '@wordpress/block-editor'; import { useSelect, useDispatch } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; -import { crop, siteLogo as icon } from '@wordpress/icons'; +import { crop, siteLogo as icon, upload } from '@wordpress/icons'; import { SVG, Path } from '@wordpress/primitives'; /** @@ -470,6 +471,17 @@ export default function LogoEdit( { ) } onError={ onUploadError } + customMediaLibraryButton={ ( { open } ) => { + return ( + ); }; - const libraryButton = customMediaLibraryButton ?? defaultButton; - const mediaLibraryButton = ( + const libraryButton = mediaLibraryButton ?? defaultButton; + const uploadMediaLibraryButton = ( { __( 'Upload' ) } - { mediaLibraryButton } + { uploadMediaLibraryButton } { renderUrlSelectionUI() } { renderCancelLink() } @@ -383,7 +385,7 @@ export function MediaPlaceholder( { > { __( 'Upload' ) } - { mediaLibraryButton } + { uploadMediaLibraryButton } { renderUrlSelectionUI() } { renderCancelLink() } @@ -391,7 +393,7 @@ export function MediaPlaceholder( { return renderPlaceholder( content ); } - return renderPlaceholder( mediaLibraryButton ); + return renderPlaceholder( uploadMediaLibraryButton ); }; if ( dropZoneUIOnly || disableMediaButtons ) { diff --git a/packages/block-library/src/site-logo/edit.js b/packages/block-library/src/site-logo/edit.js index 6959e13b84d44..973c1bda8955e 100644 --- a/packages/block-library/src/site-logo/edit.js +++ b/packages/block-library/src/site-logo/edit.js @@ -35,7 +35,7 @@ import { } from '@wordpress/block-editor'; import { useSelect, useDispatch } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; -import { crop, siteLogo as icon, upload } from '@wordpress/icons'; +import { crop, upload } from '@wordpress/icons'; import { SVG, Path } from '@wordpress/primitives'; /** @@ -405,7 +405,6 @@ export default function LogoEdit( { ); - const label = __( 'Site Logo' ); let logoImage; const isLoading = siteLogoId === undefined || isRequestingMediaItem; if ( isLoading ) { @@ -427,6 +426,42 @@ export default function LogoEdit( { /> ); } + const placeholder = ( content ) => { + const placeholderClassName = classnames( + 'block-editor-media-placeholder', + className + ); + + return ( + + { error } + + ) + } + preview={ logoImage } + > + { + + + + } + { content } + + ); + }; + const classes = classnames( className, { 'is-default-size': ! width, } ); @@ -439,11 +474,7 @@ export default function LogoEdit( { { controls } { !! logoUrl && logoImage } { ! logoUrl && ! canUserEdit && ( - + { isLoading && ( @@ -453,25 +484,12 @@ export default function LogoEdit( { ) } { ! logoUrl && canUserEdit && ( - { error } - - ) - } onError={ onUploadError } - customMediaLibraryButton={ ( { open } ) => { + placeholder={ placeholder } + mediaLibraryButton={ ( { open } ) => { return (