From cacd65bd18dfcd3d7676d3f8d865c06b660b5202 Mon Sep 17 00:00:00 2001 From: Nick Diego Date: Mon, 22 Jul 2024 20:51:29 -0500 Subject: [PATCH] Add support for `contentOnly` editing. --- src/block.json | 6 +- src/edit.js | 198 +++++++++++++++++++++++++++++++++++------------- src/editor.scss | 9 +++ 3 files changed, 158 insertions(+), 55 deletions(-) diff --git a/src/block.json b/src/block.json index 44e0cf1..1795b28 100644 --- a/src/block.json +++ b/src/block.json @@ -10,10 +10,12 @@ "type": "string", "source": "html", "selector": ".icon-container", - "default": "" + "default": "", + "__experimentalRole": "content" }, "iconName": { - "type": "string" + "type": "string", + "__experimentalRole": "content" }, "itemsJustification": { "type": "string" diff --git a/src/edit.js b/src/edit.js index 515044a..968d77a 100644 --- a/src/edit.js +++ b/src/edit.js @@ -30,6 +30,7 @@ import { MediaUpload, useBlockProps, withColors, + useBlockEditingMode, __experimentalColorGradientSettingsDropdown as ColorGradientSettingsDropdown, // eslint-disable-line __experimentalUseMultipleOriginColorsAndGradients as useMultipleOriginColorsAndGradients, // eslint-disable-line __experimentalUseGradient as useGradient, // eslint-disable-line @@ -152,6 +153,7 @@ export function Edit( props ) { true ); + const isContentOnlyMode = useBlockEditingMode() === 'contentOnly'; const ref = useRef(); const iconRef = useRef(); const isURLSet = !! linkUrl; @@ -310,18 +312,29 @@ export function Edit( props ) { const blockControls = ( <> - - - setAttributes( { itemsJustification: value } ) - } - /> - { ( icon || iconName ) && ( - - + + + { ! isContentOnlyMode && ( + + setAttributes( { + itemsJustification: value, + } ) + } + /> + ) } - - - setRotate( rotate ) } - isPressed={ rotate } - /> - - setAttributes( { - flipHorizontal: ! flipHorizontal, - } ) - } - isPressed={ flipHorizontal } - /> - - setAttributes( { - flipVertical: ! flipVertical, - } ) - } - isPressed={ flipVertical } - /> - - - { enableCustomIcons || isSVGUploadAllowed ? ( - replaceDropdown - ) : ( - { - setInserterOpen( true ); - } } - > - { __( 'Replace', 'icon-block' ) } - + { ! isContentOnlyMode && ( + <> + setRotate( rotate ) } + isPressed={ rotate } + /> + + setAttributes( { + flipHorizontal: ! flipHorizontal, + } ) + } + isPressed={ flipHorizontal } + /> + + setAttributes( { + flipVertical: ! flipVertical, + } ) + } + isPressed={ flipVertical } + /> + ) } ) } + + + { ( icon || iconName || isContentOnlyMode ) && ( + <> + { enableCustomIcons || isSVGUploadAllowed ? ( + replaceDropdown + ) : ( + { + setInserterOpen( true ); + } } + > + { __( 'Replace', 'icon-block' ) } + + ) } + + ) } + { isContentOnlyMode && ( icon || iconName ) && ( + // Add some extra controls for content attributes when content only mode is active. + // With content only mode active, the inspector is hidden, so users need another way + // to edit these attributes. + <> + + { () => ( + + setAttributes( { label: value } ) + } + help={ __( + 'Briefly describe the icon to help screen reader users.', + 'icon-block' + ) } + __nextHasNoMarginBottom + /> + ) } + + + { () => ( + + setAttributes( { title: value } ) + } + help={ + <> + { __( + 'Describe the role of this icon on the page. ', + 'icon-block' + ) } + + { __( + 'Note: many devices and browsers do not display this text', + 'icon-block' + ) } + + + } + __nextHasNoMarginBottom + /> + ) } + + + ) } + + { isEditingURL && (