Files
icehrm/web/node_modules/rc-rate/lib/Star.js
2020-05-20 18:47:29 +02:00

164 lines
6.3 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var Star =
/*#__PURE__*/
function (_React$Component) {
_inherits(Star, _React$Component);
function Star() {
var _getPrototypeOf2;
var _this;
_classCallCheck(this, Star);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Star)).call.apply(_getPrototypeOf2, [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);
});
_defineProperty(_assertThisInitialized(_this), "onKeyDown", function (e) {
var _this$props3 = _this.props,
onClick = _this$props3.onClick,
index = _this$props3.index;
if (e.keyCode === 13) {
onClick(e, index);
}
});
return _this;
}
_createClass(Star, [{
key: "getClassName",
value: function getClassName() {
var _this$props4 = this.props,
prefixCls = _this$props4.prefixCls,
index = _this$props4.index,
value = _this$props4.value,
allowHalf = _this$props4.allowHalf,
focused = _this$props4.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,
onKeyDown = this.onKeyDown;
var _this$props5 = this.props,
disabled = _this$props5.disabled,
prefixCls = _this$props5.prefixCls,
character = _this$props5.character,
characterRender = _this$props5.characterRender,
index = _this$props5.index,
count = _this$props5.count,
value = _this$props5.value;
var start = _react["default"].createElement("li", {
className: this.getClassName()
}, _react["default"].createElement("div", {
onClick: disabled ? null : onClick,
onKeyDown: disabled ? null : onKeyDown,
onMouseMove: disabled ? null : onHover,
role: "radio",
"aria-checked": value > index ? 'true' : 'false',
"aria-posinset": index + 1,
"aria-setsize": count,
tabIndex: 0
}, _react["default"].createElement("div", {
className: "".concat(prefixCls, "-first")
}, character), _react["default"].createElement("div", {
className: "".concat(prefixCls, "-second")
}, character)));
if (characterRender) {
start = characterRender(start, this.props);
}
return start;
}
}]);
return Star;
}(_react["default"].Component);
exports["default"] = Star;
_defineProperty(Star, "propTypes", {
value: _propTypes["default"].number,
index: _propTypes["default"].number,
prefixCls: _propTypes["default"].string,
allowHalf: _propTypes["default"].bool,
disabled: _propTypes["default"].bool,
onHover: _propTypes["default"].func,
onClick: _propTypes["default"].func,
character: _propTypes["default"].node,
characterRender: _propTypes["default"].func,
focused: _propTypes["default"].bool,
count: _propTypes["default"].number
});