• Stars
    star
    635
  • Rank 70,829 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 9 years ago
  • Updated over 1 year ago

Reviews

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

Repository Details

✨ A sortable and resizable pane component for React.

Sortable and resizable pane component for react.

CircleCI Build Status

Table of Contents

Screenshot

screenshot

Live Demo

Storybook

Storybook

CodeSandbox

CodeSandbox(Uncontrolled)

Install

npm i react-sortable-pane

or

yarn add react-sortable-pane

Usage

Uncontrolled

If you need not to control SortablePane state, please use defaultSize and defaultOrder.

import * as React from 'react';
import { SortablePane, Pane } from 'react-sortable-pane';

export default function SimpleUncontrolledExample() {
  const panes = [0, 1, 2].map(key => (
    <Pane key={key} defaultSize={{ width: '100%', height: 120 }}>
      00{key}
    </Pane>
  ));
  return (
    <div>
      <SortablePane direction="vertical" margin={20} defaultOrder={['0', '1', '2']}>
        {panes}
      </SortablePane>
    </div>
  );
}

Controlled

If you need to control SortablePanestate by yourself, please use size and order.

import * as React from 'react';
import { SortablePane, Pane } from 'react-sortable-pane';

type State = {
  order: string[];
  panes: { [key: string]: { height: number } };
};

export default class SimpleControlledFullExample extends React.Component<{}, State> {
  state = {
    order: ['2', '1', '0'],
    panes: { '0': { height: 100 }, '1': { height: 200 }, '2': { height: 300 } },
  };

  render() {
    const panes = [0, 1, 2].map(key => (
      <Pane key={key} size={{ width: '100%', height: this.state.panes[key].height }}>
        00{key}
      </Pane>
    ));
    return (
      <div>
        <SortablePane
          direction="vertical"
          margin={20}
          order={this.state.order}
          onOrderChange={order => {
            this.setState({ order });
          }}
          onResizeStop={(e, key, dir, ref, d) => {
            this.setState({
              panes: { ...this.state.panes, [key]: { height: this.state.panes[key].height + d.height } },
            });
          }}
        >
          {panes}
        </SortablePane>
      </div>
    );
  }
}

Props

SortablePaneComponent

Props Required Type Default Description
className string undefined Specify className of component.
style React.CssProperties {} Original style of component.
direction 'horizontal' | 'vertical' horizontal The direction is used to set the direction of a component.
order string[] undefined The order is used to control Pane order. If you need not to control Pane state, you can omit this property. (See also, controlled)
defaultOrder string[] undefined The defaultOrder is used to set default Pane order. If you need to control Pane state, please use order property. (See also, uncontrolled)
margin number 0 The margin is used to set the margin between Pane component.
isSortable boolean true The isSortable is used to control whether panes can be dragged or not.
disableEffect boolean false The disableEffect is used to disable floating effect.
dragHandleClassName string undefined The dragHandleClassName is a class name of an element which should handle drag events for panes.
onOrderChange (order: string[]) => void undefined It is called when Pane component order changed. The argument order is array of react element's key.
onResizeStart (e: React.MouseEvent | React.TouchEvent, key: string, dir: PaneResizeDirection) => void undefined It is called when Pane component resize start.
onResize (e: MouseEvent | TouchEvent, key: string, dir: PaneResizeDirection, elementRef: HTMLElement, delta: PaneSize) => void undefined It is called when Pane component resize.
onResizeStop (e: MouseEvent | TouchEvent, key: string, dir: PaneResizeDirection, elementRef: HTMLElement, delta: PaneSize) => void undefined It is called when Pane component resize stop.
onDragStart (e: React.MouseEvent | React.TouchEvent, key: string, elementRef: HTMLElement) => void undefined It is called when Pane component dragging starts.
onDragStop (e: MouseEvent | TouchEvent, key: PaneKey, elementRef: HTMLElement, order: string[]) => void undefined It is called when Pane component dragging stop.

PaneComponent

