Skip to main content

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)​

Open Default in Storybook

Full Rating​

Open Full Rating in Storybook

Half Stars​

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

Open Half Rating in Storybook

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 />
Open Out Of Ten in Storybook

With Numeric Value​

Open With Value in Storybook

Three Star Max​

Open Three Star Max in Storybook

See Also​