Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search: Replace ButtonGroup usage with ToggleGroupControl #65340

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 27 additions & 24 deletions packages/block-library/src/search/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import { useEffect, useRef } from '@wordpress/element';
import {
ToolbarDropdownMenu,
ToolbarGroup,
Button,
ButtonGroup,
ToolbarButton,
ResizableBox,
PanelBody,
__experimentalVStack as VStack,
__experimentalUseCustomUnits as useCustomUnits,
__experimentalUnitControl as UnitControl,
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
} from '@wordpress/components';
import { useInstanceId } from '@wordpress/compose';
import { Icon, search } from '@wordpress/icons';
Expand Down Expand Up @@ -58,6 +58,7 @@ import {
// Used to calculate border radius adjustment to avoid "fat" corners when
// button is placed inside wrapper.
const DEFAULT_INNER_PADDING = '4px';
const PERCENTAGE_WIDTHS = [ 25, 50, 75, 100 ];

export default function SearchEdit( {
className,
Expand Down Expand Up @@ -445,33 +446,35 @@ export default function SearchEdit( {
value={ `${ width }${ widthUnit }` }
units={ units }
/>
<ButtonGroup
className="wp-block-search__components-button-group" // unused, kept for backwards compatibility
aria-label={ __( 'Percentage Width' ) }
<ToggleGroupControl
Mamaduka marked this conversation as resolved.
Show resolved Hide resolved
label={ __( 'Percentage Width' ) }
value={
PERCENTAGE_WIDTHS.includes( width ) &&
widthUnit === '%'
? width
: undefined
}
Mamaduka marked this conversation as resolved.
Show resolved Hide resolved
hideLabelFromVision
onChange={ ( newWidth ) => {
setAttributes( {
width: newWidth,
widthUnit: '%',
} );
} }
isBlock
__next40pxDefaultSize
__nextHasNoMarginBottom
>
{ [ 25, 50, 75, 100 ].map( ( widthValue ) => {
{ PERCENTAGE_WIDTHS.map( ( widthValue ) => {
return (
<Button
<ToggleGroupControlOption
key={ widthValue }
size="small"
variant={
widthValue === width &&
widthUnit === '%'
? 'primary'
: undefined
}
onClick={ () =>
setAttributes( {
width: widthValue,
widthUnit: '%',
} )
}
>
{ widthValue }%
</Button>
value={ widthValue }
label={ `${ widthValue }%` }
/>
);
} ) }
</ButtonGroup>
</ToggleGroupControl>
</VStack>
</PanelBody>
</InspectorControls>
Expand Down
Loading