Create a resizable component with percentage size support.
Install the package using npm:
npm install react-grid-layout
import React from 'react'
import ReactDOM from 'react-dom'
import { ResizableArea } from 'react-resizable-area'
class Main extends React.Component {
state = {}
render () {
return (
<ResizableArea
minimumHeight={{px: 0, percent: 50}}
minimumWidth={{px: 0, percent: 50}}
initHeight={{px: 0, percent: 80}}
initWidth={{px: 0, percent: 80}}
defaultHeight={{px: 0, percent: 80}}
defaultWidth={{px: 0, percent: 80}}
maximumHeight={{px: 0, percent: 100}}
maximumWidth={{px: 0, percent: 100}}
parentContainer={document.querySelector('.resizable-container')}
>
<div
style={{backgroundColor: '#03a9f4', width: '100%', height: '100%'}}
ref={e => !this.state.container && this.setState({ container: e })}
>
<ResizableArea
minimumHeight={{px: 0, percent: 10}}
minimumWidth={{px: 0, percent: 10}}
initHeight={{px: 20, percent: 50}}
initWidth={{px: 20, percent: 50}}
defaultHeight={{px: 0, percent: 50}}
defaultWidth={{px: 0, percent: 50}}
maximumHeight={{px: 0, percent: 80}}
maximumWidth={{px: 0, percent: 80}}
parentContainer={this.state.container}
>
<div style={{backgroundColor: 'white', width: '100%', height: '100%'}}>
</div>
</ResizableArea>
</div>
</ResizableArea>
)
}
}
ReactDOM.render(
<Main />,
document.querySelector('.resizable-container')
)
Set size of component directly
ID of the resizable component
Extra className of the resizable component
The component that resized by resizable component
The DOM node that CSS prop width
& height
relative to.
Disable resize on width / height direction
Resize the component by changing percentage or px
The minimum width of the component
Present as calc({px}px + {percent}%)
The minimum height of the component
The maximum width of the component
The maximum height of the component
The initial width of the component
The initial height of the component
The default width of the component (double click on right edge will reset to this size)
The default height of the component (double click on bottom edge will reset to this size)
Callback that fired on component resizing
Callback that fired on resize completed.