-
Notifications
You must be signed in to change notification settings - Fork 805
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forms: update width control to use more modern togglecontrol (#41130)
* Forms: update width selector to use ToggleGroupControl * changelog * Fix onClick/onChange Co-authored-by: Lena Morita <[email protected]> * Simplyfy the code * Update the label to match block editor --------- Co-authored-by: Lena Morita <[email protected]> Co-authored-by: Enej Bajgoric <[email protected]>
- Loading branch information
Showing
3 changed files
with
26 additions
and
23 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
projects/packages/forms/changelog/update-forms-width-togglecontrol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: changed | ||
|
||
Forms: update width control to use more modern ToggleGroupControl |
35 changes: 22 additions & 13 deletions
35
projects/packages/forms/src/blocks/contact-form/components/jetpack-field-width.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,40 @@ | ||
import { BaseControl, Button, ButtonGroup } from '@wordpress/components'; | ||
import { | ||
BaseControl, | ||
__experimentalToggleGroupControl as ToggleGroupControl, // eslint-disable-line @wordpress/no-unsafe-wp-apis | ||
__experimentalToggleGroupControlOption as ToggleGroupControlOption, // eslint-disable-line @wordpress/no-unsafe-wp-apis | ||
} from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
const PERCENTAGE_WIDTHS = [ 25, 50, 75, 100 ]; | ||
|
||
export default function JetpackFieldWidth( { setAttributes, width } ) { | ||
return ( | ||
<BaseControl | ||
help={ __( | ||
'Adjust the width of the field to include multiple fields on a single line.', | ||
'jetpack-forms' | ||
) } | ||
className="jetpack-field-label__width" | ||
__nextHasNoMarginBottom={ true } | ||
> | ||
<BaseControl.VisualLabel>{ __( 'Field Width', 'jetpack-forms' ) }</BaseControl.VisualLabel> | ||
<ButtonGroup aria-label={ __( 'Field Width', 'jetpack-forms' ) }> | ||
{ [ 25, 50, 75, 100 ].map( widthValue => { | ||
<ToggleGroupControl | ||
__next40pxDefaultSize | ||
__nextHasNoMarginBottom | ||
aria-label={ __( 'Width', 'jetpack-forms' ) } | ||
isBlock | ||
label={ __( 'Width', 'jetpack-forms' ) } | ||
onChange={ value => setAttributes( { width: value } ) } | ||
value={ width } | ||
> | ||
{ PERCENTAGE_WIDTHS.map( widthValue => { | ||
return ( | ||
<Button | ||
<ToggleGroupControlOption | ||
key={ widthValue } | ||
isSmall | ||
variant={ widthValue === width ? 'primary' : undefined } | ||
onClick={ () => setAttributes( { width: widthValue } ) } | ||
> | ||
{ widthValue }% | ||
</Button> | ||
label={ `${ widthValue }%` } | ||
value={ widthValue } | ||
/> | ||
); | ||
} ) } | ||
</ButtonGroup> | ||
</ToggleGroupControl> | ||
</BaseControl> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters