Skip to content

Commit db5bddf

Browse files
committed
Merge pull request #41 from IanVS/disable-sorting
Allow sorting to be disabled
2 parents 1112dcc + 3a10b12 commit db5bddf

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

README.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Sortable and resizable pane component for react.
77
## Demo
88

99
![screenshot](https://raw.githubusercontent.com/bokuweb/react-sortable-pane/master/screenshot/screenshot.gif)
10-
11-
10+
11+
1212
See demo: [http://bokuweb.github.io/react-sortable-pane](http://bokuweb.github.io/react-sortable-pane)
1313

1414
## Important Note
@@ -81,7 +81,7 @@ The `className` property is used to set the css class name of a component.
8181

8282
The `style` property is used to set the style of a component.
8383

84-
#### `direction`: PropTypes.oneOf(['horizontal', 'vertical']).
84+
#### `direction`: PropTypes.oneOf(['horizontal', 'vertical'])
8585

8686
The `direction` property is used to set the direction of a component.
8787
If ommited the default direction is `'horizontal'`.
@@ -91,20 +91,25 @@ If ommited the default direction is `'horizontal'`.
9191
The `margin` property is used to set the margin between Pane component.
9292
If ommited the default margin is `0`
9393

94-
#### `isResizable`: Proptypes.shape({ x: PropTypes.bool, y: PropTypes.bool, xy: PropTypes.bool })
94+
#### `isResizable`: PropTypes.shape({ x: PropTypes.bool, y: PropTypes.bool, xy: PropTypes.bool })
9595

9696
The `isResizable` property is used to set the resizable permission of a component.
9797

9898
The permission of `x`, `y`, `xy` direction resizing.
99-
If ommited the default value is `{ x: true, y: true, xy: true }`.
100-
If you want to permit only x direction resizing, please set `{ x:true, y:false, xy:false }`.
99+
If omitted the default value is `{ x: true, y: true, xy: true }`.
100+
If you want to permit only x direction resizing, please set `{ x:true, y:false, xy:false }`.
101+
102+
#### `isSortable`: PropTypes.bool
103+
104+
The `isSortable` property is used to control whether panes can be dragged or not.
105+
If omitted, the default value is `true`.
101106

102-
#### `disableEffect`: PropTypes.bool,
107+
#### `disableEffect`: PropTypes.bool
103108

104109
The `disableEffect` property is used to disable floating effect.
105-
If ommited the default margin is `false`.
110+
If omitted the default margin is `false`.
106111

107-
#### `onOrderChange`: PropTypes.func,
112+
#### `onOrderChange`: PropTypes.func
108113

109114
Calls when pane component order changed.
110115
Calls back with (`oldPanes: array`, `newPanes: array`)
@@ -136,11 +141,11 @@ See the example bellow.
136141
]
137142
```
138143

139-
144+
140145
#### `onResizeStart`: PropTypes.func
141146

142147
Calls when pane component resize starts.
143-
Calls back with (`id: number or string`, ``direction: string`)
148+
Calls back with (`id: number or string`, `direction: string`)
144149

145150
- id: pane id
146151
- direction: `x` or `y` or `xy`
@@ -156,7 +161,7 @@ Calls back with (`id: number or string`, `direction: string`, `coputedSize: obje
156161
- this argument is {width, height} of getComputedStyle.
157162
- rect: `{ width, height }`
158163
- this argument is `clientWidth` and `clientHeight`.
159-
164+
160165
For example, when `<Resizable width={100} height={200} style={{ padding: '20px'}} onResize={...} />` mounted and resize 'x', this callback is called with `('x', { width: 100, height: 200 }, { width: 140, height: 240 })`
161166

162167
#### `onResizeStop`: PropTypes.func
@@ -170,7 +175,7 @@ Calls back with (`id: number or string`, `direction: string`, `coputedSize: obje
170175
- this argument is {width, height} of getComputedStyle.
171176
- rect: `{ width, height }`
172177
- this argument is `clientWidth` and `clientHeight`.
173-
178+
174179
For example, when `<Resizable width={100} height={200} style={{ padding: '20px'}} onResize={...} />` mounted and resize 'x', this callback is called with `('x', { width: 100, height: 200 }, { width: 140, height: 240 })`
175180

176181
## Pane Component
@@ -201,7 +206,7 @@ The `maxWidth` property is used to set the maximum width of a Pane component.
201206

202207
#### `maxHeight`: PropTypes.number
203208

204-
The `maxheight` property is used to set the maximum height of a Pane component.
209+
The `maxHeight` property is used to set the maximum height of a Pane component.
205210

206211
#### `className`: PropTypes.string
207212

@@ -301,4 +306,3 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
301306
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
302307

303308
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.
304-

src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class SortablePane extends Component {
3434
y: React.PropTypes.bool,
3535
xy: React.PropTypes.bool,
3636
}),
37+
isSortable: PropTypes.bool,
3738
};
3839

3940
static defaultProps = {
@@ -54,6 +55,7 @@ class SortablePane extends Component {
5455
y: true,
5556
xy: true,
5657
},
58+
isSortable: true,
5759
};
5860

5961
constructor(props) {
@@ -341,7 +343,7 @@ class SortablePane extends Component {
341343
renderPanes() {
342344
const { mouse, isPressed, lastPressed } = this.state;
343345
const order = this.getPanePropsArrayOf('order');
344-
const { children, disableEffect } = this.props;
346+
const { children, disableEffect, isSortable } = this.props;
345347
return children.map((child, i) => {
346348
const springPosition = spring(this.getItemPositionByIndex(order.indexOf(i)), springConfig);
347349
const style = lastPressed === i && isPressed
@@ -361,7 +363,7 @@ class SortablePane extends Component {
361363
<Motion style={style} key={child.props.id}>
362364
{({ scale, shadow, x, y }) => {
363365
const onResize = this.onResize.bind(this, i);
364-
const onMouseDown = this.handleMouseDown.bind(this, i, x, y);
366+
const onMouseDown = isSortable ? this.handleMouseDown.bind(this, i, x, y) : () => null;
365367
const onTouchStart = this.handleTouchStart.bind(this, i, x, y);
366368
const onResizeStart = this.handleResizeStart.bind(this, i);
367369
const onResizeStop = this.handleResizeStop.bind(this, i);

0 commit comments

Comments
 (0)