forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
react-motion.d.ts
158 lines (142 loc) · 5.33 KB
/
react-motion.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Type definitions for react-motion
// Project: https://github.com/chenglou/react-motion
// Definitions by: Stepan Mikhaylyuk <https://github.com/stepancar>, Alexey Svetliakov <https://github.com/asvetliakov>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../react/react.d.ts" />
declare module "react-motion" {
import { Component, ReactElement } from 'react';
// your typical style object given in props. Maps to a number or a spring config
export type Style = { [key: string]: number | OpaqueConfig };
// the interpolating style object, with the same keys as the above Style object,
// with the values mapped to numbers, naturally
export type PlainStyle = { [key: string]: number };
// internal velocity object. Similar to PlainStyle, but whose numbers represent
// speed. Might be exposed one day.
export type Velocity = { [key: string]: number };
/**
* Spring additional configuration
*/
interface SpringHelperConfig {
/**
* Specified stiffness
* @defaults 170
*/
stiffness?: number;
/**
* Specifies damping
* @defaults 26
*/
damping?: number;
/**
* Specifies both the rounding of the interpolated value and the speed (internal).
* @defaults 0.01
*/
precision?: number;
}
export interface OpaqueConfig {
val: number;
stiffness: number;
damping: number;
precision: number;
}
/**
* <Motion/> properties
*/
interface MotionProps {
/**
* The default style. Being ignored on subsequent renders
* @default Object with same keys as in style whose values are the initial numbers you're interpolating on
*/
defaultStyle?: PlainStyle;
/**
* Object that maps to either number or opaque config returned by spring().
* Must keep same keys throughout component's existence
*/
style: Style;
/**
* Callback with your interpolated styles. Must return one react element to render
* @param interpolatedStyle
*/
children?: (interpolatedStyle: PlainStyle) => ReactElement<any>;
/**
* The callback that fires when the animation comes to a rest.
*/
onRest?: () => void;
}
export class Motion extends Component<MotionProps, any> { }
// === TransitionMotion ===
interface TransitionStyle {
/**
* The ID that TransitionMotion uses to track which configuration is which across renders, even when things are reordered.
* Typically reused as the component key when you map over the interpolated styles.
*/
key: string;
/**
* Anything you'd like to carry along. Will be preserved on re-renders until key off
*/
data?: any;
/**
* Actual starting style configuration
*/
style: Style; // actual style you're passing
}
/**
* Default style for transition
*/
interface TransitionPlainStyle {
key: any;
data?: any;
// same as TransitionStyle, passed as argument to style/children function
style: PlainStyle;
}
type InterpolateFunction = (previousInterpolatedStyles?: Array<TransitionPlainStyle>) => Array<TransitionStyle>;
/**
* Transition properties
*/
interface TransitionProps {
/**
* Default styles on first render
*/
defaultStyles?: Array<TransitionPlainStyle>;
/**
* Styles to interpolate. Accepts array of TransitionStyle objects or interpolated function similar as for
* <StaggeredMotion/>
*/
styles: Array<TransitionStyle> | InterpolateFunction;
children?: (interpolatedStyles: Array<TransitionPlainStyle>) => ReactElement<any>;
/**
* Triggers when new elements appears
* @param styleThatEntered
*/
willEnter?: (styleThatEntered: TransitionStyle) => PlainStyle;
/**
* Triggers when new element disappears
* @param styleThatLeft
*/
willLeave?: (styleThatLeft: TransitionStyle) => Style | void;
}
export class TransitionMotion extends Component<TransitionProps, any> { }
interface StaggeredMotionProps {
/**
* Default styles
*/
defaultStyles?: Array<PlainStyle>;
/**
* Styles to interpolate
* @param previousInterpolatedStyles The previously interpolating (array of) styles (undefined at first render, unless defaultStyles is provided).
*/
styles: (previousInterpolatedStyles?: Array<PlainStyle>) => Array<Style>;
}
export class StaggeredMotion extends Component<StaggeredMotionProps, any> { }
/**
* Used in conjunction with the components below. Specifies the how to animate to the destination value, e.g. spring(10, {stiffness: 120, damping: 17}) means "animate to value 10, with a spring of stiffness 120 and damping 17".
*/
export function spring(val: number, config?: SpringHelperConfig): OpaqueConfig;
export class Presets {
noWobble: OpaqueConfig; // the default, if nothing provided
gentle: OpaqueConfig;
wobbly: OpaqueConfig;
stiff: OpaqueConfig;
}
export const presets: Presets;
}