diff --git a/demo/demo.jsx b/demo/demo.jsx
index ab48015..1aa6e8d 100644
--- a/demo/demo.jsx
+++ b/demo/demo.jsx
@@ -20,6 +20,17 @@ const DemoItem = (props) => (
);
+const Example = (props) => (
+
+
+
{props.description}
+
+);
+
class ChangingProgressbar extends React.Component {
constructor(props) {
super(props);
@@ -73,20 +84,24 @@ class Demo extends React.Component {
+
-
-
-
- {
- return percentage === 100 ? 'complete' : 'incomplete';
- }}
- />
-
-
-
Configure color/styling based on percentage using plain old CSS classes.
-
+
+ {
+ return percentage === 100 ? 'complete' : 'incomplete';
+ }}
+ />
+
+
+
+
+
diff --git a/src/index.jsx b/src/index.jsx
index 7bd74cf..649f8ee 100644
--- a/src/index.jsx
+++ b/src/index.jsx
@@ -3,6 +3,26 @@ import React, { PropTypes } from 'react';
class CircularProgressbar extends React.Component {
constructor(props) {
super(props);
+
+ this.state = {
+ percentage: props.initialAnimation ? 0 : props.percentage,
+ };
+ }
+
+ componentDidMount() {
+ if (this.props.initialAnimation) {
+ setTimeout(() => {
+ this.setState({
+ percentage: this.props.percentage,
+ });
+ }, 10);
+ }
+ }
+
+ componentWillReceiveProps(nextProps) {
+ this.setState({
+ percentage: this.props.percentage,
+ });
}
render() {
@@ -16,7 +36,7 @@ class CircularProgressbar extends React.Component {
const diameter = Math.PI * 2 * radius;
const progressStyle = {
strokeDasharray: `${diameter}px ${diameter}px`,
- strokeDashoffset: `${((100 - this.props.percentage) / 100 * diameter)}px`,
+ strokeDashoffset: `${((100 - this.state.percentage) / 100 * diameter)}px`,
};
return (
@@ -58,6 +78,7 @@ CircularProgressbar.propTypes = {
CircularProgressbar.defaultProps = {
strokeWidth: 8,
textForPercentage: (percentage) => `${percentage}%`,
+ initialAnimation: false,
};
export default CircularProgressbar;