UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

149 lines (131 loc) 5.55 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectSpread from "@babel/runtime/helpers/objectSpread2"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _inherits from "@babel/runtime/helpers/inherits"; import _createSuper from "@babel/runtime/helpers/createSuper"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; var _excluded = ["prefixCls", "strokeWidth", "trailWidth", "strokeColor", "percent", "trailColor", "strokeLinecap", "style", "className"]; /* eslint react/prop-types: 0 */ import React, { Component } from 'react'; import enhancer from './enhancer'; import { defaultProps } from './types'; var Circle = /*#__PURE__*/function (_Component) { _inherits(Circle, _Component); var _super = _createSuper(Circle); function Circle() { _classCallCheck(this, Circle); return _super.apply(this, arguments); } _createClass(Circle, [{ key: "getPathStyles", value: function getPathStyles() { var _this$props = this.props, percent = _this$props.percent, strokeWidth = _this$props.strokeWidth, _this$props$gapDegree = _this$props.gapDegree, gapDegree = _this$props$gapDegree === void 0 ? 0 : _this$props$gapDegree, gapPosition = _this$props.gapPosition; var radius = 50 - strokeWidth / 2; var beginPositionX = 0; var beginPositionY = -radius; var endPositionX = 0; var endPositionY = -2 * radius; switch (gapPosition) { case 'left': beginPositionX = -radius; beginPositionY = 0; endPositionX = 2 * radius; endPositionY = 0; break; case 'right': beginPositionX = radius; beginPositionY = 0; endPositionX = -2 * radius; endPositionY = 0; break; case 'bottom': beginPositionY = radius; endPositionY = 2 * radius; break; default: } var pathString = "M 50,50 m ".concat(beginPositionX, ",").concat(beginPositionY, "\n a ").concat(radius, ",").concat(radius, " 0 1 1 ").concat(endPositionX, ",").concat(-endPositionY, "\n a ").concat(radius, ",").concat(radius, " 0 1 1 ").concat(-endPositionX, ",").concat(endPositionY); var len = Math.PI * 2 * radius; var trailPathStyle = { strokeDasharray: "".concat(len - gapDegree, "px ").concat(len, "px"), strokeDashoffset: "-".concat(gapDegree / 2, "px"), transition: 'stroke-dashoffset .3s ease 0s, stroke-dasharray .3s ease 0s, stroke .3s' }; var strokePathStyle = { strokeDasharray: "".concat(percent / 100 * (len - gapDegree), "px ").concat(len, "px"), strokeDashoffset: "-".concat(gapDegree / 2, "px"), transition: 'stroke-dashoffset .3s ease 0s, stroke-dasharray .3s ease 0s, stroke .3s, stroke-width .06s ease .3s' // eslint-disable-line }; return { pathString: pathString, trailPathStyle: trailPathStyle, strokePathStyle: strokePathStyle }; } }, { key: "render", value: function render() { var _this = this; var _this$props2 = this.props, prefixCls = _this$props2.prefixCls, strokeWidth = _this$props2.strokeWidth, trailWidth = _this$props2.trailWidth, strokeColor = _this$props2.strokeColor, percent = _this$props2.percent, trailColor = _this$props2.trailColor, strokeLinecap = _this$props2.strokeLinecap, style = _this$props2.style, className = _this$props2.className, restProps = _objectWithoutProperties(_this$props2, _excluded); var pathStyles = this.getPathStyles(); var pathString = pathStyles.pathString; var trailPathStyle = pathStyles.trailPathStyle, strokePathStyle = pathStyles.strokePathStyle; trailPathStyle = trailColor ? _objectSpread(_objectSpread({}, trailPathStyle), {}, { stroke: trailColor }) : trailPathStyle; strokePathStyle = strokeColor ? _objectSpread(_objectSpread({}, strokePathStyle), {}, { stroke: strokeColor }) : strokePathStyle; delete restProps.percent; delete restProps.gapDegree; delete restProps.gapPosition; return /*#__PURE__*/React.createElement("svg", _extends({ className: "".concat(prefixCls, "-circle ").concat(className), viewBox: "0 0 100 100", style: style }, restProps), /*#__PURE__*/React.createElement("path", { className: "".concat(prefixCls, "-circle-trail"), d: pathString, stroke: trailColor, strokeWidth: trailWidth || strokeWidth, fillOpacity: "0", style: trailPathStyle }), /*#__PURE__*/React.createElement("path", { className: "".concat(prefixCls, "-circle-path"), d: pathString, strokeLinecap: strokeLinecap, stroke: strokeColor, strokeWidth: this.props.percent === 0 ? 0 : strokeWidth, fillOpacity: "0", ref: function ref(path) { _this.path = path; }, style: strokePathStyle })); } }]); return Circle; }(Component); _defineProperty(Circle, "defaultProps", _objectSpread(_objectSpread({}, defaultProps), {}, { gapPosition: 'top' })); export default enhancer(Circle); //# sourceMappingURL=Circle.js.map