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

Commit

Permalink
Merge pull request #26 from sebacruz/master
Browse files Browse the repository at this point in the history
Update to React 16 and move to ES6
  • Loading branch information
kimmobrunfeldt authored May 28, 2018
2 parents 414dc4c + fae968f commit 8ffd06c
Show file tree
Hide file tree
Showing 4 changed files with 275 additions and 157 deletions.
292 changes: 203 additions & 89 deletions dist/react-progressbar.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
(function (global, factory) {
if (typeof define === "function" && define.amd) {
define(['module', 'react', 'react-dom', 'lodash.isequal', 'progressbar.js'], factory);
define(['module', 'react', 'react-dom', 'lodash/isEqual', 'progressbar.js'], factory);
} else if (typeof exports !== "undefined") {
factory(module, require('react'), require('react-dom'), require('lodash.isequal'), require('progressbar.js'));
factory(module, require('react'), require('react-dom'), require('lodash/isEqual'), require('progressbar.js'));
} else {
var mod = {
exports: {}
};
factory(mod, global.react, global.reactDom, global.lodash, global.progressbar);
factory(mod, global.react, global.reactDom, global.isEqual, global.progressbar);
global.main = mod.exports;
}
})(this, function (module, React, ReactDom, isEqual, ProgressBar) {
})(this, function (module, _react, _reactDom, _isEqual, _progressbar) {
'use strict';

var _react2 = _interopRequireDefault(_react);

var _isEqual2 = _interopRequireDefault(_isEqual);

var _progressbar2 = _interopRequireDefault(_progressbar);

function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}

var _extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
Expand All @@ -27,118 +39,220 @@
return target;
};

var Shape = React.createClass({
displayName: 'Shape',

getDefaultProps: function getDefaultProps() {
return {
ShapeClass: null,
options: {},
progress: 0,
text: null,
initialAnimate: false,
containerStyle: {},
containerClassName: '.progressbar-container'
};
},
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}

var _createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}

return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();

function _possibleConstructorReturn(self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}

return call && (typeof call === "object" || typeof call === "function") ? call : self;
}

function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}

subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
}

