Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit 4b15907

Browse files
Merge pull request #6 from blogfoster/feature/dist-output
Upgrade to React v15, prepare dist folder.
2 parents 16f80e2 + 90e25a1 commit 4b15907

File tree

5 files changed

+181
-20
lines changed

5 files changed

+181
-20
lines changed

.babelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["es2015", "react"],
3+
"plugins": ["transform-es2015-modules-umd"]
4+
}

dist/react-progressbar.js

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
(function (global, factory) {
2+
if (typeof define === "function" && define.amd) {
3+
define(['module', 'react', 'react-dom', 'lodash.isequal', 'progressbar.js'], factory);
4+
} else if (typeof exports !== "undefined") {
5+
factory(module, require('react'), require('react-dom'), require('lodash.isequal'), require('progressbar.js'));
6+
} else {
7+
var mod = {
8+
exports: {}
9+
};
10+
factory(mod, global.react, global.reactDom, global.lodash, global.progressbar);
11+
global.main = mod.exports;
12+
}
13+
})(this, function (module, React, ReactDom, isEqual, ProgressBar) {
14+
'use strict';
15+
16+
var _extends = Object.assign || function (target) {
17+
for (var i = 1; i < arguments.length; i++) {
18+
var source = arguments[i];
19+
20+
for (var key in source) {
21+
if (Object.prototype.hasOwnProperty.call(source, key)) {
22+
target[key] = source[key];
23+
}
24+
}
25+
}
26+
27+
return target;
28+
};
29+
30+
var Shape = React.createClass({
31+
displayName: 'Shape',
32+
33+
getDefaultProps: function getDefaultProps() {
34+
return {
35+
ShapeClass: null,
36+
options: {},
37+
progress: 0,
38+
text: null,
39+
initialAnimate: false,
40+
containerStyle: {},
41+
containerClassName: '.progressbar-container'
42+
};
43+
},
44+
45+
getInitialState: function getInitialState() {
46+
return {
47+
shape: null
48+
};
49+
},
50+
51+
render: function render() {
52+
var style = this.props.containerStyle;
53+
var className = this.props.containerClassName;
54+
55+
return React.createElement('div', { className: className, style: style, ref: 'progressBar' });
56+
},
57+
58+
componentWillReceiveProps: function componentWillReceiveProps(nextProps) {
59+
if (!isEqual(this.props.options, nextProps.options)) {
60+
this._destroy();
61+
this._create(nextProps, this.props);
62+
return;
63+
}
64+
65+
this._animateProgress(nextProps.progress);
66+
this._setText(nextProps.text);
67+
},
68+
69+
componentDidMount: function componentDidMount() {
70+
this._create(this.props);
71+
},
72+
73+
componentWillUnmount: function componentWillUnmount() {
74+
this._destroy();
75+
},
76+
77+
_create: function _create(props, oldProps) {
78+
if (this.state.shape !== null) {
79+
throw new Error('Progressbar is already created');
80+
}
81+
82+
// setState function is not used to prevent a new render cycle
83+
// This handling happens outside of React component's lifecycle
84+
var container = ReactDom.findDOMNode(this.refs.progressBar);
85+
this.state.shape = new props.ShapeClass(container, props.options);
86+
87+
if (props.initialAnimate) {
88+
if (oldProps) {
89+
this._setProgress(oldProps.progress);
90+
}
91+
92+
this._animateProgress(props.progress);
93+
} else {
94+
this._setProgress(props.progress);
95+
}
96+
97+
this._setText(props.text);
98+
},
99+
100+
_destroy: function _destroy() {
101+
if (this.state.shape) {
102+
this.state.shape.destroy();
103+
this.state.shape = null;
104+
}
105+
},
106+
107+
_animateProgress: function _animateProgress(progress) {
108+
this.state.shape.animate(progress);
109+
},
110+
111+
_setProgress: function _setProgress(progress) {
112+
this.state.shape.set(progress);
113+
},
114+
115+
_setText: function _setText(text) {
116+
if (text) {
117+
this.state.shape.setText(text);
118+
}
119+
}
120+
});
121+
122+
var Line = React.createClass({
123+
displayName: 'Line',
124+
render: function render() {
125+
return React.createElement(Shape, _extends({}, this.props, { ShapeClass: ProgressBar.Line }));
126+
}
127+
});
128+
129+
var Circle = React.createClass({
130+
displayName: 'Circle',
131+
render: function render() {
132+
return React.createElement(Shape, _extends({}, this.props, { ShapeClass: ProgressBar.Circle }));
133+
}
134+
});
135+
136+
var SemiCircle = React.createClass({
137+
displayName: 'SemiCircle',
138+
render: function render() {
139+
return React.createElement(Shape, _extends({}, this.props, { ShapeClass: ProgressBar.SemiCircle }));
140+
}
141+
});
142+
143+
module.exports = {
144+
Line: Line,
145+
Circle: Circle,
146+
SemiCircle: SemiCircle
147+
};
148+
});

