choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
208 lines (169 loc) • 7.5 kB
JavaScript
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _enhancer = _interopRequireDefault(require("./enhancer"));
var _types = require("./types");
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 = (0, _getPrototypeOf2["default"])(Derived),
result;
if (isNativeReflectConstruct()) {
var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return (0, _possibleConstructorReturn2["default"])(this, result);
};
}
var Circle =
/*#__PURE__*/
function (_Component) {
(0, _inherits2["default"])(Circle, _Component);
var _super = _createSuper(Circle);
function Circle() {
(0, _classCallCheck2["default"])(this, Circle);
return _super.apply(this, arguments);
}
(0, _createClass2["default"])(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 = (0, _objectWithoutProperties2["default"])(_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 ? (0, _objectSpread2["default"])({}, trailPathStyle, {
stroke: trailColor
}) : trailPathStyle;
strokePathStyle = strokeColor ? (0, _objectSpread2["default"])({}, strokePathStyle, {
stroke: strokeColor
}) : strokePathStyle;
delete restProps.percent;
delete restProps.gapDegree;
delete restProps.gapPosition;
return _react["default"].createElement("svg", (0, _extends2["default"])({
className: "".concat(prefixCls, "-circle ").concat(className),
viewBox: "0 0 100 100",
style: style
}, restProps), _react["default"].createElement("path", {
className: "".concat(prefixCls, "-circle-trail"),
d: pathString,
stroke: trailColor,
strokeWidth: trailWidth || strokeWidth,
fillOpacity: "0",
style: trailPathStyle
}), _react["default"].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;
}(_react.Component);
(0, _defineProperty2["default"])(Circle, "propTypes", (0, _objectSpread2["default"])({}, _types.propTypes, {
gapPosition: _propTypes["default"].oneOf(['top', 'bottom', 'left', 'right'])
}));
(0, _defineProperty2["default"])(Circle, "defaultProps", (0, _objectSpread2["default"])({}, _types.defaultProps, {
gapPosition: 'top'
}));
var _default = (0, _enhancer["default"])(Circle);
exports["default"] = _default;
//# sourceMappingURL=Circle.js.map