diff --git a/demo/src/AnimatedProgressProvider.tsx b/demo/src/AnimatedProgressProvider.tsx new file mode 100644 index 0000000..fcd9b65 --- /dev/null +++ b/demo/src/AnimatedProgressProvider.tsx @@ -0,0 +1,53 @@ +import React from 'react'; +import { Animate } from 'react-move'; + +type Props = { + duration: number; + easingFunction: Function; + percentageStart: number; + percentageEnd: number; + children: (percentage: number) => React.ReactElement; +}; + +type State = { + isAnimated: boolean; +}; + +class AnimatedProgressProvider extends React.Component { + state = { + isAnimated: false, + }; + + static defaultProps = { + percentageStart: 0, + }; + + componentDidMount() { + this.setState({ + isAnimated: true, + }); + } + + render() { + return ( + ({ + percentage: this.props.percentageStart, + })} + update={() => ({ + percentage: [ + this.state.isAnimated ? this.props.percentageEnd : this.props.percentageStart, + ], + timing: { + duration: this.props.duration * 1000, + ease: this.props.easingFunction, + }, + })} + > + {({ percentage }) => this.props.children(percentage)} + + ); + } +} + +export default AnimatedProgressProvider; diff --git a/demo/src/AnimatedProgressbar.tsx b/demo/src/AnimatedProgressbar.tsx deleted file mode 100644 index f026123..0000000 --- a/demo/src/AnimatedProgressbar.tsx +++ /dev/null @@ -1,59 +0,0 @@ -import React from 'react'; -import { Animate } from 'react-move'; -import { CircularProgressbar } from 'react-circular-progressbar'; - -type Props = { - duration: number; - easingFunction: Function; - percentage: number; -}; - -type State = { - isAnimated: boolean; -}; - -class AnimatedProgressbar extends React.Component { - state = { - isAnimated: false, - }; - - componentDidMount() { - this.setState({ - isAnimated: true, - }); - } - - render() { - return ( - ({ - percentage: 0, - })} - update={() => ({ - percentage: [this.state.isAnimated ? this.props.percentage : 0], - timing: { - duration: this.props.duration * 1000, - ease: this.props.easingFunction, - }, - })} - > - {({ percentage }) => { - const roundedPercentage = Math.round(percentage); - return ( - - ); - }} - - ); - } -} - -export default AnimatedProgressbar; diff --git a/demo/src/Demo.tsx b/demo/src/Demo.tsx index 5d2c39c..56893f4 100644 --- a/demo/src/Demo.tsx +++ b/demo/src/Demo.tsx @@ -8,7 +8,7 @@ import classNames from 'classnames'; import { easeSinOut, easeQuadIn, easeQuadInOut, easeLinear, easeCubicInOut } from 'd3-ease'; // Custom progressbar wrappers -import AnimatedProgressbar from './AnimatedProgressbar'; +import AnimatedProgressProvider from './AnimatedProgressProvider'; import ChangingProgressProvider from './ChangingProgressProvider'; import ProgressProvider from './ProgressProvider'; @@ -146,7 +146,22 @@ function Demo() { } > - + + {(percentage) => { + const roundedPercentage = Math.round(percentage); + return ( + + ); + }} +