ResizableBox wraps content in a container with draggable handles, letting
users interactively resize it along one or more edges or corners.
import { ResizableBox } from '@wordpress/components';
LinksPermalink to this section
PropsPermalink to this section
| Name | Default | Description |
|---|---|---|
as |
| |
style |
| |
className |
| |
grid |
| |
snap |
| |
snapGap |
| |
bounds |
| |
boundsByDirection |
| |
size |
| |
minWidth |
| |
minHeight |
| |
maxWidth |
| |
maxHeight |
| |
lockAspectRatio |
| |
lockAspectRatioExtraWidth |
| |
lockAspectRatioExtraHeight |
| |
enable |
| |
handleStyles |
| |
handleClasses |
| |
handleWrapperStyle |
| |
handleWrapperClass |
| |
handleComponent |
| |
children |
| |
onResizeStart |
| |
onResize |
| |
onResizeStop |
| |
defaultSize |
| |
scale |
| |
resizeRatio |
| |
showHandle | true |
|
__experimentalShowTooltip | false |
|
__experimentalTooltipProps | {} |
|
ref |
Allows getting a ref to the component instance.
Once the component unmounts, React will set | |
key |
|
ExamplesPermalink to this section
DefaultPermalink to this section
const Default = ( {
onResizeStop,
...props
} ) => {
const [ { height, width }, setAttributes ] = useState( {
height: 200,
width: 400,
} );
return (
<ResizableBox
{ ...props }
size={ {
height,
width,
} }
onResizeStop={ ( event, direction, elt, delta ) => {
onResizeStop?.( event, direction, elt, delta );
setAttributes( {
height: height + delta.height,
width: width + delta.width,
} );
} }
/>
);
};
Disabled DirectionsPermalink to this section
The enable prop can be used to disable resizing in specific directions.
const DisabledDirections = ( {
onResizeStop,
...props
} ) => {
const [ { height, width }, setAttributes ] = useState( {
height: 200,
width: 400,
} );
return (
<ResizableBox
{ ...props }
size={ {
height,
width,
} }
onResizeStop={ ( event, direction, elt, delta ) => {
onResizeStop?.( event, direction, elt, delta );
setAttributes( {
height: height + delta.height,
width: width + delta.width,
} );
} }
/>
);
};
With Resize TooltipPermalink to this section
The resize size label is hidden by default. Enable it with
__experimentalShowTooltip, or toggle that control in Storybook.
const WithResizeTooltip = ( {
onResizeStop,
...props
} ) => {
const [ { height, width }, setAttributes ] = useState( {
height: 200,
width: 400,
} );
return (
<ResizableBox
{ ...props }
size={ {
height,
width,
} }
onResizeStop={ ( event, direction, elt, delta ) => {
onResizeStop?.( event, direction, elt, delta );
setAttributes( {
height: height + delta.height,
width: width + delta.width,
} );
} }
/>
);
};