Skip to content

Commit e626906

Browse files
authored
Merge pull request #1 from Forever-Young/master
Tahnk you very much for this build!
2 parents b62a3e3 + cd16ce3 commit e626906

File tree

1 file changed

+180
-101
lines changed

1 file changed

+180
-101
lines changed

dist/react-progressbar.js

Lines changed: 180 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
11
(function (global, factory) {
22
if (typeof define === "function" && define.amd) {
3-
define(['module', 'react', 'react-dom', 'lodash.isequal', 'progressbar.js'], factory);
3+
define(['exports', 'react', 'prop-types', 'lodash.isequal', 'progressbar.js'], factory);
44
} else if (typeof exports !== "undefined") {
5-
factory(module, require('react'), require('react-dom'), require('lodash.isequal'), require('progressbar.js'));
5+
factory(exports, require('react'), require('prop-types'), require('lodash.isequal'), require('progressbar.js'));
66
} else {
77
var mod = {
88
exports: {}
99
};
10-
factory(mod, global.react, global.reactDom, global.lodash, global.progressbar);
10+
factory(mod.exports, global.react, global.propTypes, global.lodash, global.progressbar);
1111
global.main = mod.exports;
1212
}
13-
})(this, function (module, React, ReactDom, isEqual, ProgressBar) {
13+
})(this, function (exports, _react, _propTypes, _lodash, _progressbar) {
1414
'use strict';
1515

16+
Object.defineProperty(exports, "__esModule", {
17+
value: true
18+
});
19+
exports.SemiCircle = exports.Circle = exports.Line = exports.Shape = undefined;
20+
21+
var _react2 = _interopRequireDefault(_react);
22+
23+
var _propTypes2 = _interopRequireDefault(_propTypes);
24+
25+
var _lodash2 = _interopRequireDefault(_lodash);
26+
27+
var _progressbar2 = _interopRequireDefault(_progressbar);
28+
29+
function _interopRequireDefault(obj) {
30+
return obj && obj.__esModule ? obj : {
31+
default: obj
32+
};
33+
}
34+
1635
var _extends = Object.assign || function (target) {
1736
for (var i = 1; i < arguments.length; i++) {
1837
var source = arguments[i];
@@ -27,122 +46,182 @@
2746
return target;
2847
};
2948

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;
49+
function _classCallCheck(instance, Constructor) {
50+
if (!(instance instanceof Constructor)) {
51+
throw new TypeError("Cannot call a class as a function");
52+
}
53+
}
54+
55+
var _createClass = function () {
56+
function defineProperties(target, props) {
57+
for (var i = 0; i < props.length; i++) {
58+
var descriptor = props[i];
59+
descriptor.enumerable = descriptor.enumerable || false;
60+
descriptor.configurable = true;
61+
if ("value" in descriptor) descriptor.writable = true;
62+
Object.defineProperty(target, descriptor.key, descriptor);
6363
}
64+
}
65+
66+
return function (Constructor, protoProps, staticProps) {
67+
if (protoProps) defineProperties(Constructor.prototype, protoProps);
68+
if (staticProps) defineProperties(Constructor, staticProps);
69+
return Constructor;
70+
};
71+
}();
6472

65-
this._animateProgress(nextProps.progress);
66-
this._setText(nextProps.text);
67-
},
73+
function _possibleConstructorReturn(self, call) {
74+
if (!self) {
75+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
76+
}
6877

69-
componentDidMount: function componentDidMount() {
70-
this._create(this.props);
71-
},
78+
return call && (typeof call === "object" || typeof call === "function") ? call : self;
79+
}
7280

73-
componentWillUnmount: function componentWillUnmount() {
74-
this._destroy();
75-
},
81+
function _inherits(subClass, superClass) {
82+
if (typeof superClass !== "function" && superClass !== null) {
83+
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
84+
}
7685

77-
_create: function _create(props, oldProps) {
78-
if (this.state.shape !== null) {
79-
throw new Error('Progressbar is already created');
86+
subClass.prototype = Object.create(superClass && superClass.prototype, {
87+
constructor: {
88+
value: subClass,
89+
enumerable: false,
90+
writable: true,
91+
configurable: true
8092
}
93+
});
94+
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
95+
}
8196

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);
97+
var Shape = exports.Shape = function (_React$Component) {
98+
_inherits(Shape, _React$Component);
8699

87-
if (props.initialAnimate) {
88-
if (oldProps) {
89-
this._setProgress(oldProps.progress);
90-
}
100+
function Shape() {
101+
_classCallCheck(this, Shape);
91102

92-
this._animateProgress(props.progress);
93-
} else {
94-
this._setProgress(props.progress);
95-
}
103+
return _possibleConstructorReturn(this, (Shape.__proto__ || Object.getPrototypeOf(Shape)).apply(this, arguments));
104+
}
96105

97-
this._setText(props.text);
98-
},
106+
_createClass(Shape, [{
107+
key: 'componentDidMount',
108+
value: function componentDidMount() {
109+
this.shape = null;
110+
this.create(this.props);
111+
}
112+
}, {
113+
key: 'componentWillReceiveProps',
114+
value: function componentWillReceiveProps(nextProps) {
115+
if (!(0, _lodash2.default)(this.props.options, nextProps.options)) {
116+
this.destroy();
117+
this.create(nextProps, this.props);
118+
return false;
119+
}
99120

100-
_destroy: function _destroy() {
101-
if (this.state.shape) {
102-
this.state.shape.destroy();
103-
this.state.shape = null;
121+
this.animateProgress(nextProps.progress);
122+
this.setText(nextProps.text);
123+
return true;
104124
}
105-
},
125+
}, {
126+
key: 'componentWillUnmount',
127+
value: function componentWillUnmount() {
128+
this.destroy();
129+
}
130+
}, {
131+
key: 'setProgress',
132+
value: function setProgress(progress) {
133+
this.shape.set(progress);
134+
}
135+
}, {
136+
key: 'setText',
137+
value: function setText(text) {
138+
if (text) {
139+
this.shape.setText(text);
140+
}
141+
}
142+
}, {
143+
key: 'create',
144+
value: function create(nextProps, oldProps) {
145+
if (this.shape !== null) {
146+
throw new Error('Progressbar is already created');
147+
}
148+
149+
this.shape = new nextProps.ShapeClass(this.progressBar, nextProps.options);
106150

107-
_animateProgress: function _animateProgress(progress) {
108-
this.state.shape.animate(progress);
109-
},
151+
if (nextProps.initialAnimate) {
152+
if (oldProps) {
153+
this.setProgress(oldProps.progress);
154+
}
110155

111-
_setProgress: function _setProgress(progress) {
112-
this.state.shape.set(progress);
113-
},
156+
this.animateProgress(nextProps.progress);
157+
} else {
158+
this.setProgress(nextProps.progress);
159+
}
114160

115-
_setText: function _setText(text) {
116-
if (text) {
117-
this.state.shape.setText(text);
161+
this.setText(nextProps.text);
118162
}
119-
}
120-
});
163+
}, {
164+
key: 'animateProgress',
165+
value: function animateProgress(progress) {
166+
this.shape.animate(progress);
167+
}
168+
}, {
169+
key: 'destroy',
170+
value: function destroy() {
171+
if (this.shape) {
172+
this.shape.destroy();
173+
this.shape = null;
174+
}
175+
}
176+
}, {
177+
key: 'render',
178+
value: function render() {
179+
var _this2 = this;
180+
181+
var style = this.props.containerStyle;
182+
var className = this.props.containerClassName;
183+
return _react2.default.createElement('div', {
184+
className: className,
185+
style: style,
186+
ref: function ref(node) {
187+
_this2.progressBar = node;
188+
}
189+
});
190+
}
191+
}]);
192+
193+
return Shape;
194+
}(_react2.default.Component);
195+
196+
Shape.defaultProps = {
197+
ShapeClass: null,
198+
options: {},
199+
progress: 0,
200+
text: null,
201+
initialAnimate: false,
202+
containerStyle: {},
203+
containerClassName: '.progressbar-container'
204+
};
121205

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-
});
206+
Shape.propTypes = {
207+
ShapeClass: _propTypes2.default.oneOf([_progressbar2.default.Circle]),
208+
options: _propTypes2.default.objectOf(_propTypes2.default.oneOfType([_propTypes2.default.number, _propTypes2.default.string, _propTypes2.default.object])),
209+
progress: _propTypes2.default.number,
210+
text: _propTypes2.default.string,
211+
initialAnimate: _propTypes2.default.bool,
212+
containerStyle: _propTypes2.default.objectOf(_propTypes2.default.string),
213+
containerClassName: _propTypes2.default.string
214+
};
128215

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-
});
216+
var Line = exports.Line = function Line(props) {
217+
return _react2.default.createElement(Shape, _extends({}, props, { ShapeClass: _progressbar2.default.Line }));
218+
};
135219

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-
});
220+
var Circle = exports.Circle = function Circle(props) {
221+
return _react2.default.createElement(Shape, _extends({}, props, { ShapeClass: _progressbar2.default.Circle }));
222+
};
142223

143-
module.exports = {
144-
Line: Line,
145-
Circle: Circle,
146-
SemiCircle: SemiCircle
224+
var SemiCircle = exports.SemiCircle = function SemiCircle(props) {
225+
return _react2.default.createElement(Shape, _extends({}, props, { ShapeClass: _progressbar2.default.SemiCircle }));
147226
};
148227
});

0 commit comments

Comments
 (0)