1 | 'use strict';
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.default = undefined;
|
5 |
|
6 | var _extends2 = require('babel-runtime/helpers/extends');
|
7 |
|
8 | var _extends3 = _interopRequireDefault(_extends2);
|
9 |
|
10 | var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
|
11 |
|
12 | var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
|
13 |
|
14 | var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
|
15 |
|
16 | var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
|
17 |
|
18 | var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
|
19 |
|
20 | var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
|
21 |
|
22 | var _inherits2 = require('babel-runtime/helpers/inherits');
|
23 |
|
24 | var _inherits3 = _interopRequireDefault(_inherits2);
|
25 |
|
26 | var _class, _temp;
|
27 |
|
28 | var _react = require('react');
|
29 |
|
30 | var _react2 = _interopRequireDefault(_react);
|
31 |
|
32 | var _propTypes = require('prop-types');
|
33 |
|
34 | var _propTypes2 = _interopRequireDefault(_propTypes);
|
35 |
|
36 | var _classnames = require('classnames');
|
37 |
|
38 | var _classnames2 = _interopRequireDefault(_classnames);
|
39 |
|
40 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
41 |
|
42 | var VIEWBOX_WIDTH = 100;
|
43 | var HALF_VIEWBOX_WIDTH = VIEWBOX_WIDTH / 2;
|
44 | var DEFAULT_STROKE_WIDTH = 8;
|
45 |
|
46 | var viewBox = '0 0 ' + VIEWBOX_WIDTH + ' ' + VIEWBOX_WIDTH;
|
47 |
|
48 | var Circle = (_temp = _class = function (_Component) {
|
49 | (0, _inherits3.default)(Circle, _Component);
|
50 |
|
51 | function Circle(props) {
|
52 | (0, _classCallCheck3.default)(this, Circle);
|
53 |
|
54 | var _this = (0, _possibleConstructorReturn3.default)(this, _Component.call(this, props));
|
55 |
|
56 | _this._underlayRefHandler = function (ref) {
|
57 | _this.underlay = ref;
|
58 | };
|
59 |
|
60 | _this._overlayRefHandler = function (ref) {
|
61 | _this.overlay = ref;
|
62 | };
|
63 |
|
64 | _this.state = {
|
65 | underlayStrokeWidth: DEFAULT_STROKE_WIDTH,
|
66 | overlayStrokeWidth: DEFAULT_STROKE_WIDTH
|
67 | };
|
68 | return _this;
|
69 | }
|
70 |
|
71 | Circle.prototype.componentDidMount = function componentDidMount() {
|
72 | if (this.underlay && this.overlay) {
|
73 |
|
74 | this.setState({
|
75 | underlayStrokeWidth: this._getCssValue(this.underlay, 'stroke-width') || DEFAULT_STROKE_WIDTH,
|
76 | overlayStrokeWidth: this._getCssValue(this.overlay, 'stroke-width') || DEFAULT_STROKE_WIDTH
|
77 | });
|
78 | }
|
79 | };
|
80 |
|
81 | Circle.prototype._getCssValue = function _getCssValue(dom, name) {
|
82 | var css = window.getComputedStyle(dom).getPropertyValue(name);
|
83 | var regExp = /(\d*)px/g;
|
84 | var result = regExp.exec(css);
|
85 |
|
86 | return Array.isArray(result) ? Number(result[1]) : 0;
|
87 | };
|
88 |
|
89 | Circle.prototype._computeOverlayStrokeDashOffset = function _computeOverlayStrokeDashOffset() {
|
90 | var _state = this.state,
|
91 | underlayStrokeWidth = _state.underlayStrokeWidth,
|
92 | overlayStrokeWidth = _state.overlayStrokeWidth;
|
93 |
|
94 | var overlayRadius = HALF_VIEWBOX_WIDTH - overlayStrokeWidth / 2 - (underlayStrokeWidth - overlayStrokeWidth) / 2;
|
95 | var overlayLen = Math.PI * 2 * overlayRadius;
|
96 | return (VIEWBOX_WIDTH - this.props.percent) / VIEWBOX_WIDTH * overlayLen;
|
97 | };
|
98 |
|
99 | Circle.prototype._getPath = function _getPath(radius) {
|
100 | return 'M ' + HALF_VIEWBOX_WIDTH + ',' + HALF_VIEWBOX_WIDTH + ' m 0,-' + radius + ' a ' + radius + ',' + radius + ' 0 1 1 0,' + 2 * radius + ' a ' + radius + ',' + radius + ' 0 1 1 0,-' + 2 * radius;
|
101 | };
|
102 |
|
103 | Circle.prototype.render = function render() {
|
104 | var _classNames, _classNames2;
|
105 |
|
106 | var _props = this.props,
|
107 | prefix = _props.prefix,
|
108 | size = _props.size,
|
109 | state = _props.state,
|
110 | percent = _props.percent,
|
111 | className = _props.className,
|
112 | textRender = _props.textRender,
|
113 | progressive = _props.progressive,
|
114 | color = _props.color,
|
115 | backgroundColor = _props.backgroundColor,
|
116 | rtl = _props.rtl,
|
117 | others = (0, _objectWithoutProperties3.default)(_props, ['prefix', 'size', 'state', 'percent', 'className', 'textRender', 'progressive', 'color', 'backgroundColor', 'rtl']);
|
118 | var _state2 = this.state,
|
119 | underlayStrokeWidth = _state2.underlayStrokeWidth,
|
120 | overlayStrokeWidth = _state2.overlayStrokeWidth;
|
121 |
|
122 |
|
123 |
|
124 | var underlayRadius = HALF_VIEWBOX_WIDTH - underlayStrokeWidth / 2;
|
125 | var underlayPath = this._getPath(underlayRadius);
|
126 |
|
127 |
|
128 | var overlayRadius = HALF_VIEWBOX_WIDTH - overlayStrokeWidth / 2 - (underlayStrokeWidth - overlayStrokeWidth) / 2;
|
129 | var overlayPath = this._getPath(overlayRadius);
|
130 | var overlayLen = Math.PI * 2 * overlayRadius;
|
131 | var overlayStrokeDasharray = overlayLen + 'px ' + overlayLen + 'px';
|
132 | var overlayStrokeDashoffset = this._computeOverlayStrokeDashOffset() + 'px';
|
133 |
|
134 | var suffixText = textRender(percent, { rtl: rtl });
|
135 |
|
136 | var wrapCls = (0, _classnames2.default)((_classNames = {}, _classNames[prefix + 'progress-circle'] = true, _classNames[prefix + 'progress-circle-show-info'] = suffixText, _classNames['' + (prefix + size)] = size, _classNames[className] = className, _classNames));
|
137 |
|
138 | var pathCls = (0, _classnames2.default)((_classNames2 = {}, _classNames2[prefix + 'progress-circle-overlay'] = true, _classNames2[prefix + 'progress-circle-overlay-' + state] = !color && !progressive && state, _classNames2[prefix + 'progress-circle-overlay-started'] = !color && progressive && percent <= 30, _classNames2[prefix + 'progress-circle-overlay-middle'] = !color && progressive && percent > 30 && percent < 80, _classNames2[prefix + 'progress-circle-overlay-finishing'] = !color && progressive && percent >= 80, _classNames2));
|
139 |
|
140 | var underlayStyle = { stroke: backgroundColor };
|
141 |
|
142 | return _react2.default.createElement(
|
143 | 'div',
|
144 | (0, _extends3.default)({
|
145 | className: wrapCls,
|
146 | dir: rtl ? 'rtl' : undefined,
|
147 | role: 'progressbar',
|
148 | 'aria-valuenow': percent,
|
149 | 'aria-valuemin': '0',
|
150 | 'aria-valuemax': '100'
|
151 | }, others),
|
152 | _react2.default.createElement(
|
153 | 'svg',
|
154 | {
|
155 | className: prefix + 'progress-circle-container',
|
156 | viewBox: viewBox
|
157 | },
|
158 | _react2.default.createElement('path', {
|
159 | className: prefix + 'progress-circle-underlay',
|
160 | d: underlayPath,
|
161 | fillOpacity: '0',
|
162 | ref: this._underlayRefHandler,
|
163 | style: underlayStyle
|
164 | }),
|
165 | _react2.default.createElement('path', {
|
166 | className: pathCls,
|
167 | d: overlayPath,
|
168 | fillOpacity: '0',
|
169 | strokeDasharray: overlayStrokeDasharray,
|
170 | strokeDashoffset: overlayStrokeDashoffset,
|
171 | ref: this._overlayRefHandler,
|
172 | stroke: color
|
173 | })
|
174 | ),
|
175 | suffixText ? _react2.default.createElement(
|
176 | 'div',
|
177 | { className: prefix + 'progress-circle-text' },
|
178 | suffixText
|
179 | ) : null
|
180 | );
|
181 | };
|
182 |
|
183 | return Circle;
|
184 | }(_react.Component), _class.propTypes = {
|
185 | size: _propTypes2.default.oneOf(['small', 'medium', 'large']),
|
186 | percent: _propTypes2.default.number,
|
187 | state: _propTypes2.default.oneOf(['normal', 'success', 'error']),
|
188 | progressive: _propTypes2.default.bool,
|
189 | textRender: _propTypes2.default.func,
|
190 | prefix: _propTypes2.default.string,
|
191 | className: _propTypes2.default.string,
|
192 | color: _propTypes2.default.string,
|
193 | backgroundColor: _propTypes2.default.string,
|
194 | rtl: _propTypes2.default.bool
|
195 | }, _temp);
|
196 | Circle.displayName = 'Circle';
|
197 | exports.default = Circle;
|
198 | module.exports = exports['default']; |
\ | No newline at end of file |