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

Button: Replace ButtonGroup usage with ToggleGroupControl #65346

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Changes from 1 commit
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
48 changes: 20 additions & 28 deletions packages/block-library/src/button/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import removeAnchorTag from '../utils/remove-anchor-tag';
import { __ } from '@wordpress/i18n';
import { useEffect, useState, useRef, useMemo } from '@wordpress/element';
import {
Button,
ButtonGroup,
TextControl,
ToolbarButton,
Popover,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
} from '@wordpress/components';
import {
AlignmentControl,
Expand Down Expand Up @@ -115,46 +115,38 @@ function useEnter( props ) {
}

function WidthPanel( { selectedWidth, setAttributes } ) {
function handleChange( newWidth ) {
// Check if we are toggling the width off
const width = selectedWidth === newWidth ? undefined : newWidth;

// Update attributes.
setAttributes( { width } );
}

return (
<ToolsPanel
label={ __( 'Settings' ) }
resetAll={ () => {
handleChange( undefined );
} }
resetAll={ () => setAttributes( { width: undefined } ) }
>
<ToolsPanelItem
label={ __( 'Button width' ) }
__nextHasNoMarginBottom
isShownByDefault
hasValue={ () => !! selectedWidth }
onDeselect={ () => handleChange( undefined ) }
onDeselect={ () => setAttributes( { width: undefined } ) }
__nextHasNoMarginBottom
>
<ButtonGroup aria-label={ __( 'Button width' ) }>
<ToggleGroupControl
label={ __( 'Button width' ) }
value={ selectedWidth }
onChange={ ( newWidth ) =>
setAttributes( { width: newWidth } )
}
isBlock
__next40pxDefaultSize
__nextHasNoMarginBottom
>
{ [ 25, 50, 75, 100 ].map( ( widthValue ) => {
return (
<Button
<ToggleGroupControlOption
key={ widthValue }
size="small"
variant={
widthValue === selectedWidth
? 'primary'
: undefined
}
onClick={ () => handleChange( widthValue ) }
>
{ widthValue }%
</Button>
value={ widthValue }
label={ `${ widthValue }%` }
/>
);
} ) }
</ButtonGroup>
</ToggleGroupControl>
</ToolsPanelItem>
</ToolsPanel>
);
Expand Down
Loading