Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Move logic to hook for BorderControl
  • Loading branch information
brookewp committed Jan 15, 2024
commit dfe78d508eae29600503bc0565dbd9fa3dc97882
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ const UnconnectedBorderControl = (
...otherProps
} = useBorderControl( props );

const inputHeight = __next40pxDefaultSize ? '__unstable-large' : size;

return (
<View as="fieldset" { ...otherProps } ref={ forwardedRef }>
<BorderLabel
Expand All @@ -89,7 +87,7 @@ const UnconnectedBorderControl = (
__experimentalIsRenderedInSidebar={
__experimentalIsRenderedInSidebar
}
size={ inputHeight }
size={ size }
/>
}
label={ __( 'Border width' ) }
Expand All @@ -100,7 +98,7 @@ const UnconnectedBorderControl = (
placeholder={ placeholder }
disableUnits={ disableUnits }
__unstableInputWidth={ inputWidth }
size={ inputHeight }
size={ size }
/>
{ withSlider && (
<RangeControl
Expand All @@ -115,6 +113,7 @@ const UnconnectedBorderControl = (
step={ [ 'px', '%' ].includes( widthUnit ) ? 1 : 0.1 }
value={ widthValue || undefined }
withInputField={ false }
__next40pxDefaultSize={ __next40pxDefaultSize }
/>
) }
</HStack>
Expand Down
11 changes: 8 additions & 3 deletions packages/components/src/border-control/border-control/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ export function useBorderControl(
value: border,
width,
__experimentalIsRenderedInSidebar = false,
__next40pxDefaultSize,
...otherProps
} = useContextSystem( props, 'BorderControl' );

const computedSize =
size === 'default' && __next40pxDefaultSize ? '__unstable-large' : size;

const [ widthValue, originalWidthUnit ] = parseQuantityAndUnitFromRawValue(
border?.width
);
Expand Down Expand Up @@ -130,10 +134,10 @@ export function useBorderControl(
}
const innerWrapperClassName = useMemo( () => {
const widthStyle = !! wrapperWidth && styles.wrapperWidth;
const heightStyle = styles.wrapperHeight( size );
const heightStyle = styles.wrapperHeight( computedSize );

return cx( styles.innerWrapper(), widthStyle, heightStyle );
}, [ wrapperWidth, cx, size ] );
}, [ wrapperWidth, cx, computedSize ] );

const sliderClassName = useMemo( () => {
return cx( styles.borderSlider() );
Expand All @@ -155,7 +159,8 @@ export function useBorderControl(
value: border,
widthUnit,
widthValue,
size,
size: computedSize,
__experimentalIsRenderedInSidebar,
__next40pxDefaultSize,
};
}