Rost

← All components

component

Rating

Stars out of five: a score to read, or one to give. Lit stars in the warning yellow, the rest in Input's edge grey.

In code Contract: review Guidance: proposed Contract on GitHub Figma 773:127 As markdown

Try it

Every variant

Default

Hover, press or tab to one to see the other 1 states.

Install

npx github:Runceanu/rost add rating

It lands in src/rost/rating/, with what it needs and its contract. Install has the rest.

When to use

  • A score to read

    A review's stars next to its text, an average next to a count: 4.5 from 120 reviews.

  • A score to give

    Asking how something went, in one tap, at the end of a flow.

When not to use

Behaviour

Read-only, it lights value of five stars, halves included. Giving a score, pointing at a star lights the stars up to it, and a press gives that score; pressing the score already given takes it back to 0.

Accessibility

  • Element

    Read-only, the stars are role="img" named 3 out of 5. Giving a score, it's role="radiogroup" of five role="radio" buttons named 1 star to 5 stars, the ARIA pattern for one choice in a row.

  • Name

    label names the group.

  • Keyboard

    Tab reaches the given score, or the first star when there's none. Left and Right, Up and Down move the score by one, Home and End to 1 and 5.

  • Focus

    focus-ring around all five, on :focus-visible, while the lit stars show where the focus is.

  • Colour

    The lit yellow is 9:1 on the dark page, the unlit grey 4.3:1, so an unlit star still reads as a star.

Content

Pair a read-only score with its number and its count, since five stars can't show 4.3.

Props

PropTypeValuesDefault
value number
label string
onValueChange node

States: Default, Focus.

Values

Straight from the contract. Each value sits next to its token, because six tokens here all come out as #3a3a3a and the colour alone can't tell you which one is right.

Never changes

root

  • width 120px no token yet
  • height 24px spacing/size/small

displayinline-block · positionrelative · vertical-alignmiddle

track

  • mask url(./icon-star.svg) left center / var(--spacing-size-small) var(--spacing-size-small) repeat-x on purpose: The icon file, repeated at spacing/size/small.
  • background #747573 rating/off

displayblock · positionabsolute · inset0

fill

  • mask url(./icon-star.svg) left center / var(--spacing-size-small) var(--spacing-size-small) repeat-x on purpose: The icon file, repeated at spacing/size/small.
  • background #fda50d rating/on

displayblock · positionabsolute · left0 · top0 · height100%

options

displayflex · positionabsolute · inset0

option

displayblock · flex1 1 0 · height100% · padding0 · bordernone · backgroundtransparent · outlinenone · cursorpointer

focus-ring

  • border-width 2px spacing/outline/medium
  • border-radius 8px spacing/radius/small

displaynone · positionabsolute · insetcalc(-1 * var(--spacing-gap-2xsmall)) · border-stylesolid · pointer-eventsnone

Only in some variants

These don't change: they're just set in some variants and not others.

Focus

  • focus-ring.border-color #00d669 rating/focus-ring
  • focus-ring.display block layout