forked from pmndrs/react-spring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
310 lines (283 loc) · 7.56 KB
/
index.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
import {
Component,
PureComponent,
ReactNode,
ComponentClass,
ComponentType,
Ref,
ForwardRefExoticComponent,
} from 'react'
export type SpringEasingFunc = (t: number) => number
export interface SpringConfig {
mass?: number
tension?: number
friction?: number
velocity?: number
clamp?: boolean
precision?: number
delay?: number
duration?: number
easing?: SpringEasingFunc
}
type SpringRendererFunc<DS extends object = {}> = (params: DS) => ReactNode
interface SpringProps<DS extends object = {}> {
/**
* Spring config, or for individual keys: fn(key => config)
* @default config.default
*/
config?: SpringConfig | ((key: string) => SpringConfig)
/**
* Will skip rendering the component if true and write to the dom directly
* @default false
*/
native?: boolean
/**
* Base styles
* @default {}
*/
from?: Partial<DS>
/**
* Animates to...
* @default {}
*/
to: DS
/**
* Callback when the animation starts to animate
*/
onStart?: () => void
/**
* Callback when the animation comes to a still-stand
*/
onRest?: (ds: DS) => void
/**
* Frame by frame callback, first argument passed is the animated value
*/
onFrame?: (ds: DS) => void
/**
* Takes a function that receives interpolated styles
*/
children?: SpringRendererFunc<DS>
/**
* Prevents animation if true, you can also pass individual keys
* @default false
*/
immediate?: boolean | string[] | ((key: string) => boolean)
/**
* When true it literally resets: from -> to
* @default false
*/
reset?: boolean
/**
* Inject props
* @default undefined
*/
inject?: any
/**
* Animation start delay, optional
*/
delay?: number
/**
* Inject props after animation is ended
*/
after?: Partial<DS>
/**
* reverse the animation
*/
reverse?: boolean
/**
* Escape hatch to force the spring to render
*/
force?: boolean
}
export const config: {
/** default: { tension: 170, friction: 26 } */
default: SpringConfig
/** gentle: { tension: 120, friction: 14 } */
gentle: SpringConfig
/** wobbly: { tension: 180, friction: 12 } */
wobbly: SpringConfig
/** stiff: { tension: 210, friction: 20 } */
stiff: SpringConfig
/** slow: { tension: 280, friction: 60 } */
slow: SpringConfig
/** molasses: { tension: 280, friction: 120 } */
molasses: SpringConfig
}
export class Spring<DS extends object> extends PureComponent<SpringProps<DS>> {}
export function interpolate(
parent: number[],
config: (...args: number[]) => any
): any
export const animated: {
<P>(comp: ComponentType<P>): ForwardRefExoticComponent<P>
} & {
[Tag in keyof JSX.IntrinsicElements]: ForwardRefExoticComponent<
JSX.IntrinsicElements[Tag]
>
}
type TransitionKeyProps = string | number
type State = "enter" | "update" | "leave"
interface TransitionProps<
TItem,
TInit extends object = {},
TFrom extends object = {},
TEnter extends object = {},
TLeave extends object = {},
TUpdate extends object = {}
> {
/**
* First-render initial values, if present overrides "from" on the first render pass. It can be "null" to skip first mounting transition. Otherwise it can take an object or a function (item => object)
*/
initial?: TInit | null
/**
* Will skip rendering the component if true and write to the dom directly
* @default false
*/
native?: boolean
/**
* Spring config ({ tension, friction })
* @default config.default
*/
config?: SpringConfig | ((key: string) => SpringConfig)
/**
* Base values (from -> enter), or: item => values
* @default {}
*/
from?: TFrom
/**
* Values that apply to new elements, or: fitem => values
* @default {}
*/
enter?: TEnter
/**
* Values that apply to leaving elements, or: item => values
* @default {}
*/
leave?: TLeave
/**
* Values that apply to elements that are neither entering nor leaving (you can use this to update present elements), or: item => values
*/
update?: TUpdate
/**
* The same keys you would normally hand over to React in a list. Keys can be specified as a key-accessor function, an array of keys, or a single value
*/
keys?:
| ((item: TItem) => TransitionKeyProps)
| Array<TransitionKeyProps>
| TransitionKeyProps
/**
* An array of items to be displayed, this is used by Transition as the primary means of detecting changes.
* @default {}
*/
items: TItem[] | TItem
/**
* A single function-child that receives the individual item and return a functional component ((item, state, index) => props => view)
*/
children?: (
item: TItem,
state: State,
index: number
) => boolean | null | SpringRendererFunc<TInit & TFrom & TEnter & TLeave & TUpdate>
}
export class Transition<
TItem,
TInit extends object,
TFrom extends object,
TEnter extends object,
TLeave extends object,
TUpdate extends object
> extends PureComponent<
TransitionProps<TItem, TInit, TFrom, TEnter, TLeave, TUpdate>
> {}
type TrailKeyProps = string | number
interface TrailProps<TItem, DS extends object = {}> {
/**
* Will skip rendering the component if true and write to the dom directly
* @default false
*/
native?: boolean
/**
* Spring config, or for individual keys: fn(key => config)
* @default config.default
*/
config?: SpringConfig | ((key: string) => SpringConfig)
/**
* Base values, optional
*/
from?: Partial<DS>
/**
* Animates to ...
*/
to?: DS
/**
* An array of items to be displayed, use this if you need access to the actual items when distributing values as functions
*/
items: TItem[] | TItem
/**
* Item keys (the same keys you'd hand over to react in a list). If you specify items, keys can be an accessor function (item => item.key)
* @default item => item
*/
keys?: ((item: TItem) => TrailKeyProps) | Array<TrailKeyProps> | TrailKeyProps
/**
* A single function-child that receives the individual item and return a functional component (item, index) => props => view)
*/
children?: (item: TItem, index: number) => SpringRendererFunc<DS>
/**
* When true the trailing order is switched, it will then trail bottom to top
*/
reverse?: boolean
}
export class Trail<TItem, DS extends object> extends PureComponent<
TrailProps<TItem, DS>
> {}
interface ParallaxProps {
pages: number
config?: SpringConfig | ((key: string) => SpringConfig)
scrolling?: boolean
horizontal?: boolean
ref?: Ref<Parallax>
}
export class Parallax extends PureComponent<ParallaxProps> {
scrollTo: (offset: number) => void
}
interface ParallaxLayerProps {
factor?: number
offset?: number
speed?: number
}
export class ParallaxLayer extends PureComponent<ParallaxLayerProps> {}
interface KeyframesProps<DS extends object = {}> {
state?: string
}
export class Keyframes<
S extends object,
DS extends object
> extends PureComponent<KeyframesProps<DS> & S> {
static create<S extends object, DS extends object>(
primitive: ComponentType
): (states: object) => (props: object) => Keyframes<S, DS>
static Spring<S extends object, DS extends object>(
states: object
): (
props: object
) => Keyframes<
S | Pick<SpringProps<DS>, Exclude<keyof SpringProps<DS>, 'to'>>,
DS
>
static Trail<S extends object, DS extends object>(
states: object
): (
props: object
) => Keyframes<
S | Pick<TrailProps<DS>, Exclude<keyof TrailProps<DS>, 'to'>>,
DS
>
static Transition<S extends object, DS extends object>(
states: object
): (
props: object
) => Keyframes<
S | Pick<TransitionProps<S, DS>, Exclude<keyof TransitionProps<DS>, 'to'>>,
DS
>
}