UNPKG

@smitch/fluid

Version:

A Next/React ui-component libray.

25 lines (24 loc) 2.25 kB
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { twMerge } from 'tailwind-merge'; import { round } from '@smitch/js-lib'; import { Badge } from '..'; import { FaStar, FaThumbsUp, FaFaceSmile, FaHeart, FaCheck, FaThumbsDown, FaFaceFrown, } from 'react-icons/fa6'; var Ratings = function (_a) { var _b = _a.className, className = _b === void 0 ? '' : _b, rating = _a.rating, range = _a.range, _c = _a.icon, icon = _c === void 0 ? 'star' : _c, customIcon = _a.customIcon, _d = _a.spacing, spacing = _d === void 0 ? '0' : _d, _e = _a.shape, shape = _e === void 0 ? 'circle' : _e, _f = _a.size, size = _f === void 0 ? 'md' : _f, _g = _a.ratingsBackground, ratingsBackground = _g === void 0 ? 'info' : _g, _h = _a.ratingsColor, ratingsColor = _h === void 0 ? 'dark' : _h; rating = round(rating); if (rating === 0) rating = 1; if (!range) range = rating; return (_jsxs("div", { className: 'ratings-wrapper inline-block', children: [_jsx("div", { className: twMerge("ratings group relative flex gap-".concat(spacing), className), title: "Rating: ".concat(rating, " out of ").concat(range), children: __spreadArray([], new Array(range), true).map(function (_el, index) { return (_jsx(Badge, { layout: shape, size: size, badgeBackground: ratingsBackground, badgeColor: ratingsColor, className: "static ".concat(rating <= index ? 'grayscale' : ''), children: customIcon ? (customIcon) : icon === 'smiley' ? (_jsx(FaFaceSmile, {})) : icon === 'frown' ? (_jsx(FaFaceFrown, {})) : icon === 'thumb' ? (_jsx(FaThumbsUp, {})) : icon === 'thumbdown' ? (_jsx(FaThumbsDown, {})) : icon === 'heart' ? (_jsx(FaHeart, {})) : icon === 'check' ? (_jsx(FaCheck, {})) : (_jsx(FaStar, {})) }, index)); }) }), _jsx("p", { className: 'sr-only', children: "Rating: ".concat(rating, "/").concat(range) })] })); }; export default Ratings;