Skip to content

Commit

Permalink
DimensionControl: Add flag to remove bottom margin (WordPress#64346)
Browse files Browse the repository at this point in the history
* DimensionControl: Add flag to remove bottom margin

* Add lint rule

* Update in block-editor readme

* Add changelog

Co-authored-by: mirka <[email protected]>
Co-authored-by: tyxla <[email protected]>
  • Loading branch information
3 people authored Aug 9, 2024
1 parent 34b5219 commit db35abd
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ module.exports = {
...[
'CheckboxControl',
'ComboboxControl',
'DimensionControl',
'FocalPointPicker',
'RangeControl',
'SearchControl',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ registerBlockType( 'my-plugin/my-block', {
const paddingControl = ( labelComponent, viewport ) => {
return (
<DimensionControl
__nextHasNoMarginBottom
label={ viewport.label }
onChange={ // handle update to padding value here }
value={ paddingSize }
Expand Down
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- `SelectControl`: Infer `value` type from `options` ([#64069](https://github.com/WordPress/gutenberg/pull/64069)).
- `Guide`: Add `__next40pxDefaultSize` to buttons ([#64181](https://github.com/WordPress/gutenberg/pull/64181)).
- `SelectControl`: Pass through `options` props ([#64211](https://github.com/WordPress/gutenberg/pull/64211)).
- `DimensionControl`: Add `__nextHasNoMarginBottom` prop to remove bottom margin ([#64346](https://github.com/WordPress/gutenberg/pull/64346)).

### Internal

Expand Down
9 changes: 9 additions & 0 deletions packages/components/src/dimension-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default function MyCustomDimensionControl() {

return (
<DimensionControl
__nextHasNoMarginBottom
label={ 'Padding' }
icon={ 'desktop' }
onChange={ ( value ) => setPaddingSize( value ) }
Expand Down Expand Up @@ -91,3 +92,11 @@ A callback which is triggered when a spacing size value changes (is selected/cli
- **Required:** No

A string of classes to be added to the control component.

### __nextHasNoMarginBottom

Start opting into the new margin-free styles that will become the default in a future version.

- Type: `Boolean`
- Required: No
- Default: `false`
3 changes: 3 additions & 0 deletions packages/components/src/dimension-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import type { SelectControlSingleSelectionProps } from '../select-control/types'
*
* return (
* <DimensionControl
* __nextHasNoMarginBottom
* label={ 'Padding' }
* icon={ 'desktop' }
* onChange={ ( value ) => setPaddingSize( value ) }
Expand All @@ -43,6 +44,7 @@ import type { SelectControlSingleSelectionProps } from '../select-control/types'
export function DimensionControl( props: DimensionControlProps ) {
const {
__next40pxDefaultSize = false,
__nextHasNoMarginBottom = false,
label,
value,
sizes = sizesTable,
Expand Down Expand Up @@ -87,6 +89,7 @@ export function DimensionControl( props: DimensionControlProps ) {
return (
<SelectControl
__next40pxDefaultSize={ __next40pxDefaultSize }
__nextHasNoMarginBottom={ __nextHasNoMarginBottom }
className={ clsx( className, 'block-editor-dimension-control' ) }
label={ selectLabel }
hideLabelFromVision={ false }
Expand Down
12 changes: 5 additions & 7 deletions packages/components/src/dimension-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Internal dependencies
*/
import type { IconType } from '../icon';
import type { SelectControlProps } from '../select-control/types';

export type Size = {
/**
Expand All @@ -14,7 +15,10 @@ export type Size = {
slug: string;
};

export type DimensionControlProps = {
export type DimensionControlProps = Pick<
SelectControlProps,
'__next40pxDefaultSize' | '__nextHasNoMarginBottom'
> & {
/**
* Label for the control.
*/
Expand Down Expand Up @@ -45,10 +49,4 @@ export type DimensionControlProps = {
* @default ''
*/
className?: string;
/**
* Start opting into the larger default height that will become the default size in a future version.
*
* @default false
*/
__next40pxDefaultSize?: boolean;
};

0 comments on commit db35abd

Please sign in to comment.