Skip to content

Commit

Permalink
Merge pull request #233 from Edheltur/master
Browse files Browse the repository at this point in the history
Added ability to specify custom springConfig
  • Loading branch information
bokuweb authored May 1, 2019
2 parents 9b26d65 + ce0bedd commit 977fb9e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Motion, spring } from 'react-motion';
import { Motion, spring, SpringHelperConfig } from 'react-motion';
import { ResizableDirection } from 're-resizable';
import ResizeObserver from 'resize-observer-polyfill';
import isEqual from 'lodash.isequal';
Expand Down Expand Up @@ -31,13 +31,7 @@ const directionDict: { [key: string]: PaneResizeDirection } = {

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

type Spring = {
damping?: number;
stiffness?: number;
precision?: number;
};

const springConfig: Spring = {
const defaultSpringConfig: SpringHelperConfig = {
damping: 30,
stiffness: 500,
};
Expand Down Expand Up @@ -93,6 +87,7 @@ export type SortablePaneProps = {
dragHandleClassName?: string;
defaultOrder?: string[];
order?: string[];
springConfig?: SpringHelperConfig,
children: React.ReactElement<PaneProps>[];
};

Expand Down Expand Up @@ -127,6 +122,7 @@ class SortablePane extends React.Component<SortablePaneProps, State> {
className: '',
disableEffect: false,
isSortable: true,
springConfig: defaultSpringConfig
};

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

renderPanes() {
const { mouse, isPressed, lastPressed, isResizing } = this.state;
const { disableEffect, isSortable } = this.props;
const { disableEffect, isSortable, springConfig } = this.props;
const children = this.props.children || [];
return children.map((child, i) => {
const pos = this.props.order
Expand Down
2 changes: 2 additions & 0 deletions src/react-sortable-pane.es5.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type SortablePaneProps = {
dragHandleClassName?: string,
defaultOrder?: string[],
order?: string[],
springConfig?: { stiffness?: number, damping?: number, precision?: number }
children: Pane[],
};

Expand All @@ -44,6 +45,7 @@ class SortablePane extends React.Component<SortablePaneProps> {
onOrderChange: () => {},
className: '',
disableEffect: false,
springConfig: { damping: 30, stiffness: 500 },
isSortable: true,
};
}
Expand Down

0 comments on commit 977fb9e

Please sign in to comment.