Skip to content

Commit ce0bedd

Browse files
committed
Added ability to specify custom springConfig
1 parent 9b26d65 commit ce0bedd

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/index.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { Motion, spring } from 'react-motion';
2+
import { Motion, spring, SpringHelperConfig } from 'react-motion';
33
import { ResizableDirection } from 're-resizable';
44
import ResizeObserver from 'resize-observer-polyfill';
55
import isEqual from 'lodash.isequal';
@@ -31,13 +31,7 @@ const directionDict: { [key: string]: PaneResizeDirection } = {
3131

3232
const clamp = (n: number, min = n, max = n): number => Math.max(Math.min(n, max), min);
3333

34-
type Spring = {
35-
damping?: number;
36-
stiffness?: number;
37-
precision?: number;
38-
};
39-
40-
const springConfig: Spring = {
34+
const defaultSpringConfig: SpringHelperConfig = {
4135
damping: 30,
4236
stiffness: 500,
4337
};
@@ -93,6 +87,7 @@ export type SortablePaneProps = {
9387
dragHandleClassName?: string;
9488
defaultOrder?: string[];
9589
order?: string[];
90+
springConfig?: SpringHelperConfig,
9691
children: React.ReactElement<PaneProps>[];
9792
};
9893

@@ -127,6 +122,7 @@ class SortablePane extends React.Component<SortablePaneProps, State> {
127122
className: '',
128123
disableEffect: false,
129124
isSortable: true,
125+
springConfig: defaultSpringConfig
130126
};
131127

132128
constructor(props: SortablePaneProps) {
@@ -516,7 +512,7 @@ class SortablePane extends React.Component<SortablePaneProps, State> {
516512

517513
renderPanes() {
518514
const { mouse, isPressed, lastPressed, isResizing } = this.state;
519-
const { disableEffect, isSortable } = this.props;
515+
const { disableEffect, isSortable, springConfig } = this.props;
520516
const children = this.props.children || [];
521517
return children.map((child, i) => {
522518
const pos = this.props.order

src/react-sortable-pane.es5.js.flow

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export type SortablePaneProps = {
2525
dragHandleClassName?: string,
2626
defaultOrder?: string[],
2727
order?: string[],
28+
springConfig?: { stiffness?: number, damping?: number, precision?: number }
2829
children: Pane[],
2930
};
3031

@@ -44,6 +45,7 @@ class SortablePane extends React.Component<SortablePaneProps> {
4445
onOrderChange: () => {},
4546
className: '',
4647
disableEffect: false,
48+
springConfig: { damping: 30, stiffness: 500 },
4749
isSortable: true,
4850
};
4951
}

0 commit comments

Comments
 (0)