local-dev/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var React = require('react');
2+
var ReactDom = require('react-dom');
23
var ProgressBar = require('../src/main.js');
34
var Circle = ProgressBar.Circle;
45

@@ -34,7 +35,7 @@ var App = React.createClass({
3435
}
3536
});
3637

37-
React.render(
38+
ReactDom.render(
3839
<App />,
3940
document.querySelector('body')
4041
);

package.json

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "react-progressbar.js",
33
"version": "0.1.2-dev",
44
"description": "React wrapper for progressbar.js",
5-
"main": "src/main.js",
5+
"main": "dist/react-progressbar.js",
66
"repository": {
77
"type": "git",
88
"url": "git+https://github.com/kimmobrunfeldt/react-progressbar.js.git"
@@ -29,28 +29,34 @@
2929
},
3030
"homepage": "https://github.com/kimmobrunfeldt/react-progressbar.js#readme",
3131
"dependencies": {
32-
"lodash.isequal": "^3.0.4",
33-
"progressbar.js": "^0.9.0",
34-
"react": "^0.13.3"
32+
"lodash.isequal": "^4.1.4",
33+
"progressbar.js": "^1.0.1",
34+
"react": "^15.0.1",
35+
"react-dom": "^15.0.1"
3536
},
3637
"devDependencies": {
37-
"babel": "^5.8.23",
38-
"babel-eslint": "^4.1.1",
39-
"babel-jscs": "^2.0.4",
40-
"bluebird": "^2.9.34",
38+
"babel": "^6.5.2",
39+
"babel-cli": "^6.7.7",
40+
"babel-eslint": "^6.0.3",
41+
"babel-jscs": "^3.0.0-beta1",
42+
"babel-plugin-transform-es2015-modules-umd": "^6.6.5",
43+
"babel-preset-es2015": "^6.6.0",
44+
"babel-preset-react": "^6.5.0",
45+
"babelify": "^7.2.0",
46+
"bluebird": "^3.3.5",
4147
"commander": "^2.8.1",
42-
"concurrently": "^0.1.1",
43-
"eslint": "^1.3.1",
44-
"eslint-plugin-react": "^3.3.1",
45-
"http-server": "^0.8.0",
46-
"jscs": "^2.1.1",
47-
"lodash": "^3.10.1",
48+
"concurrently": "^2.0.0",
49+
"eslint": "^2.8.0",
50+
"eslint-plugin-react": "^5.0.1",
51+
"http-server": "^0.9.0",
52+
"jscs": "^3.0.3",
53+
"lodash": "^4.11.1",
4854
"mustache": "^2.1.3",
55+
"reactify": "^1.1.1",
4956
"semver": "^5.0.1",
50-
"shelljs": "^0.5.3",
57+
"shelljs": "^0.6.0",
5158
"string": "^3.3.1",
52-
"watchify": "^3.4.0",
53-
"reactify": "^1.1.1"
59+
"watchify": "^3.4.0"
5460
},
5561
"browserify": {
5662
"transform": [
@@ -60,9 +66,10 @@
6066
"scripts": {
6167
"start": "concurrent 'npm run serve' 'npm run watch-js' 'open http://localhost:8080'",
6268
"watch-js": "watchify local-dev/main.js -t reactify -o local-dev/bundle.js --debug --verbose",
69+
"build": "babel src/main.js -o ./dist/react-progressbar.js",
6370
"serve": "http-server ./local-dev -c 0",
6471
"lint": "./tools/lint.sh",
6572
"jscs": "jscs ./src ./test",
6673
"eslint": "eslint --ext .js ./src ./test"
6774
}
68-
}
75+
}

src/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var React = require('react');
2+
var ReactDom = require('react-dom');
23
var isEqual = require('lodash.isequal');
34
var ProgressBar = require('progressbar.js');
45

@@ -54,7 +55,7 @@ var Shape = React.createClass({
5455

5556
// setState function is not used to prevent a new render cycle
5657
// This handling happens outside of React component's lifecycle
57-
var container = React.findDOMNode(this.refs.progressBar);
58+
var container = ReactDom.findDOMNode(this.refs.progressBar);
5859
this.state.shape = new props.ShapeClass(
5960
container,
6061
props.options

0 commit comments

Comments
 (0)