メインコンテンツまでスキップ

Rating

Every example on this page is live, drawn by the library's Storybook, where you can also change its props and see the result.

A star-based rating display using Unicode star characters.

Import​

import { Rating } from "~lib/data-display/rating";

Props​

NameTypeRequiredDefaultDescription
valuenumberYesN/ARating (0 to scale)
maxnumberNo5How many stars to draw
scalenumberNomaxThe most the rating can be, such as 10
precision1 | 0.5No1Fill to the nearest whole star, or the nearest half
size"sm" | "md" | "lg"No"md"Text size
showValuebooleanNofalseShow numeric value

Examples​

Default (3 of 5)​

StorybookでDefaultを開く

Full Rating​

StorybookでFull Ratingを開く

Half Stars​

Set precision={0.5} to fill the stars to the nearest half.

StorybookでHalf Ratingを開く

Out of Ten​

When a rating is out of ten (or any other number), pass that as scale. The stars fill in proportion, and showValue prints the rating out of ten, as people know it.

<Rating value={6.9} scale={10} precision={0.5} showValue />
StorybookでOut Of Tenを開く

With Numeric Value​

StorybookでWith Valueを開く

Three Star Max​

StorybookでThree Star Maxを開く

See Also​