UNPKG

@kiwicom/orbit-components

Version:

Orbit-components is a React component library which provides developers with the easiest possible way of building Kiwi.com’s products.

52 lines (49 loc) 1.99 kB
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"; import * as React from "react"; import styled from "styled-components"; import StarEmpty from "../icons/StarEmpty"; import StarFull from "../icons/StarFull"; import defaultTheme from "../defaultTheme"; import MAX_STARS from "./consts"; import { ICON_COLORS, ICON_SIZES } from "../Icon/consts"; import useTranslate from "../hooks/useTranslate"; var StyledRatingStars = styled.div.withConfig({ displayName: "RatingStars__StyledRatingStars", componentId: "vyfznx-0" })(["display:flex;flex-direction:row;justify-content:flex-start;flex-shrink:0;svg{flex-shrink:0;}"]); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198 StyledRatingStars.defaultProps = { theme: defaultTheme }; var RatingStars = function RatingStars(_ref) { var rating = _ref.rating, _ref$size = _ref.size, size = _ref$size === void 0 ? ICON_SIZES.SMALL : _ref$size, dataTest = _ref.dataTest, _ref$color = _ref.color, color = _ref$color === void 0 ? ICON_COLORS.PRIMARY : _ref$color, _ref$showEmpty = _ref.showEmpty, showEmpty = _ref$showEmpty === void 0 ? false : _ref$showEmpty; var translate = useTranslate(); var ratingRounded = Math.round(rating); var starsCount = showEmpty ? MAX_STARS : ratingRounded; return /*#__PURE__*/React.createElement(StyledRatingStars, { "data-test": dataTest, size: size, "aria-label": translate("ratingstar_description", { number: ratingRounded, total: starsCount }) }, Array.apply(void 0, _toConsumableArray(Array(starsCount))).map(function (_, index) { var key = "star-".concat(index); return index <= ratingRounded - 1 ? /*#__PURE__*/React.createElement(StarFull, { key: key, size: size, color: color }) : /*#__PURE__*/React.createElement(StarEmpty, { key: key, size: size, color: color }); })); }; export default RatingStars;