Skip to content

Commit

Permalink
Move explicit width handling to UnitControl instead of styles
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Jul 22, 2022
1 parent fc71ace commit ef4c90b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const UnconnectedBorderControl = (
enableStyle = true,
hideLabelFromVision,
innerWrapperClassName,
inputWidth,
label,
onBorderChange,
onSliderChange,
Expand Down Expand Up @@ -96,6 +97,7 @@ const UnconnectedBorderControl = (
onChange={ onWidthChange }
value={ border?.width || '' }
placeholder={ placeholder }
__unstableInputWidth={ inputWidth }
/>
{ withSlider && (
<RangeControl
Expand Down
8 changes: 4 additions & 4 deletions packages/components/src/border-control/border-control/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,13 @@ export function useBorderControl(
return cx( styles.borderControl, className );
}, [ className, cx ] );

const wrapperWidth = isCompact ? '90px' : width;
const innerWrapperClassName = useMemo( () => {
const wrapperWidth = isCompact ? '90px' : width;
const widthStyle =
!! wrapperWidth && styles.wrapperWidth( wrapperWidth );
const widthStyle = !! wrapperWidth && styles.wrapperWidth;
const heightStyle = styles.wrapperHeight( __next36pxDefaultSize );

return cx( styles.innerWrapper(), widthStyle, heightStyle );
}, [ isCompact, width, cx, __next36pxDefaultSize ] );
}, [ wrapperWidth, cx, __next36pxDefaultSize ] );

const sliderClassName = useMemo( () => {
return cx( styles.borderSlider() );
Expand All @@ -135,6 +134,7 @@ export function useBorderControl(
...otherProps,
className: classes,
innerWrapperClassName,
inputWidth: wrapperWidth,
onBorderChange,
onSliderChange,
onWidthChange,
Expand Down
23 changes: 14 additions & 9 deletions packages/components/src/border-control/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import { css } from '@emotion/react';
import type { CSSProperties } from 'react';

/**
* Internal dependencies
Expand Down Expand Up @@ -35,20 +34,26 @@ export const borderControl = css`
`;

export const innerWrapper = () => css`
${ UnitControlWrapper } {
flex: 1 1 40%;
}
&& ${ UnitSelect } {
/* Prevent unit select forcing min height larger than its UnitControl */
min-height: 0;
}
`;

export const wrapperWidth = ( width: CSSProperties[ 'width' ] ) => {
return css`
${ UnitControlWrapper } {
width: ${ width };
flex: 0 0 auto;
}
`;
};
/*
* This style is only applied to the UnitControl wrapper when the border width
* field should be a set width. Omitting this allows the UnitControl &
* RangeControl to share the available width in a 40/60 split respectively.
*/
export const wrapperWidth = css`
${ UnitControlWrapper } {
/* Force the UnitControl's set width. */
flex: 0 0 auto;
}
`;

/*
* When default control height is 36px the following should be removed.
Expand Down

0 comments on commit ef4c90b

Please sign in to comment.