Catalog npm
Back to packageRELEASE DETAILS

2.0.4

npm

@0kzh/react-split-pane

React split-pane component

es6reactreact-componentreact-split-panesplit-pane
Published6 Nov 2023
Direct dependencies31
Transitive dependenciesNot calculated

README

Current package documentation

React Split Pane

Split-Pane component built with React, can be split vertically or horizontally.

npm install react-split-pane

Build Status Coverage Status

Check out the demos

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

Primary pane

By dragging 'draggable' surface you can change size of the first pane. The first pane keeps then its size while the second pane is resized by browser window. By default it is the left pane for 'vertical' SplitPane and the top pane for 'horizontal' SplitPane. If you want to keep size of the second pane and let the first pane to shrink or grow by browser window dimensions, set SplitPane prop primary to second. In case of 'horizontal' SplitPane the height of bottom pane remains the same.

Resizing can be disabled by passing the allowResize prop as false (allowResize={false}). Resizing is enabled by default.

You can also set the size of the pane using the size prop. Note that a size set through props ignores the defaultSize and minSize properties.

In this example right pane keeps its width 200px while user is resizing browser window.

    <SplitPane split="vertical" defaultSize={200} primary="second">
        <div></div>
        <div></div>
    </SplitPane>

maxSize

You can limit the maximal size of the 'fixed' pane using the maxSize parameter with a positive value (measured in pixels but state just a number). If you wrap the SplitPane into a container component (yes you can, just remember the container has to have the relative or absolute positioning), then you'll need to limit the movement of the splitter (resizer) at the end of the SplitPane (otherwise it can be dragged outside the SplitPane and you don't catch it never more). For this purpose use the maxSize parameter with value 0. When dragged the splitter/resizer will stop at the border of the SplitPane component and think this you'll be able to pick it again and drag it back then. And more: if you set the maxSize to negative value (e.g. -200), then the splitter stops 200px before the border (in other words it sets the minimal size of the 'resizable' pane in this case). This can be useful also in the full-screen case of use.

step

You can use the step prop to only allow resizing in fixed increments.

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}
               defaultSize={ parseInt(localStorage.getItem('splitPos'), 10) }
               onChange={ size => localStorage.setItem('splitPos', size) }>
        <div></div>
        <div></div>
    </SplitPane>

Disclaimer: localStorage has a variety of performance trade-offs. Browsers such as Firefox have now optimized localStorage use so that they will asynchronously initiate a read of all saved localStorage data for an origin once they know the page will load. If the data has not fully loaded by the time code accesses localStorage, the code will cause the page's main thread to block until the database load completes. When the main thread is blocked, no other JS code will run or layout will occur. In multiprocess browsers and for users with fast disk storage, this will be less of a problem. You are likely to get yelled at if you use localStorage.

A potentially better idea is to use something like https://github.com/mozilla/localForage although hooking it up will be slightly more involved. You are likely to be admired by all for judiciously avoiding use of localStorage.

Resizing callbacks

