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.

37 lines (35 loc) 1.1 kB
import * as React from "react"; import styled from "styled-components"; import StarEmpty from "../icons/StarEmpty"; import StarFull from "../icons/StarFull"; import defaultTokens from "../defaultTokens"; import MAX_STARS from "./consts"; import { ICON_COLORS, ICON_SIZES } from "../Icon/consts"; const 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;}"]); StyledRatingStars.defaultProps = { theme: defaultTokens }; const RatingStars = ({ rating, size = ICON_SIZES.SMALL, dataTest, color = ICON_COLORS.PRIMARY }) => React.createElement(StyledRatingStars, { "data-test": dataTest, size: size }, Array(...Array(MAX_STARS)).map((_, index) => { const key = `star-${index}`; return index <= Math.round(rating) - 1 ? React.createElement(StarFull, { key: key, size: size, color: color }) : React.createElement(StarEmpty, { key: key, size: size, color: color }); })); export default RatingStars;