UNPKG

choerodon-ui

Version:

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

145 lines (120 loc) 4.31 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; 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); }; } import React, { Component } from 'react'; import PropTypes from 'prop-types'; var Star = /*#__PURE__*/ function (_Component) { _inherits(Star, _Component); var _super = _createSuper(Star); function Star() { var _this; _classCallCheck(this, Star); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _super.call.apply(_super, [this].concat(args)); _defineProperty(_assertThisInitialized(_this), "onHover", function (e) { var _this$props = _this.props, onHover = _this$props.onHover, index = _this$props.index; onHover(e, index); }); _defineProperty(_assertThisInitialized(_this), "onClick", function (e) { var _this$props2 = _this.props, onClick = _this$props2.onClick, index = _this$props2.index; onClick(e, index); }); return _this; } _createClass(Star, [{ key: "getClassName", value: function getClassName() { var _this$props3 = this.props, prefixCls = _this$props3.prefixCls, index = _this$props3.index, value = _this$props3.value, allowHalf = _this$props3.allowHalf, focused = _this$props3.focused; var starValue = index + 1; var className = prefixCls; if (value === 0 && index === 0 && focused) { className += " ".concat(prefixCls, "-focused"); } else if (allowHalf && value + 0.5 === starValue) { className += " ".concat(prefixCls, "-half ").concat(prefixCls, "-active"); if (focused) { className += " ".concat(prefixCls, "-focused"); } } else { className += starValue <= value ? " ".concat(prefixCls, "-full") : " ".concat(prefixCls, "-zero"); if (starValue === value && focused) { className += " ".concat(prefixCls, "-focused"); } } return className; } }, { key: "render", value: function render() { var onHover = this.onHover, onClick = this.onClick; var _this$props4 = this.props, disabled = _this$props4.disabled, prefixCls = _this$props4.prefixCls, character = _this$props4.character; return React.createElement("li", { className: this.getClassName(), onClick: disabled ? null : onClick, onMouseMove: disabled ? null : onHover }, React.createElement("div", { className: "".concat(prefixCls, "-first") }, character), React.createElement("div", { className: "".concat(prefixCls, "-second") }, character)); } }]); return Star; }(Component); _defineProperty(Star, "propTypes", { value: PropTypes.number, index: PropTypes.number, prefixCls: PropTypes.string, allowHalf: PropTypes.bool, disabled: PropTypes.bool, onHover: PropTypes.func, onClick: PropTypes.func, character: PropTypes.node, focused: PropTypes.bool }); export { Star as default }; //# sourceMappingURL=Star.js.map