Sha256: 0abca94bbe1645790d6c2e7b8ab0d5d42412ca9d4e114900d0ef2f288d304bfa

Contents?: true

Size: 1.93 KB

Versions: 427

Compression:

Stored size: 1.93 KB

Contents

import React from "react"
import { GlobalProps } from '../../utilities/globalProps'
import Icon from '../../pb_icon/_icon'
import Flex from '../../pb_flex/_flex'
import { getStarIconObject } from "../stars/utils"

type StarRatingDisplayProps = {
    backgroundType: "fill" | "outline",
    colorOption: "yellow" | "primary" | "subtle" | "outline",
    dark: boolean,
    denominator: number,
    layoutOption: "default" | "number" | "onestar",
    rating: number,
    size: "xs" | "sm" | "md" | "lg",
} & GlobalProps

const StarRatingDisplay = (props: StarRatingDisplayProps) => {
    const {
        backgroundType,
        colorOption,
        dark,
        denominator,
        layoutOption,
        rating,
        size,
    } = props
    const denominatorStyle = layoutOption === "onestar" ? 1 : denominator
    const activeStars = Math.round(rating) > denominatorStyle ? denominatorStyle : Math.round(rating)
    const emptyStars = denominatorStyle - Math.round(rating) < 0 ? 0 : denominatorStyle - Math.round(rating)
    const starIcon = getStarIconObject(backgroundType, colorOption, dark, size)

    return (
        <Flex className="star_flex_area">
            {[...Array(activeStars)].map((_, index) => (
                <React.Fragment key={index}>
                    <Icon
                        className={starIcon[colorOption].className}
                        customIcon={starIcon[colorOption].icon as unknown as { [key: string]: SVGElement }}
                    />
                </React.Fragment>
            ))}
            {[...Array(emptyStars)].map((_, index) => (
                <React.Fragment key={index}>
                    <Icon
                        className={starIcon[backgroundType].className}
                        customIcon={starIcon[backgroundType].icon  as unknown as { [key: string]: SVGElement }}
                    />
                </React.Fragment>
            ))}
        </Flex>
    )
}

export default StarRatingDisplay

Version data entries

427 entries across 427 versions & 1 rubygems

Version Path
playbook_ui-14.11.1.pre.alpha.PLAY17445539 app/pb_kits/playbook/pb_star_rating/subcomponents/_star_rating_display.tsx
playbook_ui-14.11.1.pre.alpha.PBNTR798datepickerturbo5537 app/pb_kits/playbook/pb_star_rating/subcomponents/_star_rating_display.tsx
playbook_ui-14.11.1.pre.alpha.pbntr703collapsiblerowsrails5536 app/pb_kits/playbook/pb_star_rating/subcomponents/_star_rating_display.tsx
playbook_ui-14.11.1.pre.alpha.PLAY1751pbcontenttagpt25529 app/pb_kits/playbook/pb_star_rating/subcomponents/_star_rating_display.tsx
playbook_ui-14.11.1.pre.alpha.PBNTR7495495 app/pb_kits/playbook/pb_star_rating/subcomponents/_star_rating_display.tsx
playbook_ui-14.12.0.pre.rc.11 app/pb_kits/playbook/pb_star_rating/subcomponents/_star_rating_display.tsx
playbook_ui-14.12.0.pre.rc.10 app/pb_kits/playbook/pb_star_rating/subcomponents/_star_rating_display.tsx
playbook_ui-14.12.0.pre.rc.9 app/pb_kits/playbook/pb_star_rating/subcomponents/_star_rating_display.tsx
playbook_ui-14.12.0.pre.rc.8 app/pb_kits/playbook/pb_star_rating/subcomponents/_star_rating_display.tsx
playbook_ui-14.12.0.pre.rc.7 app/pb_kits/playbook/pb_star_rating/subcomponents/_star_rating_display.tsx
playbook_ui-14.11.1.pre.alpha.play1724darkmodeauditmap5437 app/pb_kits/playbook/pb_star_rating/subcomponents/_star_rating_display.tsx
playbook_ui-14.11.1.pre.alpha.PBNTR719listdraggablesimple5432 app/pb_kits/playbook/pb_star_rating/subcomponents/_star_rating_display.tsx
playbook_ui-14.11.1.pre.alpha.PBNTR768stickyrightcolumn5431 app/pb_kits/playbook/pb_star_rating/subcomponents/_star_rating_display.tsx
playbook_ui-14.12.0.pre.rc.6 app/pb_kits/playbook/pb_star_rating/subcomponents/_star_rating_display.tsx
playbook_ui-14.11.1.pre.alpha.PBNTR718simiplifieddraggablereact5415 app/pb_kits/playbook/pb_star_rating/subcomponents/_star_rating_display.tsx
playbook_ui-14.11.1.pre.alpha.play1724darkmodeauditmap5413 app/pb_kits/playbook/pb_star_rating/subcomponents/_star_rating_display.tsx
playbook_ui-14.12.0.pre.rc.5 app/pb_kits/playbook/pb_star_rating/subcomponents/_star_rating_display.tsx
playbook_ui-14.11.1.pre.alpha.play1724darkmodeauditmap5409 app/pb_kits/playbook/pb_star_rating/subcomponents/_star_rating_display.tsx
playbook_ui-14.11.1.pre.alpha.PBNTR718simiplifieddraggablereact5400 app/pb_kits/playbook/pb_star_rating/subcomponents/_star_rating_display.tsx
playbook_ui-14.11.1.pre.alpha.PBNTR718simiplifieddraggablereact5392 app/pb_kits/playbook/pb_star_rating/subcomponents/_star_rating_display.tsx