Home

Awesome

<p align="center"><img src ="https://github.com/bokuweb/react-sortable-pane/blob/master/logo.png?raw=true" /></p> <p align="center">Sortable and resizable pane component for react.</p> <p align="center"> <a href="https://circleci.com/gh/bokuweb/react-sortable-pane"> <img src="https://circleci.com/gh/bokuweb/react-sortable-pane/tree/master.svg?style=svg" alt="CircleCI" /></a> <a href="https://www.npmjs.com/package/react-sortable-pane"> <img src="https://img.shields.io/npm/v/react-sortable-pane.svg" alt="Build Status" /></a> <a href="https://www.npmjs.com/package/react-sortable-pane"> <img src="https://img.shields.io/npm/dm/react-sortable-pane.svg" /></a> <a href="https://renovatebot.com/"> <img src="https://img.shields.io/badge/renovate-enabled-brightgreen.svg" /></a> <a href="https://github.com/prettier/prettier"> <img src="https://img.shields.io/badge/styled_with-prettier-ff69b4.svg" /></a> </p>

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

PropsRequiredTypeDefaultDescription
classNamestringundefinedSpecify className of component.
styleReact.CssProperties{}Original style of component.
direction<code>'horizontal' | 'vertical'</code>horizontalThe direction is used to set the direction of a component.
orderstring[]undefinedThe order is used to control Pane order. If you need not to control Pane state, you can omit this property. (See also, controlled)
defaultOrderstring[]undefinedThe defaultOrder is used to set default Pane order. If you need to control Pane state, please use order property. (See also, uncontrolled)
marginnumber0The margin is used to set the margin between Pane component.
isSortablebooleantrueThe isSortable is used to control whether panes can be dragged or not.
disableEffectbooleanfalseThe disableEffect is used to disable floating effect.
dragHandleClassNamestringundefinedThe dragHandleClassName is a class name of an element which should handle drag events for panes.
onOrderChange(order: string[]) => voidundefinedIt is called when Pane component order changed. The argument order is array of react element's key.
onResizeStart<code>(e: React.MouseEvent | React.TouchEvent, key: string, dir: PaneResizeDirection) => void</code>undefinedIt is called when Pane component resize start.
onResize<code>(e: MouseEvent | TouchEvent, key: string, dir: PaneResizeDirection, elementRef: HTMLElement, delta: PaneSize) => void</code>undefinedIt is called when Pane component resize.
onResizeStop<code>(e: MouseEvent | TouchEvent, key: string, dir: PaneResizeDirection, elementRef: HTMLElement, delta: PaneSize) => void</code>undefinedIt is called when Pane component resize stop.
onDragStart<code>(e: React.MouseEvent<HTMLElement> | React.TouchEvent<HTMLElement>, key: string, elementRef: HTMLElement) => void</code>undefinedIt is called when Pane component dragging starts.
onDragStop<code>(e: MouseEvent | TouchEvent, key: PaneKey, elementRef: HTMLElement, order: string[]) => void</code>undefinedIt is called when Pane component dragging stop.

PaneComponent

PropsRequiredTypeDefaultDescription
classNamestringundefinedSpecify className of component.
styleReact.CssProperties{}Original style of component.
defaultSize<code>{ width?: (number | string), height?: (number | string) }</code>autoSpecifies the width and height that the dragged item should start at. For example, you can set 300, '300px', 50%.
size<code>{ width?: (number | string), height?: (number | string) }</code>autoThe size property is used to set the size of the component. For example, you can set 300, '300px', '50%'.
minWidth<code>number | string</code>10pxThe minWidth is used to set the minimum width of a Pane component.
minHeight<code>number | string</code>10pxThe minHeight is used to set the minimum height of a Pane component.
maxWidth<code>number | string</code>undefinedThe maxWidth is used to set the maximum width of a Pane component.
maxHeight<code>number | string</code>undefinedThe 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

V1.0.1

V1.0.0

V1.0.0-beta.2

V1.0.0-beta.1

V1.0.0-beta.0

V0.8.2

V0.8.1

V0.8.0

V0.7.1

V0.7.0

V0.6.8

V0.6.7

V0.6.6

V0.6.5

V0.6.4

V0.6.2

V0.5.5

V0.5.4

V0.5.3

V0.5.2

V0.5.1

V0.5.0

V0.4.1

V0.4.0

V0.3.2

V0.3.1

V0.3.0

V0.2.12

V0.2.10, V0.2.11

V0.2.8

V0.2.7

V0.2.6

V0.2.5

V0.2.4

V0.2.3

V0.2.2

V0.2.1

V0.2.0

V0.1.2

V0.1.1

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.