getInitialState: function getInitialState() {
return {
var Shape = function (_Component) {
_inherits(Shape, _Component);

function Shape(props) {
_classCallCheck(this, Shape);

var _this = _possibleConstructorReturn(this, (Shape.__proto__ || Object.getPrototypeOf(Shape)).call(this, props));

_this.state = {
shape: null
};
},
return _this;
}

render: function render() {
var style = this.props.containerStyle;
var className = this.props.containerClassName;
_createClass(Shape, [{
key: 'render',
value: function render() {
var _props = this.props,
style = _props.style,
className = _props.className;

return React.createElement('div', { className: className, style: style, ref: 'progressBar' });
},

componentWillReceiveProps: function componentWillReceiveProps(nextProps) {
if (!isEqual(this.props.options, nextProps.options)) {
this._destroy();
this._create(nextProps, this.props);
return;
return _react2.default.createElement('div', { className: className, style: style, ref: 'progressBar' });
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
if (!(0, _isEqual2.default)(this.props.options, nextProps.options)) {
this._destroy();
this._create(nextProps, this.props);

this._animateProgress(nextProps.progress);
this._setText(nextProps.text);
},
return;
}

componentDidMount: function componentDidMount() {
this._create(this.props);
},
this._animateProgress(nextProps.progress);
this._setText(nextProps.text);
}
}, {
key: 'componentDidMount',
value: function componentDidMount() {
this._create(this.props);
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
this._destroy();
}
}, {
key: '_create',
value: function _create(props, oldProps) {
if (this.state.shape !== null) {
throw new Error('Progressbar is already created');
}

componentWillUnmount: function componentWillUnmount() {
this._destroy();
},
// setState function is not used to prevent a new render cycle
// This handling happens outside of React component's lifecycle
var container = (0, _reactDom.findDOMNode)(this.refs.progressBar);

_create: function _create(props, oldProps) {
if (this.state.shape !== null) {
throw new Error('Progressbar is already created');
}
this.state.shape = new props.ShapeClass(container, props.options);

// setState function is not used to prevent a new render cycle
// This handling happens outside of React component's lifecycle
var container = ReactDom.findDOMNode(this.refs.progressBar);
this.state.shape = new props.ShapeClass(container, props.options);
if (props.initialAnimate) {
if (oldProps) {
this._setProgress(oldProps.progress);
}

if (props.initialAnimate) {
if (oldProps) {
this._setProgress(oldProps.progress);
this._animateProgress(props.progress);
} else {
this._setProgress(props.progress);
}

this._animateProgress(props.progress);
} else {
this._setProgress(props.progress);
this._setText(props.text);
}
}, {
key: '_destroy',
value: function _destroy() {
if (this.state.shape) {
this.state.shape.destroy();
this.state.shape = null;
}
}
}, {
key: '_animateProgress',
value: function _animateProgress(progress) {
this.state.shape.animate(progress);
}
}, {
key: '_setProgress',
value: function _setProgress(progress) {
this.state.shape.set(progress);
}
}, {
key: '_setText',
value: function _setText(text) {
if (text) {
this.state.shape.setText(text);
}
}
}]);

this._setText(props.text);
},
return Shape;
}(_react.Component);

_destroy: function _destroy() {
if (this.state.shape) {
this.state.shape.destroy();
this.state.shape = null;
}
},
;

_animateProgress: function _animateProgress(progress) {
this.state.shape.animate(progress);
},
var Line = function (_Component2) {
_inherits(Line, _Component2);

_setProgress: function _setProgress(progress) {
this.state.shape.set(progress);
},
function Line() {
_classCallCheck(this, Line);

_setText: function _setText(text) {
if (text) {
this.state.shape.setText(text);
}
return _possibleConstructorReturn(this, (Line.__proto__ || Object.getPrototypeOf(Line)).apply(this, arguments));
}
});

var Line = React.createClass({
displayName: 'Line',
render: function render() {
return React.createElement(Shape, _extends({}, this.props, { ShapeClass: ProgressBar.Line }));
}
});
_createClass(Line, [{
key: 'render',
value: function render() {
return _react2.default.createElement(Shape, _extends({}, this.props, { ShapeClass: _progressbar2.default.Line }));
}
}]);

var Circle = React.createClass({
displayName: 'Circle',
render: function render() {
return React.createElement(Shape, _extends({}, this.props, { ShapeClass: ProgressBar.Circle }));
return Line;
}(_react.Component);

;

var Circle = function (_Component3) {
_inherits(Circle, _Component3);

function Circle() {
_classCallCheck(this, Circle);

return _possibleConstructorReturn(this, (Circle.__proto__ || Object.getPrototypeOf(Circle)).apply(this, arguments));
}
});

var SemiCircle = React.createClass({
displayName: 'SemiCircle',
render: function render() {
return React.createElement(Shape, _extends({}, this.props, { ShapeClass: ProgressBar.SemiCircle }));
_createClass(Circle, [{
key: 'render',
value: function render() {
return _react2.default.createElement(Shape, _extends({}, this.props, { ShapeClass: _progressbar2.default.Circle }));
}
}]);

return Circle;
}(_react.Component);

;

var SemiCircle = function (_Component4) {
_inherits(SemiCircle, _Component4);

function SemiCircle() {
_classCallCheck(this, SemiCircle);

return _possibleConstructorReturn(this, (SemiCircle.__proto__ || Object.getPrototypeOf(SemiCircle)).apply(this, arguments));
}
});

_createClass(SemiCircle, [{
key: 'render',
value: function render() {
return _react2.default.createElement(Shape, _extends({}, this.props, { ShapeClass: _progressbar2.default.SemiCircle }));
}
}]);

return SemiCircle;
}(_react.Component);

;

module.exports = {
Line: Line,
Expand Down
Loading

0 comments on commit 8ffd06c

Please sign in to comment.