Giter Club home page Giter Club logo

react-multi-split-pane's Introduction

React Multi Split Pane

NPM version NPM license

Fork of react-split-pane with support for more than two panes.

Installing

npm install react-multi-split-pane

# or if you use yarn

yarn add react-multi-split-pane

Example Usage

<SplitPane split="vertical" minSize={50}>
    <div></div>
    <div></div>
    <div></div>
</SplitPane>
<SplitPane split="vertical" minSize={50}>
    <div></div>
    <SplitPane split="horizontal">
        <div></div>
        <div></div>
    </SplitPane>
</SplitPane>

Differences from react-split-pane

Much of the code has been rewritten, so the feature set is a bit different. All code has been converted to TypeScript.

The most important changes:

  • All pane sizes are relative, so when the window is resized, all panes grow/shrink at the same time (as far as their minSize properties allow)
  • An array of all pane sizes is passed to the onDragFinished and onChange callbacks

Props

split: 'vertical' | 'horizontal'

Split direction, defaults to vertical.

defaultSizes: number[]

Array of (relative) default sizes for the individual panes. Missing values default to 1. When no defaultSizes are passed, all sizes default to 1, equally distributing the available space (as far as minSize values permit).

minSize: number | number[]

Minimum size of all panes (in pixels), or array containing individual minimum sizes for each pane. Defaults to 50.

className: string

Additional CSS class name that is appied to all elements rendered by the SplitPane. For a class name custom, the individual elements can be selected as .SplitPane.custom, .Resizer.custom, and .Pane.custom.

resizerClassName: string

Additional CSS class name that is appied only to the resizer rendered by the SplitPane.

onDragStarted: () => void

This callback is invoked when a drag starts.

onDragFinished: (sizes: number[]) => void

This callback is invoked when a drag ends.

onChange: (sizes: number[]) => void

This callback is invoked with the current drag during a drag event. It is recommended that it is wrapped in a debounce function.

Persisting Positions

Each SplitPane accepts an onChange function prop. Used in conjunction with defaultSize and a persistence layer, you can ensure that your splitter choices survive a refresh of your app.

For example, if you are comfortable with the trade-offs of localStorage, you could do something like the following:

<SplitPane
    split="vertical" minSize={50}
    defaultSizes={JSON.parse(localStorage.getItem('splitPos')) || undefined}
    onDragFinished={(size) => localStorage.setItem('splitPos', JSON.stringify(size))}
>
    <div></div>
    <div></div>
</SplitPane>

Example styling

This gives a single pixel wide divider, but with a 'grabbable' surface of 11 pixels.

Thanks to background-clip: padding-box; for making transparent borders possible.

.Resizer {
    background: #000;
    opacity: .2;
    z-index: 1;
    box-sizing: border-box;
    background-clip: padding-box;
}

.Resizer:hover {
    transition: all 2s ease;
}

.Resizer.horizontal {
    height: 11px;
    margin: -5px 0;
    border-top: 5px solid rgba(255, 255, 255, 0);
    border-bottom: 5px solid rgba(255, 255, 255, 0);
    cursor: row-resize;
}

.Resizer.horizontal:hover, .Resizer.horizontal.resizing {
    border-top: 5px solid rgba(0, 0, 0, 0.5);
    border-bottom: 5px solid rgba(0, 0, 0, 0.5);
}

.Resizer.vertical {
    width: 11px;
    margin: 0 -5px;
    border-left: 5px solid rgba(255, 255, 255, 0);
    border-right: 5px solid rgba(255, 255, 255, 0);
    cursor: col-resize;
}

.Resizer.vertical:hover, .Resizer.vertical.resizing {
    border-left: 5px solid rgba(0, 0, 0, 0.5);
    border-right: 5px solid rgba(0, 0, 0, 0.5);
}

.DragLayer {
	z-index: 1;
	pointer-events: none;
}

.DragLayer.resizing {
	pointer-events: auto;
}

.DragLayer.horizontal {
	cursor: row-resize;
}