If you need more control over resizing, SplitPane can notify you about when resizing started and when it ended through two callbacks: onDragStarted and onDragFinished.

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;
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        -moz-background-clip: padding;
        -webkit-background-clip: padding;
        background-clip: padding-box;
    }

     .Resizer:hover {
        -webkit-transition: all 2s ease;
        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;
        width: 100%;
    }

    .Resizer.horizontal:hover {
        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 {
        border-left: 5px solid rgba(0, 0, 0, 0.5);
        border-right: 5px solid rgba(0, 0, 0, 0.5);
    }
    .Resizer.disabled {
      cursor: not-allowed;
    }
    .Resizer.disabled:hover {
      border-color: transparent;
    }

Inline Styles

You can also pass inline styles to the components via props. These are:

  • paneStyle - Styling to be applied to both panes
  • pane1Style - Styling to be applied to the first pane, with precedence over paneStyle
  • pane2Style - Styling to be applied to the second pane, with precedence over paneStyle
  • resizerStyle - Styling to be applied to the resizer bar

Contributing

I'm always happy to receive Pull Requests for contributions of any kind.

Please include tests and/or update the examples if possible.

I've been working on an updated version of this library - if you'd like to get involved in any way please ping me a message.

Thanks, Tom

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 33

Native requirements
31 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
glamor
Environment
{
  "local_name": "glamor",
  "alias": false,
  "peer_metadata": null
}
^2.20.40runtime
glamorous
Environment
{
  "local_name": "glamorous",
  "alias": false,
  "peer_metadata": null
}
^4.11.2runtime
inline-style-prefixer
Environment
{
  "local_name": "inline-style-prefixer",
  "alias": false,
  "peer_metadata": null
}
^4.0.0runtime
normalize.css
Environment
{
  "local_name": "normalize.css",
  "alias": false,
  "peer_metadata": null
}
^7.0.0runtime
styled-components
Environment
{
  "local_name": "styled-components",
  "alias": false,
  "peer_metadata": null
}
^2.4.0runtime
prop-types
Environment
{
  "local_name": "prop-types",
  "alias": false,
  "peer_metadata": null
}
^15.6.0runtime
react
Environment
{
  "local_name": "react",
  "alias": false,
  "peer_metadata": null
}
^16.2.0runtime
react-dom
Environment
{
  "local_name": "react-dom",
  "alias": false,
  "peer_metadata": null
}
^16.2.0runtime
babel-cli
Environment
{
  "local_name": "babel-cli",
  "alias": false,
  "peer_metadata": null
}
^6.26.0development
babel-plugin-add-module-exports
Environment
{
  "local_name": "babel-plugin-add-module-exports",
  "alias": false,
  "peer_metadata": null
}
^0.2.1development
babel-plugin-transform-object-assign
Environment
{
  "local_name": "babel-plugin-transform-object-assign",
  "alias": false,
  "peer_metadata": null
}
^6.22.0development
babel-plugin-transform-object-rest-spread
Environment
{
  "local_name": "babel-plugin-transform-object-rest-spread",
  "alias": false,
  "peer_metadata": null
}
^6.26.0development
babel-preset-es2015
Environment
{
  "local_name": "babel-preset-es2015",
  "alias": false,
  "peer_metadata": null
}
^6.24.1development
babel-preset-react
Environment
{
  "local_name": "babel-preset-react",
  "alias": false,
  "peer_metadata": null
}
^6.24.1development
babelify
Environment
{
  "local_name": "babelify",
  "alias": false,
  "peer_metadata": null
}
^8.0.0development
browserify
Environment
{
  "local_name": "browserify",
  "alias": false,
  "peer_metadata": null
}
^14.5.0development
chai
Environment
{
  "local_name": "chai",
  "alias": false,
  "peer_metadata": null
}
^4.1.2development
chai-spies
Environment
{
  "local_name": "chai-spies",
  "alias": false,
  "peer_metadata": null
}
^0.7.1development
core-js
Environment
{
  "local_name": "core-js",
  "alias": false,
  "peer_metadata": null
}
^2.5.3development
coveralls
Environment
{
  "local_name": "coveralls",
  "alias": false,
  "peer_metadata": null
}
^3.0.0development
express
Environment
{
  "local_name": "express",
  "alias": false,
  "peer_metadata": null
}
^4.16.2development
mochify
Environment
{
  "local_name": "mochify",
  "alias": false,
  "peer_metadata": null
}
^4.0.0development
mochify-istanbul
Environment
{
  "local_name": "mochify-istanbul",
  "alias": false,
  "peer_metadata": null
}
^2.4.2development
prettier
Environment
{
  "local_name": "prettier",
  "alias": false,
  "peer_metadata": null
}
^1.9.2development
react
Environment
{
  "local_name": "react",
  "alias": false,
  "peer_metadata": null
}
^16.2.0development
react-dom
Environment
{
  "local_name": "react-dom",
  "alias": false,
  "peer_metadata": null
}
^16.2.0development
sinon
Environment
{
  "local_name": "sinon",
  "alias": false,
  "peer_metadata": null
}
^5.0.7development
surge
Environment
{
  "local_name": "surge",
  "alias": false,
  "peer_metadata": null
}
^0.19.0development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
^2.6.2development
watchify
Environment
{
  "local_name": "watchify",
  "alias": false,
  "peer_metadata": null
}
^3.9.0development
@storybook/react
Environment
{
  "local_name": "@storybook/react",
  "alias": false,
  "peer_metadata": null
}
^3.3.3development
@storybook/addon-actions
Environment
{
  "local_name": "@storybook/addon-actions",
  "alias": false,
  "peer_metadata": null
}
^3.3.3development
@storybook/addon-links
Environment
{
  "local_name": "@storybook/addon-links",
  "alias": false,
  "peer_metadata": null
}
^3.3.3development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-YDuOxl8EXWWD+BmrMYW90UGfwBZ8qs1GRnClzNb2xg7twV9sNaYtUTTAmGN+B32JSYaV57QRmFX2RTsxEwPPUg==",
  "shasum": "367255f2799326101ccd6ae055deb9c66d66dc45",
  "tarball": "https://registry.npmjs.org/@0kzh/react-split-pane/-/react-split-pane-2.0.4.tgz",
  "fileCount": 15,
  "unpackedSize": 41338,
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEUCIQCX5WRb7rAwmelRKx9nbqcKin+brWKDqJF/TF8PPiaAvgIgS8AB0bV433PubFYAwsLeQBkK0wubxWo50i3fRUob+5k="
    }
  ]
}

Repository

PENDING
tomkp/react-split-pane

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:12 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:f9396efaa47fde63680d68aa902754bd5d2ae1afce9efdeb6941c95bd7905abb

Other collected versions

2.1.16 Nov2.1.06 Nov2.0.96 Nov2.0.86 Nov2.0.76 Nov2.0.66 NovView all collected versions →