• Stars
    star
    2,166
  • Rank 21,290 (Top 0.5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

📏 A resizable component for React.

📏 A resizable component for React.

Build Status Build Status

Table of Contents

Screenshot

screenshot

Live Demo

Storybook

Storybook

CodeSandbox

Edit xp9p7272m4
CodeSandbox
CodeSandbox(TypeScript)
CodeSandbox(With hooks)

Install

$ npm install --save re-resizable

Usage

Example with defaultSize

import { Resizable } from 're-resizable';

<Resizable
  defaultSize={{
    width: 320,
    height: 200,
  }}
>
  Sample with default size
</Resizable>

Example with size

If you use size props, please manage state by yourself.

import { Resizable } from 're-resizable';

<Resizable
  size={{ width: this.state.width, height: this.state.height }}
  onResizeStop={(e, direction, ref, d) => {
    this.setState({
      width: this.state.width + d.width,
      height: this.state.height + d.height,
    });
  }}
>
  Sample with size
</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 | string;

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.

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;

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.

type ResizeStartCallback = (
  e: SyntheticMouseEvent<HTMLDivElement> | SyntheticTouchEvent<HTMLDivElement>,
  dir: ResizableDirection,
  refToElement: HTMLDivElement,
) => 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.

type ResizeCallback = (
  event: MouseEvent | TouchEvent,
  direction: ResizableDirection,
  refToElement: HTMLDivElement,
  delta: NumberSize,
) => void;

Calls when resizable component resizing.

onResizeStop?: ResizeCallback;

ResizeCallback type is below.

type ResizeCallback = (
  event: MouseEvent | TouchEvent,
  direction: ResizableDirection,
  refToElement: HTMLDivElement,
  delta: NumberSize,
) => 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
class YourComponent extends Component {

  // ...

  update() {
    this.resizable.updateSize({ width: 200, height: 300 });
  }

  render() {
    return (
      <Resizable ref={c => { this.resizable = c; }}>
        example
      </Resizable>
    );
  }

  // ...
}

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

npm test

Related

More Repositories

1

react-rnd

🖱 A resizable and draggable component for React.
TypeScript
3,417
star
2

react-sortable-pane

✨ A sortable and resizable pane component for React.
TypeScript
635
star
3

rustynes

👾 An NES emulator by Rust and WebAssembly
Rust
473
star
4

re-bulma

[Deprecated] 💎Bulma components for React
JavaScript
364
star
5

docx-rs

📝 A .docx file writer with Rust/WebAssembly.
Rust
335
star
6

gopher-boy

🎮 A Game Boy emulator written in Go
Go
244
star
7

flownes

🎮 An NES emulator written in ES2015+ with flowtype
JavaScript
170
star
8

zstd-wasm

Zstandard for browser, Node.js and Deno
TypeScript
108
star
9

r2

A RISC-V emulator written in Rust 🦀
Rust
100
star
10

lcs-image-diff-rs

🖼 Image diff tool with LCS algorithm
Rust
83
star
11

slack-list-ja

📋 A handpicked selection of top Slack communities in japan
CSS
78
star
12

Tsukiakari

【WIP】Twitter Client built on Electron.
JavaScript
64
star
13

lifegameboy

🦀 Conway's Game of Life written in Rust on GameBoyAdvance
Rust
54
star
14

yaw

🦀 A wasm interpreter in Rust
Rust
53
star
15

karma-nightmare

⚡ A Karma plugin. Launcher for Nightmare
JavaScript
52
star
16

slate-editable-table

🖊️ An editable table plugin for Slate.js
TypeScript
44
star
17

rust-wasm-game-of-life

👾 Conway's Game of Life written by Rust with WebAssembly
Rust
41
star
18

tuna_pasta

[Deprecated] Hatena Bookmark Viwer, build with React/Redux, focused on keyword.
JavaScript
38
star
19

bmsjs

browser bms player project.
CoffeeScript
35
star
20

ithildin

Twitter Client built on Electron with Mithril.js
CoffeeScript
28
star
21

deno-pretty-assert

🦕A colorful assertEqual for deno
TypeScript
26
star
22

avaron

🚀 AVA + Electron :electron: = Avaron
JavaScript
22
star
23

react-tutorial-with-redux

react tutorial with redux
JavaScript
21
star
24

github-image-diff

🚧 [Deprecated] :octocat: A chrome extension to check github image difference.
JavaScript
19
star
25

nes-sprites2png

👾 convert nes sprites to png
JavaScript
18
star
26

wu-diff-js

Compute differences between two slices using wu(the O(NP)) algorithm.
TypeScript
17
star
27

node-lcs-img-diff

🖼 Image diff tool with LCS algorithm for Node.js
Rust
14
star
28

react-native-universal-modal

Universal simple modal component for React Native
JavaScript
14
star
29

vscode-git-grep

Git grep extension for Visual Studio Code
TypeScript
13
star
30

rxjs-tetris

DOM based rxjs tetris
TypeScript
13
star
31

image-diff-rs

This project provides an image differencing library that supports PNG,JPEG,GIF,TIFF,and WebP formats for Node.js, Deno, and Rust.
JavaScript
13
star
32

app.flavabeats

browser music game for PC
JavaScript
12
star
33

json-schema-to-flowtype-cli

JSON Schema to flowtype cli.
JavaScript
11
star
34

zig-os-in-1000-lines

Zig
10
star
35

pixelmatch-rs

port of mapbox/pixelmatch
JavaScript
9
star
36

react-resizable-decorator

[Deprecated] Resizable decorator for React component.
JavaScript
9
star
37

vscode-ripgrep

A ripgrep extension for Visual Studio Code
TypeScript
9
star
38

react-blog-sample

Blog system sample on Node.js, Express.js, MongoDB and React.js
CoffeeScript
8
star
39

r2v

[WIP] 🦀 A RISC-V emulator written in Rust
Rust
8
star
40

react-elastic-modal

React elastic modal component.
JavaScript
7
star
41

youtube_music_game

yotube game sample
JavaScript
6
star
42

rxjs-lifegame

TypeScript
6
star
43

go-lifegame

Go
4
star
44

tomato_pasta

JavaScript
4
star
45

wu-diff-rs

Compute differences between two slices using wu(the O(NP)) algorithm.
Rust
4
star
46

react-draggable-custom

[deprecated]
JavaScript
4
star
47

armv4-emu-rs

🚧 [WIP] An ARMv4 emulator by Rust.
Rust
3
star
48

lcs-diff-rs

📃 Compute differences between two slices using LCS algorithm.
Rust
3
star
49

bounddoc

TypeScript
3
star
50

flava_cocos

cocos2d-JS music game
CoffeeScript
3
star
51

wasm-cv-with-laughing-man

😃 wasm + opencv + facedetect sample
JavaScript
3
star
52

wasi-threads-sandbox

WebAssembly
3
star
53

kanten_old

Rust
2
star
54

elixir_scraping_sample

Elixir
2
star
55

phoenix-redux-blog

WIP
Elixir
2
star
56

ng-resizable

TypeScript
1
star
57

kebab2camel

Transform camel case to kebab case
JavaScript
1
star
58

specterio

JavaScript
1
star
59

pixi-sandbox

pixi.js sandbox
JavaScript
1
star
60

use-resizable-table

TypeScript
1
star
61

c3

c3.jsを使用し、setTimerIntervalでチャートを描画するサンプル。
JavaScript
1
star
62

cv-wasm-face-detect-sample

JavaScript
1
star
63

raect-tutorial-with-redux-and-flowtype

JavaScript
1
star
64

node-go-with-browser

Dockerfile
1
star
65

wasip1-threads-rayon-example

JavaScript
1
star
66

rust-wasm-png-decoder-example

png decoder example by wasm32-unknown-unnkown.
JavaScript
1
star
67

planter

My plants
JavaScript
1
star
68

liquidfun_test

liquidfun_test
JavaScript
1
star
69

wasm-pixelmatch

JavaScript
1
star
70

react-sortable-column-sandbox

JavaScript
1
star
71

bmsjs-react

Browser BMS player project powered by React
JavaScript
1
star
72

chrome_serial_sample

chrome.serial API sample
CoffeeScript
1
star
73

cocos2d-JS_skeleton

cocos2d-JS v3.5+ skeleton
CoffeeScript
1
star
74

bms-gamepad-example

JavaScript
1
star
75

flava_sample

スマホブラウザで遊べる音ゲーサンプル
CoffeeScript
1
star
76

react-avaron-sample

React + Avaron sample
JavaScript
1
star
77

git-test

JavaScript
1
star
78

logue

1
star
79

cv-wasm

1
star