UNPKG

6.05 kBMarkdownView Raw
1# React-Split   [![CI](https://img.shields.io/circleci/project/github/nathancahill/split/master.svg)](https://circleci.com/gh/nathancahill/split) ![Dependencies](https://david-dm.org/nathancahill/split/status.svg) ![](https://img.badgesize.io/https://unpkg.com/react-split/dist/react-split.min.js?compression=gzip&label=size&v=2.0.5)
2
3React component for [Split.js](https://github.com/nathancahill/Split.js/)
4
5## Installation
6
7Yarn:
8
9```
10$ yarn add react-split
11```
12
13npm:
14
15```
16$ npm install --save react-split
17```
18
19Include with a module bundler like [rollup](http://rollupjs.org/) or [webpack](https://webpack.github.io/):
20
21```js
22// using ES6 modules
23import Split from 'react-split'
24
25// using CommonJS modules
26var Split = require('react-split')
27```
28
29The [UMD](https://github.com/umdjs/umd) build is also available on [unpkg](http://unpkg.com/):
30
31```html
32<script src="https://unpkg.com/react-split/dist/react-split.js"></script>
33```
34
35You can find the library on `window.ReactSplit`.
36
37## Usage
38
39The `<Split />` component wraps multiple children components to create a resizeable split view. The component is a
40light wrapper around the [Split.js](https://github.com/nathancahill/Split.js/) library and accepts (mostly) the same options.
41
42```js
43import Split from 'react-split'
44
45<Split>
46 <ComponentA />
47 <ComponentB />
48</Split>
49```
50
51## Reference
52
53### `<Split>`
54
55Creates a Split instance and a `<div>` wrapper around the children components.
56All additional props are passed through to the to the `<div>` component.
57
58### Example
59
60```js
61import Split from 'react-split'
62
63<Split
64 sizes={[25, 75]}
65 minSize={100}
66 expandToMin={false}
67 gutterSize={10}
68 gutterAlign="center"
69 snapOffset={30}
70 dragInterval={1}
71 direction="horizontal"
72 cursor="col-resize"
73>
74 <ComponentA />
75 <ComponentB />
76</Split>
77```
78
79### Props
80
81#### `sizes`
82
83`sizes?: [number]` - [Docs](https://github.com/nathancahill/split/tree/master/packages/splitjs#sizes)
84
85#### `minSize`
86
87`minSize?: number | [number]` - [Docs](https://github.com/nathancahill/split/tree/master/packages/splitjs#minsize-default-100)
88
89#### `expandToMin`
90
91`expandToMin?: boolean` - [Docs](https://github.com/nathancahill/split/tree/master/packages/splitjs#expandtomin-default-false)
92
93#### `gutterSize`
94
95`gutterSize?: number` - [Docs](https://github.com/nathancahill/split/tree/master/packages/splitjs#guttersize-default-10)
96
97#### `gutterAlign`
98
99`gutterAlign?: 'center' | 'start' | 'end'` - [Docs](https://github.com/nathancahill/split/tree/master/packages/splitjs#gutteralign-default-center)
100
101#### `snapOffset`
102
103`snapOffset?: number` - [Docs](https://github.com/nathancahill/split/tree/master/packages/splitjs#snapoffset-default-30)
104
105#### `dragInterval`
106
107`dragInterval?: number` - [Docs](https://github.com/nathancahill/split/tree/master/packages/splitjs#draginterval-default-1)
108
109#### `direction`
110
111`direction?: 'horizontal' | 'vertical'` - [Docs](https://github.com/nathancahill/split/tree/master/packages/splitjs#direction-default-horizontal)
112
113#### `cursor`
114
115`cursor?: string` - [Docs](https://github.com/nathancahill/split/tree/master/packages/splitjs#cursor-default-col-resize)
116
117#### `gutter`
118
119`gutter?: (index, direction, pairElement) => HTMLElement` - [Docs](https://github.com/nathancahill/split/tree/master/packages/splitjs#gutter)
120
121#### `elementStyle`
122
123`elementStyle?: (dimension, elementSize, gutterSize, index) => Object` - [Docs](https://github.com/nathancahill/split/tree/master/packages/splitjs#elementstyle)
124
125#### `gutterStyle`
126
127`gutterStyle?: (dimension, gutterSize, index) => Object` - [Docs](https://github.com/nathancahill/split/tree/master/packages/splitjs#gutterstyle)
128
129#### `onDrag`
130
131`onDrag?: sizes => void` - [Docs](https://github.com/nathancahill/split/tree/master/packages/splitjs#ondrag-ondragstart-ondragend)
132
133#### `onDragStart`
134
135`onDragStart?: sizes => void` - [Docs](https://github.com/nathancahill/split/tree/master/packages/splitjs#ondrag-ondragstart-ondragend)
136
137#### `onDragEnd`
138
139`onDragEnd?: sizes => void` - [Docs](https://github.com/nathancahill/split/tree/master/packages/splitjs#ondrag-ondragstart-ondragend)
140
141## Migrating from Split.js
142
143Refer to [Split.js documentation](https://github.com/nathancahill/split/tree/master/packages/splitjs#documentation) for the options the component accepts as props. The differences are noted below:
144
145A few props are exempt from updating. These props are functions, these props will not trigger a `componentDidUpdate`.
146Following React best practices, and do not create functions in the render method. Instead, create them once and pass them as props.
147
148- `gutter`
149- `elementStyle`
150- `gutterStyle`
151- `onDrag`
152- `onDragStart`
153- `onDragEnd`
154
155#### API
156
157- `.setSizes(sizes)` becomes the prop `sizes={sizes}`
158- `.getSizes()` is unavailable, but sizes are passed to `onDragStart` and `onDragEnd`
159- `.collapse(index)` becomes the prop: `collapsed={index}`
160- `.destroy()` is triggered automatically on `componentWillUnmount`
161
162## License
163
164Copyright (c) 2019 Nathan Cahill
165
166Permission is hereby granted, free of charge, to any person obtaining a copy
167of this software and associated documentation files (the "Software"), to deal
168in the Software without restriction, including without limitation the rights
169to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
170copies of the Software, and to permit persons to whom the Software is
171furnished to do so, subject to the following conditions:
172
173The above copyright notice and this permission notice shall be included in
174all copies or substantial portions of the Software.
175
176THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
177IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
178FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
179AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
180LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
181OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
182THE SOFTWARE.