.DragLayer.vertical {
	cursor: col-resize;
}

react-multi-split-pane's People

Contributors

adidahiya avatar aimed avatar aktenkundig avatar ansont avatar asutherland avatar chrisbolin avatar craga89 avatar davvidbaker avatar dmigo avatar greenkeeperio-bot avatar ianvs avatar jirokun avatar jlmakes avatar joeflateau avatar kabudahab avatar keegan-lillo avatar kierson avatar lgeiger avatar littlemaneuver avatar meowtimer avatar michaeldeboey avatar neocturne avatar njlr avatar owenconti avatar robertf224 avatar timrobbings avatar tomkp avatar vlad-nica avatar wuweiweiwu avatar zerkms avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-multi-split-pane's Issues

Missing allowResize prop

I know this is based on the react-split-panes which is great. But this one is missing a key feature allowResize=false

The workaround I'm guessing would be stopping the event onDragStart, but the resizer would it still be there, which will make us forced to use conditional styling.

Also if possible to include percentage size as well, as the workaround now it to manually calculate it based on the window width/height

Set react and react-dom as peerDependencies instead of dependencies

Is your feature request related to a problem? Please describe.

The current version introduces react and react-dom as a dependency. Would be great to set them as peerDependencies in the same way of react-split-pane does.

Describe the solution you'd like

I tried to submit a PR but didn't have access. Essentially change package.json from

	"dependencies": {
		"react": "^16.13.1",
		"react-dom": "^16.13.1"
	},

to

	"peerDependencies": {
		"react": "^16.13.1",
		"react-dom": "^16.13.1"
	},

Additional context

Thanks a lot for the work so far in the module! : )

Add react 18 to peerDependencies

Is your feature request related to a problem? Please describe.

The current version do not include react 18 in peer dependency. Would be grate to see them added

Describe the solution you'd like

change peerDependencies from

"peerDependencies": {
	"react": "^16.14.0 || ^17.0.1",
	"react-dom": "^16.14.0 || ^17.0.1"
},

to

"peerDependencies": {
	"react": "^16.14.0 || ^17.0.1 || ^18.0.0",
	"react-dom": "^16.14.0 || ^17.0.1 || ^18.0.0"
},

Additional context

Thanks a lot for this module, it is really great! : )

when using this package in a react app typescript based, while build getting compiled with warning 'Failed to parse source map'

Describe the bug:

while react build getting compiled with warning 'Failed to parse source map' here are the full compiler and warnings :

Failed to parse source map from 'D:\POC\my-app5\node_modules\react-multi-split-pane\src\index.ts' file: Error: ENOENT: no such file or directory, open 'D:\POC\my-app5\node_modules\react-multi-split-pane\src\index.ts'

Failed to parse source map from 'D:\POC\my-app5\node_modules\react-multi-split-pane\src\lib\Pane.tsx' file: Error: ENOENT: no such file or directory, open 'D:\POC\my-app5\node_modules\react-multi-split-pane\src\lib\Pane.tsx'

Failed to parse source map from 'D:\POC\my-app5\node_modules\react-multi-split-pane\src\lib\Resizer.tsx' file: Error: ENOENT: no such file or directory, open 'D:\POC\my-app5\node_modules\react-multi-split-pane\src\lib\Resizer.tsx'

Failed to parse source map from 'D:\POC\my-app5\node_modules\react-multi-split-pane\src\lib\SplitPane.tsx' file: Error: ENOENT: no such file or directory, open 'D:\POC\my-app5\node_modules\react-multi-split-pane\src\lib\SplitPane.tsx'

Failed to parse source map from 'D:\POC\my-app5\node_modules\react-multi-split-pane\src\lib\util.ts' file: Error: ENOENT: no such file or directory, open 'D:\POC\my-app5\node_modules\react-multi-split-pane\src\lib\util.ts'

Steps to reproduce the behavior:

After installing package; we are getting this warning at build phase,

npm start
or
npm run build

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.