From 632d8d62e8f8621c2771b266c1d2a68477bb3ca1 Mon Sep 17 00:00:00 2001 From: Madhu Dollu Date: Fri, 13 Sep 2024 12:09:33 +0530 Subject: [PATCH] Spacing control: Replace sides dropdwon with link button (#65193) * replace sides dropdown with link button for spacing control * remove sides dropdown * lowercase the link button tooltip * fix unit tests --- .../components/spacing-sizes-control/index.js | 23 ++--- .../spacing-sizes-control/linked-button.js | 32 +++++++ .../sides-dropdown/index.js | 91 ------------------- .../spacing-sizes-control/test/utils.js | 29 +++--- .../components/spacing-sizes-control/utils.js | 23 +---- 5 files changed, 61 insertions(+), 137 deletions(-) create mode 100644 packages/block-editor/src/components/spacing-sizes-control/linked-button.js delete mode 100644 packages/block-editor/src/components/spacing-sizes-control/sides-dropdown/index.js diff --git a/packages/block-editor/src/components/spacing-sizes-control/index.js b/packages/block-editor/src/components/spacing-sizes-control/index.js index 6886670f54115..6ca143d14706a 100644 --- a/packages/block-editor/src/components/spacing-sizes-control/index.js +++ b/packages/block-editor/src/components/spacing-sizes-control/index.js @@ -7,7 +7,7 @@ import { __experimentalVStack as VStack, } from '@wordpress/components'; import { useState } from '@wordpress/element'; -import { __, _x, sprintf } from '@wordpress/i18n'; +import { __, sprintf } from '@wordpress/i18n'; /** * Internal dependencies @@ -15,7 +15,7 @@ import { __, _x, sprintf } from '@wordpress/i18n'; import AxialInputControls from './input-controls/axial'; import SeparatedInputControls from './input-controls/separated'; import SingleInputControl from './input-controls/single'; -import SidesDropdown from './sides-dropdown'; +import LinkedButton from './linked-button'; import useSpacingSizes from './hooks/use-spacing-sizes'; import { ALL_SIDES, @@ -47,6 +47,10 @@ export default function SpacingSizesControl( { const [ view, setView ] = useState( getInitialView( inputValues, sides ) ); + const toggleLinked = () => { + setView( view === VIEWS.axial ? VIEWS.custom : VIEWS.axial ); + }; + const handleOnChange = ( nextValue ) => { const newValues = { ...values, ...nextValue }; onChange( newValues ); @@ -91,12 +95,6 @@ export default function SpacingSizesControl( { sideLabel ).trim(); - const dropdownLabelText = sprintf( - // translators: %s: The current spacing property e.g. "Padding", "Margin". - _x( '%s options', 'Button label to reveal side configuration options' ), - labelProp - ); - return (
@@ -107,11 +105,10 @@ export default function SpacingSizesControl( { { label } { ! hasOneSide && ! hasOnlyAxialSides && ( - ) } diff --git a/packages/block-editor/src/components/spacing-sizes-control/linked-button.js b/packages/block-editor/src/components/spacing-sizes-control/linked-button.js new file mode 100644 index 0000000000000..e9ca68aaa2b31 --- /dev/null +++ b/packages/block-editor/src/components/spacing-sizes-control/linked-button.js @@ -0,0 +1,32 @@ +/** + * WordPress dependencies + */ +import { Button, Tooltip } from '@wordpress/components'; +import { link, linkOff } from '@wordpress/icons'; +import { __, sprintf } from '@wordpress/i18n'; + +export default function LinkedButton( { isLinked, ...props } ) { + const label = isLinked + ? sprintf( + // translators: 1. Type of spacing being modified (padding, margin, etc). + __( 'Unlink %1$s' ), + props.label.toLowerCase() + ).trim() + : sprintf( + // translators: 1. Type of spacing being modified (padding, margin, etc). + __( 'Link %1$s' ), + props.label.toLowerCase() + ).trim(); + + return ( + +