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

DimensionControl: Add flag to remove bottom margin #64346

Merged
merged 4 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
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
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'
> & {
Comment on lines +18 to +21
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not picking other props like value or label because they either have different descriptions or different required settings.

/**
* 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;
};
Loading