A simple split layout for React and modern browsers.
rc-split-layout depends on React. See package.json for more details.
$ npm install --save rc-split-layoutTo run tests, execute test command with npm.
$ npm testTo run coverage tests, execute coverage script with npm.
$ npm run coverage-
Add
rc-split-layoutdependency to your code.$ npm install --save react-split-layout
-
Include the library into your code and use it.
import React from 'react'; import SplitLayout from 'rc-split-layout'; class YourComponent extends React.Component { handleSplitChange(v){ console.log(v); } render() { return ( <SplitLayout onChange={this.handleSplitChange.bind(this)}> <div>Pane 1</div> <div>Pane 2</div> </SplitLayout> ); } } export default YourComponent;
Write two parts of the layout as direct children of your SplitLayout element.
SplitLayout renders the first 2 direct children only if it has more than 2 direct children.
SplitLayout does not render splitter when it has only 1 direct children,
and the only direct children occupies all available space.
The SplitLayout component supports the following props.
-
customClassName: React.PropTypes.stringCustom CSS class name applied to the layout
div. You can use this to customize layout style. Refers to the original stylesheet to see what you can customize. -
vertical: React.PropTypes.boolDetermine whether the layout should be a horizontal split or a vertical split. The default value is
false. -
percentage: React.PropTypes.boolDetermine whether the width of each pane should be calculated in percentage or by pixels. The default value is
false, which means width is calculated in pixels. -
primaryIndex: React.PropTypes.numberIndex of the primary pane. Since
SplitterLayoutsupports at most 2 children, only0or1is allowed. The default value is0.A primary pane is used to show users primary content, while a secondary pane is the other pane. When window size changes and
percentageis set tofalse, primary pane's size is flexible and secondary pane's size is kept unchanged. However, when the window size is not enough for showing both minimal primary pane and minimal secondary pane, the primary pane's size is served first. -
primaryMinSize: React.PropTypes.numberMinimal size of primary pane. The default value is 0.
When
percentageis set tofalse, this value is pixel size (25 means 25px). Whenpercentageis set totrue, this value is percentage (25 means 25%). -
secondaryMinSize: React.PropTypes.numberMinimal size of secondary pane.
-
secondaryInitialSize: React.PropTypes.numberInitial size of secondary pane when page loads.
If this prop is not defined,
SplitterLayouttries to split the layout with equal sizes. (Note: equal size may not apply when there are nested layouts.) -
onChangereturn secondary size.