Gathering detailed insights and metrics for react-resizable
Gathering detailed insights and metrics for react-resizable
Gathering detailed insights and metrics for react-resizable
Gathering detailed insights and metrics for react-resizable
npm install react-resizable
Typescript
Module System
92.4
Supply Chain
95
Quality
75.9
Maintenance
100
Vulnerability
100
License
Total Downloads
133,113,765
Last Day
205,466
Last Week
1,003,597
Last Month
3,217,712
Last Year
44,313,326
Minified
Minified + Gzipped
Latest Version
3.0.5
Package Id
react-resizable@3.0.5
Unpacked Size
113.65 kB
Size
29.46 kB
File Count
24
Publised On
21 Mar 2023
Cumulative downloads
Total Downloads
Last day
14.3%
205,466
Compared to previous day
Last week
14.3%
1,003,597
Compared to previous week
Last month
-21.8%
3,217,712
Compared to previous month
Last year
34.5%
44,313,326
Compared to previous year
2
1
28
A simple widget that can be resized via one or more handles.
You can either use the <Resizable>
element directly, or use the much simpler <ResizableBox>
element.
See the example and associated code in ExampleLayout and ResizableBox for more details.
Make sure you use the associated styles in /css/styles.css, as without them, you will have problems with handle placement and visibility.
You can pass options directly to the underlying DraggableCore
instance by using the prop draggableOpts
.
See the demo for more on this.
$ npm install --save react-resizable
React-Resizable 3.x is compatible with React >= 16.3
.
React-Resizable 2.x has been skipped.
React-Resizable 1.x is compatible with React 14-17
.
This package has two major exports:
<Resizable>
: A raw component that does not have state. Use as a building block for larger components, by listening to its
callbacks and setting its props.<ResizableBox>
: A simple <div {...props} />
element that manages basic state. Convenient for simple use-cases.<Resizable>
1const {Resizable} = require('react-resizable'); 2 3// ES6 4import { Resizable } from 'react-resizable'; 5 6// ... 7class Example extends React.Component { 8 state = { 9 width: 200, 10 height: 200, 11 }; 12 13 // On top layout 14 onResize = (event, {node, size, handle}) => { 15 this.setState({width: size.width, height: size.height}); 16 }; 17 18 render() { 19 return ( 20 <Resizable height={this.state.height} width={this.state.width} onResize={this.onResize}> 21 <div className="box" style={{width: this.state.width + 'px', height: this.state.height + 'px'}}> 22 <span>Contents</span> 23 </div> 24 </Resizable> 25 ); 26 } 27} 28
<ResizableBox>
1const {ResizableBox} = require('react-resizable'); 2 3// ES6 4import { ResizableBox } from 'react-resizable'; 5 6class Example extends React.Component { 7 render() { 8 return ( 9 <ResizableBox width={200} height={200} draggableOpts={{...}} 10 minConstraints={[100, 100]} maxConstraints={[300, 300]}> 11 <span>Contents</span> 12 </ResizableBox> 13 ); 14 } 15}
These props apply to both <Resizable>
and <ResizableBox>
. Unknown props that are not in the list below will be passed to the child component.
1type ResizeCallbackData = { 2 node: HTMLElement, 3 size: {width: number, height: number}, 4 handle: ResizeHandleAxis 5}; 6type ResizeHandleAxis = 's' | 'w' | 'e' | 'n' | 'sw' | 'nw' | 'se' | 'ne'; 7 8type ResizableProps = 9{ 10 children: React.Element<any>, 11 width: number, 12 height: number, 13 // Either a ReactElement to be used as handle, or a function returning an element that is fed the handle's location as its first argument. 14 handle: ReactElement<any> | (resizeHandle: ResizeHandleAxis, ref: ReactRef<HTMLElement>) => ReactElement<any>, 15 // If you change this, be sure to update your css 16 handleSize: [number, number] = [10, 10], 17 lockAspectRatio: boolean = false, 18 axis: 'both' | 'x' | 'y' | 'none' = 'both', 19 minConstraints: [number, number] = [10, 10], 20 maxConstraints: [number, number] = [Infinity, Infinity], 21 onResizeStop?: ?(e: SyntheticEvent, data: ResizeCallbackData) => any, 22 onResizeStart?: ?(e: SyntheticEvent, data: ResizeCallbackData) => any, 23 onResize?: ?(e: SyntheticEvent, data: ResizeCallbackData) => any, 24 draggableOpts?: ?Object, 25 resizeHandles?: ?Array<ResizeHandleAxis> = ['se'] 26};
The following props can also be used on <ResizableBox>
:
1{ 2 style?: Object // styles the returned <div /> 3}
If a width
or height
is passed to <ResizableBox>
's style
prop, it will be ignored as it is required for internal function.
If you override the resize handle, we expect that any ref
passed to your new handle with represent the underlying DOM element.
This is required, as react-resizable
must be able to access the underlying DOM node to attach handlers and measure position deltas.
There are a few ways to do this:
This requires no special treatment.
1<Resizable handle={<div className="foo" />} />
You must forward the ref and props to the underlying DOM element.
1class MyHandleComponent extends React.Component { 2 render() { 3 const {handleAxis, innerRef, ...props} = this.props; 4 return <div ref={innerRef} className={`foo handle-${handleAxis}`} {...props} /> 5 } 6} 7const MyHandle = React.forwardRef((props, ref) => <MyHandleComponent innerRef={ref} {...props} />); 8 9<Resizable handle={<MyHandle />} />
1const MyHandle = React.forwardRef((props, ref) => { 2 const {handleAxis, ...restProps} = props; 3 return <div ref={ref} className={`foo handle-${handleAxis}`} {...restProps} />; 4}); 5 6<Resizable handle={<MyHandle />} />
You can define a function as a handle, which will simply receive an axis (see above ResizeHandleAxis
type) and ref. This may be more clear to read, depending on your coding style.
1const MyHandle = (props) => { 2 return <div ref={props.innerRef} className="foo" {...props} />; 3}; 4 5<Resizable handle={(handleAxis, ref) => <MyHandle innerRef={ref} className={`foo handle-${handleAxis}`} {...props} />} />
No vulnerabilities found.
No security vulnerabilities found.