@findify/react-components
Version:
Findify react UI components
46 lines (43 loc) • 1.71 kB
JavaScript
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; }
/**
* @module components/Cards/Product/Rating
*/
import cx from 'classnames';
import Icon from "../../../Icon";
import Text from "../../../Text";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var styles = {
"rating": "findify-components--cards--product--rating__rating",
"stars": "findify-components--cards--product--rating__stars",
"star": "findify-components--cards--product--rating__star",
"filled": "findify-components--cards--product--rating__filled",
"count": "findify-components--cards--product--rating__count"
};
/** Array of empty stars */
var itemsArray = Array.from(Array(5).keys());
/** List of props that Rating component accepts */
export default (function (_ref) {
var value = _ref.value,
count = _ref.count,
className = _ref.className,
_ref$theme = _ref.theme,
theme = _ref$theme === void 0 ? styles : _ref$theme;
return /*#__PURE__*/_jsxs("div", {
className: cx(theme.rating, className),
children: [/*#__PURE__*/_jsx("div", {
className: theme.stars,
children: itemsArray.map(function (index) {
return /*#__PURE__*/_jsx(Icon, {
name: "Star",
title: "Star",
className: cx(theme.star, _defineProperty({}, theme.filled, index < value))
}, index);
})
}), !!count ? /*#__PURE__*/_jsxs(Text, {
className: theme.count,
mode: "secondary-uppercase",
children: ["(", count, ")"]
}) : null]
});
});