From 6590dbdd158ae17688ca782170111b5dba1e5fcc Mon Sep 17 00:00:00 2001 From: Stepan Mikhaylyuk Date: Wed, 6 Apr 2016 15:53:20 +0400 Subject: [PATCH] Created defintions for react-motion * started react motion definitions implementation * added tests * test from repo * updated definitions * chenaged to tsx * Update react-motion-tests.tsx * Update react-motion-tests.tsx --- react-motion/react-motion-tests.tsx | 17 ++++++ react-motion/react-motion.d.ts | 87 +++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 react-motion/react-motion-tests.tsx create mode 100644 react-motion/react-motion.d.ts diff --git a/react-motion/react-motion-tests.tsx b/react-motion/react-motion-tests.tsx new file mode 100644 index 000000000..0ff53dae4 --- /dev/null +++ b/react-motion/react-motion-tests.tsx @@ -0,0 +1,17 @@ + +/// +/// + +import * as React from 'react'; +import {Motion, spring} from 'react-motion'; + + +class Root extends React.Component<{}, {}> { + render() { + return ( + + {(value: any) =>
{ value.x }
} +
+ ); + } +} diff --git a/react-motion/react-motion.d.ts b/react-motion/react-motion.d.ts new file mode 100644 index 000000000..f868d084d --- /dev/null +++ b/react-motion/react-motion.d.ts @@ -0,0 +1,87 @@ +// Type definitions for react-motion +// Project: https://github.com/chenglou/react-motion +// Definitions by: Stepan Mikhaylyuk +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module "react-motion" { + import { Component } 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 }; + interface SpringHelperConfig { + stiffness: number; + damping: number; + /** + * Specifies both the rounding of the interpolated value and the speed (internal). + */ + precision?: number; + // TODO: add onRest. Not public yet + } + + export interface OpaqueConfig { + val: number; + stiffness: number; + damping: number; + precision: number; + // TODO: add onRest. Not public yet + } + + interface MotionProps { + defaultStyle?: any; + style: any; + } + + export class Motion extends Component { } + + // === TransitionMotion === + interface TransitionStyle { + key: any; // unique ID to identify component across render animations + data?: any; // optional data you want to carry along the style, e.g. itemText + style: Style; // actual style you're passing + } + interface TransitionPlainStyle { + key: any; + data?: any; + // same as TransitionStyle, passed as argument to style/children function + style: PlainStyle; + } + type InterpolateFunction = (previousInterpolatedStyles?: Array) => Array; + type Styles = Array | InterpolateFunction; + interface TransitionProps { + defaultStyles?: Array; + styles: Styles; + children: (interpolatedStyles: Array) => __React.ReactElement; + willEnter?: (styleThatEntered: TransitionStyle) => PlainStyle; + willLeave?: (styleThatLeft: TransitionStyle) => Style; + } + export class TransitionMotion extends Component { } + + interface StaggeredMotionProps { + defaultStyles?: Array; + styles: (previousInterpolatedStyles?: Array) => Array