Props Required Type Default Description
className string undefined Specify className of component.
style React.CssProperties {} Original style of component.
defaultSize { width?: (number | string), height?: (number | string) } auto Specifies the width and height that the dragged item should start at. For example, you can set 300, '300px', 50%.
size { width?: (number | string), height?: (number | string) } auto The size property is used to set the size of the component. For example, you can set 300, '300px', '50%'.
minWidth number | string 10px The minWidth is used to set the minimum width of a Pane component.
minHeight number | string 10px The minHeight is used to set the minimum height of a Pane component.
maxWidth number | string undefined The maxWidth is used to set the maximum width of a Pane component.
maxHeight number | string undefined The maxHeight is used to set the maximum height of a Pane component.
grid [number, number] [1, 1] The maxHeight is used to set the maximum height of a Pane component.
resizable { x: boolean, y: boolean, xy: boolean } { x: true, y: true, xy: true } The resizable is used to set the resizable permission of a component.

Changelog

V1.0.2

  • fix: Fixed a bug, order offset calculation doesn't work properly #203

V1.0.1

  • fix: Add flowtype definition.

V1.0.0

  • chore: Update deps.

V1.0.0-beta.2

  • fix: fixed a min / max size types.

V1.0.0-beta.1

  • fix: fixed a TouchEvent error in IE11.

V1.0.0-beta.0

  • feat: Use TypeScript instead of flowtype.
  • feat: Add defaultSize, defaultOrder, order, size props to control(or uncontrol) SortablePane state.
  • fix: Some tiny bugs.
  • chore: Add some stories.

V0.8.2

  • chore: update deps.

V0.8.1

  • fix: add hysteresis and fix sort position
  • fix: add mouseleave to panes node

V0.8.0

  • fix: remove unused order property.
  • fix: fix position when parent element resized.
  • chore: update deps.

V0.7.1

  • fix: sort, Drag, Resize does not work in Safari #128

V0.7.0

  • chore: update deps (use re-resizable instead of react-resizable-box)

V0.6.8

  • Feature: Add grid props.

V0.6.7

  • Chore: Upgrade dependencies.

V0.6.6

  • Add grid props. (#93)

V0.6.5

  • Update README.

V0.6.4

  • Fix Bug, onResizeStart and onResizeStop not fired.

V0.6.2

  • Use flowtype
  • Use rollup
  • Change callback I/F

V0.5.5

  • Use prop-types package.
  • Fix #56 thanks @avaskys.

V0.5.4

  • Support server side rendering. #50 thanks @lazreg87

V0.5.3

  • Fix componentDidUpdate argument, use this.props instaead of prev.

V0.5.2

  • Use babel-preset-es2015-ie babel-preset-es2015-ie #47 thanks @PabloDiablo

V0.5.1

  • update readme

V0.5.0

  • Fixes a nasty bug
  • Add isResizable props to Pane component
  • Set user-select: none when resizeing or moving.
  • Add zIndex props.
  • update example

V0.4.1

  • Fixes a nasty bug where all Panes could end up sharing the same static style #44 (thanks @ara4n)

V0.4.0

  • Add Object.assign transform plugin
  • Add add-module-exports plugin

V0.3.2

  • Allow strings for width and height. (thanks @lanVS)
  • Add onDragStart and onDragEnd props. (thanks @lanVS)

V0.3.1

  • Add isSortable props. (#34 thanks @lanVS)

V0.3.0

  • Change sort trigger position (#40 thanks @lanVS)

V0.2.12

  • Update react-motion(use "^0.4.3")

V0.2.10, V0.2.11

  • Fix order update bug

V0.2.8

  • Fix size updater bug

V0.2.7

  • Fix size updater bug

V0.2.6

  • Fix order bug
  • Update react-resizable-box(^1.2.0)

V0.2.5

  • Add order props to change order by parent component.
  • Add husky and pre push hook.

V0.2.4

  • update packages to support react v15

V0.2.3

  • update pane size when props.width/height updated.

V0.2.2

  • Fix className bug.

V0.2.1

  • Update resizable box component.

V0.2.0

  • Support pane append and remove.
  • Support vertical mode.
  • Fix pane size calculator.

V0.1.2

  • Add onOrderChange callback.
  • Add disableEffect props.
  • Fix eslint error.

V0.1.1

  • Add onResize callback.

V0.1.0

publised.

License

The MIT License (MIT)

Copyright (c) 2018 @bokuweb

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

react-rnd

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

re-resizable

📏 A resizable component for React.
TypeScript
2,166
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