UNPKG

choerodon-ui

Version:

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

189 lines (162 loc) 6.58 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 _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; function _createSuper(Derived) { function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } return function () { var Super = _getPrototypeOf(Derived), result; if (isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } /* eslint react/prop-types: 0 */ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import enhancer from './enhancer'; import { defaultProps, propTypes } 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, ["prefixCls", "strokeWidth", "trailWidth", "strokeColor", "percent", "trailColor", "strokeLinecap", "style", "className"]); var _this$getPathStyles = this.getPathStyles(), pathString = _this$getPathStyles.pathString; var _this$getPathStyles2 = this.getPathStyles(), trailPathStyle = _this$getPathStyles2.trailPathStyle, strokePathStyle = _this$getPathStyles2.strokePathStyle; trailPathStyle = trailColor ? _objectSpread({}, trailPathStyle, { stroke: trailColor }) : trailPathStyle; strokePathStyle = strokeColor ? _objectSpread({}, strokePathStyle, { stroke: strokeColor }) : strokePathStyle; delete restProps.percent; delete restProps.gapDegree; delete restProps.gapPosition; return React.createElement("svg", _extends({ className: "".concat(prefixCls, "-circle ").concat(className), viewBox: "0 0 100 100", style: style }, restProps), React.createElement("path", { className: "".concat(prefixCls, "-circle-trail"), d: pathString, stroke: trailColor, strokeWidth: trailWidth || strokeWidth, fillOpacity: "0", style: trailPathStyle }), 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, "propTypes", _objectSpread({}, propTypes, { gapPosition: PropTypes.oneOf(['top', 'bottom', 'left', 'right']) })); _defineProperty(Circle, "defaultProps", _objectSpread({}, defaultProps, { gapPosition: 'top' })); export default enhancer(Circle); //# sourceMappingURL=Circle.js.map