Skip to content

Commit

Permalink
feat: add <Animation> component
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Feb 23, 2018
1 parent 677d3e7 commit ac75ff5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "libreact",
"version": "0.7.1",
"version": "0.8.1",
"description": "React standard library",
"main": "lib/index.js",
"repository": {
Expand Down
29 changes: 29 additions & 0 deletions src/Animation/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {render, createEnhancer} from 'react-universal-interface';
import {Tween, ITweenProps} from '../Tween';
import {h} from '../util';

export interface IAnimationProps extends ITweenProps {
map: {[key: string]: [number, number]};
}

export const Animation: React.SFC<IAnimationProps> = (props) => {
return h(Tween, props,
({value}) => {
const {map} = props;
const keys = Object.keys(map);
const interpolated = {};

for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const [start, end] = map[key];
const diff = end - start;

interpolated[key] = diff * value + start;
}

render(props, interpolated);
}
);
};

export const withAnimation = createEnhancer(Animation, 'animation');

0 comments on commit ac75ff5

Please sign in to comment.