UNPKG

fomantic-ui-react

Version:

Fomantic-UI React -- A React Component Library.

97 lines (84 loc) 3.51 kB
/** * fomantic-ui-react v0.0.1-alpha.10 * (c) 2022 FireLoong <fireloong@foxmail.com> * @license MIT */ import { _ as _defineProperty, a as _objectWithoutProperties } from '../_chunks/dep-9f1126c1.js'; import { _ as _slicedToArray } from '../_chunks/dep-dc9b74a1.js'; import classNames from 'classnames'; import _ from 'lodash'; import React, { useState, createElement } from 'react'; import { Icon } from '../icon/index.js'; import '../icon/Icon.js'; import './style/css.js'; import '../icon/type.js'; var _excluded = ["as", "className", "icon", "max", "rating", "color", "disabled", "size"]; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } var Rating = function Rating(_ref) { var _ref$as = _ref.as, as = _ref$as === void 0 ? "div" : _ref$as, className = _ref.className, _ref$icon = _ref.icon, icon = _ref$icon === void 0 ? "star" : _ref$icon, _ref$max = _ref.max, max = _ref$max === void 0 ? 1 : _ref$max, _ref$rating = _ref.rating, rating = _ref$rating === void 0 ? 0 : _ref$rating, _ref$color = _ref.color, color = _ref$color === void 0 ? "black" : _ref$color, disabled = _ref.disabled, size = _ref.size, props = _objectWithoutProperties(_ref, _excluded); var _useState = useState(false), _useState2 = _slicedToArray(_useState, 2), selected = _useState2[0], setSelected = _useState2[1]; var _useState3 = useState(-1), _useState4 = _slicedToArray(_useState3, 2), selectedIndex = _useState4[0], setSelectedIndex = _useState4[1]; var _useState5 = useState(rating), _useState6 = _slicedToArray(_useState5, 2), ratingVal = _useState6[0], setRatingVal = _useState6[1]; if (!as) { as = "div"; } return /*#__PURE__*/createElement(as, _objectSpread({ className: classNames("ui", size, color, { disabled: disabled }, "rating", { selected: selected }, className), onMouseLeave: function onMouseLeave() { if (!disabled) { setSelectedIndex(-1); setSelected(false); } } }, props), _.times(max, function (i) { return /* @__PURE__ */React.createElement(Icon, { key: i, name: icon, className: classNames({ active: ratingVal > i, selected: selected && selectedIndex >= i }), onClick: function onClick() { if (!disabled) { setRatingVal(i + 1); } }, onMouseEnter: function onMouseEnter() { if (!disabled) { setSelectedIndex(i); setSelected(true); } } }); })); }; Rating.displayName = "Rating"; export { Rating as default }; //# sourceMappingURL=Rating.js.map