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

BoxControl: Refactor and unify the different sides implementation #67626

Merged
merged 11 commits into from
Dec 10, 2024
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- `MenuItem`: Increase height to 40px ([#67435](https://github.com/WordPress/gutenberg/pull/67435)).
- `MenuItemsChoice`: Increase option height to 40px ([#67435](https://github.com/WordPress/gutenberg/pull/67435)).
- `Navigation`: Fix active item hover color ([#67732](https://github.com/WordPress/gutenberg/pull/67732)).
- `BoxControl`: Refactor internals to unify the different combinations of sides. ([#67626](https://github.com/WordPress/gutenberg/pull/67626))
youknowriad marked this conversation as resolved.
Show resolved Hide resolved

### Deprecations

Expand Down
110 changes: 0 additions & 110 deletions packages/components/src/box-control/all-input-control.tsx

This file was deleted.

165 changes: 0 additions & 165 deletions packages/components/src/box-control/axial-input-controls.tsx

This file was deleted.

38 changes: 24 additions & 14 deletions packages/components/src/box-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ import { __ } from '@wordpress/i18n';
* Internal dependencies
*/
import { BaseControl } from '../base-control';
import AllInputControl from './all-input-control';
import InputControls from './input-controls';
import AxialInputControls from './axial-input-controls';
import InputControl from './input-control';
import LinkedButton from './linked-button';
import { Grid } from '../grid';
import {
FlexedBoxControlIcon,
InputWrapper,
ResetButton,
LinkedButtonWrapper,
Expand All @@ -24,8 +21,9 @@ import { parseQuantityAndUnitFromRawValue } from '../unit-control/utils';
import {
DEFAULT_VALUES,
getInitialSide,
isValuesMixed,
isValueMixed,
isValuesDefined,
getAllowedSides,
} from './utils';
import { useControlledState } from '../utils/hooks';
import type {
Expand Down Expand Up @@ -97,7 +95,7 @@ function BoxControl( {

const [ isDirty, setIsDirty ] = useState( hasInitialValue );
const [ isLinked, setIsLinked ] = useState(
! hasInitialValue || ! isValuesMixed( inputValues ) || hasOneSide
! hasInitialValue || ! isValueMixed( inputValues ) || hasOneSide
);

const [ side, setSide ] = useState< BoxControlIconProps[ 'side' ] >(
Expand Down Expand Up @@ -162,6 +160,7 @@ function BoxControl( {
__next40pxDefaultSize,
size: undefined,
} );
const sidesToRender = getAllowedSides( sides );

return (
<Grid
Expand All @@ -176,8 +175,7 @@ function BoxControl( {
</BaseControl.VisualLabel>
{ isLinked && (
<InputWrapper>
<FlexedBoxControlIcon side={ side } sides={ sides } />
<AllInputControl { ...inputControlProps } />
<InputControl side="all" { ...inputControlProps } />
</InputWrapper>
) }
{ ! hasOneSide && (
Expand All @@ -189,12 +187,24 @@ function BoxControl( {
</LinkedButtonWrapper>
) }

{ ! isLinked && splitOnAxis && (
<AxialInputControls { ...inputControlProps } />
) }
{ ! isLinked && ! splitOnAxis && (
<InputControls { ...inputControlProps } />
) }
{ ! isLinked &&
splitOnAxis &&
[ 'vertical', 'horizontal' ].map( ( axis ) => (
<InputControl
key={ axis }
side={ axis as 'horizontal' | 'vertical' }
youknowriad marked this conversation as resolved.
Show resolved Hide resolved
{ ...inputControlProps }
/>
) ) }
{ ! isLinked &&
! splitOnAxis &&
Array.from( sidesToRender ).map( ( axis ) => (
<InputControl
key={ axis }
side={ axis }
{ ...inputControlProps }
/>
youknowriad marked this conversation as resolved.
Show resolved Hide resolved
) ) }
{ allowReset && (
<ResetButton
className="component-box-control__reset-button"
Expand Down
Loading
Loading