Installations
npm install creep-re-resizable
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
20.9.0
NPM Version
10.2.3
Score
70.5
Supply Chain
93.8
Quality
76.2
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (95.5%)
JavaScript (3.31%)
HTML (0.55%)
Shell (0.51%)
CSS (0.13%)
Developer
Download Statistics
Total Downloads
1,089
Last Day
1
Last Week
9
Last Month
11
Last Year
492
GitHub Statistics
1 Stars
1,032 Commits
1 Branches
1 Contributors
Bundle Size
16.44 kB
Minified
4.75 kB
Minified + Gzipped
Package Meta Information
Latest Version
2.3.0
Package Id
creep-re-resizable@2.3.0
Unpacked Size
96.74 kB
Size
22.43 kB
File Count
9
NPM Version
10.2.3
Node Version
20.9.0
Publised On
26 Apr 2024
Total Downloads
Cumulative downloads
Total Downloads
1,089
Last day
0%
1
Compared to previous day
Last week
0%
9
Compared to previous week
Last month
175%
11
Compared to previous month
Last year
-17.6%
492
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
48
📏 A resizable component for React.
Table of Contents
Screenshot
Live Demo
Storybook
CodeSandbox
CodeSandbox
CodeSandbox(TypeScript)
CodeSandbox(With hooks)
Install
1$ npm install --save re-resizable
Usage
Example with defaultSize
1import { Resizable } from 're-resizable'; 2 3<Resizable 4 defaultSize={{ 5 width: 320, 6 height: 200, 7 }} 8> 9 Sample with default size 10</Resizable>
If you only want to set the width, you can do so by providing just the width property. The height property will automatically be set to auto, which means it will adjust 100% of its parent's height:
1import { Resizable } from 're-resizable'; 2 3<Resizable 4 defaultSize={{ 5 width: 320 6 }} 7> 8 Sample with default size 9</Resizable>
Example with size
If you use size
props, please manage state by yourself.
1import { Resizable } from 're-resizable'; 2 3<Resizable 4 size={{ width: this.state.width, height: this.state.height }} 5 onResizeStop={(e, direction, ref, d) => { 6 this.setState({ 7 width: this.state.width + d.width, 8 height: this.state.height + d.height, 9 }); 10 }} 11> 12 Sample with size 13</Resizable>
Props
defaultSize?: { width?: (number | string), height?: (number | string) };
Specifies the width
and height
that the dragged item should start at.
For example, you can set 300
, '300px'
, 50%
.
If both defaultSize
and size
omitted, set 'auto'
.
defaultSize
will be ignored when size
set.
size?: { width?: (number | string), height?: (number | string) };
The size
property is used to set the size of the component.
For example, you can set 300
, '300px'
, 50%
.
Use size
if you need to control size state by yourself.
className?: string;
The className
property is used to set the custom className
of a resizable component.
style?: { [key: string]: string };
The style
property is used to set the custom style
of a resizable component.
minWidth?: number | string;
The minWidth
property is used to set the minimum width of a resizable component. Defaults to 10px.
It accepts viewport as well as parent relative units. For example, you can set 300
, 50%
, 50vw
or 50vh
.
Same type of values can be applied to minHeight
, maxWidth
and maxHeight
.
minHeight?: number | string;
The minHeight
property is used to set the minimum height of a resizable component. Defaults to 10px.
maxWidth?: number | string;
The maxWidth
property is used to set the maximum width of a resizable component.
maxHeight?: number | string
;
The maxHeight
property is used to set the maximum height of a resizable component.
grid?: [number, number];
The grid
property is used to specify the increments that resizing should snap to. Defaults to [1, 1]
.
snap?: { x?: Array<number>, y?: Array<number> };
The snap
property is used to specify absolute pixel values that resizing should snap to. x
and y
are both optional, allowing you to only include the axis you want to define. Defaults to null
.
snapGap?: number
The snapGap
property is used to specify the minimum gap required in order to move to the next snapping target. Defaults to 0
which means that snap targets are always used.
resizeRatio?: number | [number, number];
The resizeRatio
property is used to set the number of pixels the resizable component scales by compared to the number of pixels the mouse/touch moves. Defaults to 1
(for a 1:1 ratio). The number set is the left side of the ratio, 2
will give a 2:1 ratio.
For [number, number] means [resizeRatioX, resizeRatioY], more precise control.
lockAspectRatio?: boolean | number;
The lockAspectRatio
property is used to lock aspect ratio.
Set to true
to lock the aspect ratio based on the initial size.
Set to a numeric value to lock a specific aspect ratio (such as 16/9
).
If set to numeric, make sure to set initial height/width to values with correct aspect ratio.
If omitted, set false
.
lockAspectRatioExtraWidth?: number;
The lockAspectRatioExtraWidth
property enables a resizable component to maintain an aspect ratio plus extra width.
For instance, a video could be displayed 16:9 with a 50px side bar.
If omitted, set 0
.
lockAspectRatioExtraHeight?: number;
The lockAspectRatioExtraHeight
property enables a resizable component to maintain an aspect ratio plus extra height.
For instance, a video could be displayed 16:9 with a 50px header bar.
If omitted, set 0
.
bounds?: ('window' | 'parent' | HTMLElement);
Specifies resize boundaries.
boundsByDirection?: boolean;
By default max dimensions based on left and top element position.
Width grow to right side, height grow to bottom side.
Set true
for detect max dimensions by direction.
For example: enable boundsByDirection
when resizable component stick on right side of screen and you want resize by left handler;
false
by default.
handleStyles?: HandleStyles;
The handleStyles
property is used to override the style of one or more resize handles.
Only the axis you specify will have its handle style replaced.
If you specify a value for right
it will completely replace the styles for the right
resize handle,
but other handle will still use the default styles.
handleClasses?: HandleClassName;
The handleClasses
property is used to set the className of one or more resize handles.
handleComponent?: HandleComponent;
The handleComponent
property is used to pass a React Component to be rendered as one or more resize handle. For example, this could be used to use an arrow icon as a handle..
handleWrapperStyle?: { [key: string]: string };
The handleWrapperStyle
property is used to override the style of resize handles wrapper.
handleWrapperClass?: string;
The handleWrapperClass
property is used to override the className of resize handles wrapper.
enable?: ?Enable | false;
The enable
property is used to set the resizable permission of a resizable component.
The permission of top
, right
, bottom
, left
, topRight
, bottomRight
, bottomLeft
, topLeft
direction resizing.
If omitted, all resizer are enabled.
If you want to permit only right direction resizing, set { top:false, right:true, bottom:false, left:false, topRight:false, bottomRight:false, bottomLeft:false, topLeft:false }
.
onResizeStart?: ResizeStartCallBack;
ResizeStartCallBack
type is below.
1type ResizeStartCallback = ( 2 e: SyntheticMouseEvent<HTMLDivElement> | SyntheticTouchEvent<HTMLDivElement>, 3 dir: ResizableDirection, 4 refToElement: HTMLDivElement, 5) => void;
Calls when resizable component resize start.
onResize?: ResizeCallback;
scale?: number
;
The scale
property is used in the scenario where the resizable element is a descendent of an element using css scaling (e.g. - transform: scale(0.5)
).
as?: string | React.ComponentType
;
By default the Resizable
component will render a div
as a wrapper. The as
property is used to change the element used.
Basic
ResizeCallback
type is below.
1type ResizeCallback = ( 2 event: MouseEvent | TouchEvent, 3 direction: ResizableDirection, 4 refToElement: HTMLDivElement, 5 delta: NumberSize, 6) => void;
Calls when resizable component resizing.
onResizeStop?: ResizeCallback;
ResizeCallback
type is below.
1type ResizeCallback = ( 2 event: MouseEvent | TouchEvent, 3 direction: ResizableDirection, 4 refToElement: HTMLDivElement, 5 delta: NumberSize, 6) => void;
Calls when resizable component resize stop.
Instance API
* updateSize(size: { width: number | string, height: number | string }): void
Update component size.
grid
, snap
, max/minWidth
, max/minHeight
props is ignored, when this method called.
- for example
1class YourComponent extends Component { 2 3 // ... 4 5 update() { 6 this.resizable.updateSize({ width: 200, height: 300 }); 7 } 8 9 render() { 10 return ( 11 <Resizable ref={c => { this.resizable = c; }}> 12 example 13 </Resizable> 14 ); 15 } 16 17 // ... 18}
Contribute
If you have a feature request, please add it as an issue or make a pull request.
If you have a bug to report, please reproduce the bug in CodeSandbox to help us easily isolate it.
Test
1npm test
Related
No vulnerabilities found.
No security vulnerabilities found.