|
1 | 1 | (function (global, factory) { |
2 | 2 | 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); |
4 | 4 | } 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')); |
6 | 6 | } else { |
7 | 7 | var mod = { |
8 | 8 | exports: {} |
9 | 9 | }; |
10 | | - factory(mod, global.react, global.reactDom, global.lodash, global.progressbar); |
| 10 | + factory(mod.exports, global.react, global.propTypes, global.lodash, global.progressbar); |
11 | 11 | global.main = mod.exports; |
12 | 12 | } |
13 | | -})(this, function (module, React, ReactDom, isEqual, ProgressBar) { |
| 13 | +})(this, function (exports, _react, _propTypes, _lodash, _progressbar) { |
14 | 14 | 'use strict'; |
15 | 15 |
|
| 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 | + |
16 | 35 | var _extends = Object.assign || function (target) { |
17 | 36 | for (var i = 1; i < arguments.length; i++) { |
18 | 37 | var source = arguments[i]; |
|
27 | 46 | return target; |
28 | 47 | }; |
29 | 48 |
|
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); |
63 | 63 | } |
| 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 | + }(); |
64 | 72 |
|
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 | + } |
68 | 77 |
|
69 | | - componentDidMount: function componentDidMount() { |
70 | | - this._create(this.props); |
71 | | - }, |
| 78 | + return call && (typeof call === "object" || typeof call === "function") ? call : self; |
| 79 | + } |
72 | 80 |
|
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 | + } |
76 | 85 |
|
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 |
80 | 92 | } |
| 93 | + }); |
| 94 | + if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; |
| 95 | + } |
81 | 96 |
|
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); |
86 | 99 |
|
87 | | - if (props.initialAnimate) { |
88 | | - if (oldProps) { |
89 | | - this._setProgress(oldProps.progress); |
90 | | - } |
| 100 | + function Shape() { |
| 101 | + _classCallCheck(this, Shape); |
91 | 102 |
|
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 | + } |
96 | 105 |
|
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 | + } |
99 | 120 |
|
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; |
104 | 124 | } |
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); |
106 | 150 |
|
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 | + } |
110 | 155 |
|
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 | + } |
114 | 160 |
|
115 | | - _setText: function _setText(text) { |
116 | | - if (text) { |
117 | | - this.state.shape.setText(text); |
| 161 | + this.setText(nextProps.text); |
118 | 162 | } |
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 | + }; |
121 | 205 |
|
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 | + }; |
128 | 215 |
|
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 | + }; |
135 | 219 |
|
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 | + }; |
142 | 223 |
|
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 })); |
147 | 226 | }; |
148 | 227 | }); |
0 commit comments