Skip to content

[component] Add Rating component - #3696

Closed
leomega1 wants to merge 2 commits into
meta:mainfrom
leomega1:add-rating-component
Closed

leomega1 wants to merge 2 commits into
meta:mainfrom
leomega1:add-rating-component

Conversation

@leomega1

@leomega1 leomega1 commented Jul 8, 2026

Copy link
Copy Markdown

Summary

Adds a new Rating component to @astryxdesign/core — an accessible star rating input for capturing or displaying a score. This fills a genuine gap in the library (no rating/score input existed; Collapsible/CollapsibleGroup already cover accordions, so that was ruled out).

What it does

  • Controlled & uncontrolled value (value / defaultValue)
  • Half-icon precision (hasHalfIcons) plus continuous fractional rendering in read-only mode (e.g. 4.3)
  • isReadOnly display mode and isDisabled state
  • Configurable max, size (sm/md/lg), and color (warning/accent/neutral)
  • Custom icons via icon / emptyIcon (defaults to a star glyph)
  • Optional value label (hasValueLabel) with a custom formatValueLabel
  • Hidden input for native form submission (htmlName)

Accessibility

  • Interactive ratings expose the WAI-ARIA slider role (single tab stop; ←/→/↑/↓ adjust, Home/End jump to bounds) with aria-valuemin/max/now/text.
  • Read-only ratings use role="img" with a descriptive aria-label.
  • This mirrors the existing Slider component's a11y conventions.
  • :hover guarded under @media (hover: hover); respects prefers-reduced-motion.

Conventions followed

  • Theme tokens only (no raw px/shadow); themeProps('rating', …) theme target (astryx-rating, visual props size/color, states readonly/disabled).
  • displayName set; StyleX styling; React 19 ref-as-prop.

Testing

  • 16 colocated unit tests, all passing (Rating.test.tsx).
  • pnpm -F @astryxdesign/core build, eslint (0 warnings), pnpm check:changesets, and pnpm sync:exports:check all pass.

Included

  • packages/core/src/Rating/ — component, tests, typed docs (docs / docsZh / docsDense), index.ts
  • apps/storybook/stories/Rating.stories.tsx — Default, HalfStars, ReadOnly, Sizes, Colors, Disabled, WithHiddenLabel
  • packages/cli/templates/blocks/components/Rating/ — CLI showcase block
  • .changeset/rating-component.md — [component] category

Screenshots

Rendered locally in the doc site at /components/Rating — add a screenshot here.

An accessible star rating input for capturing or displaying a score.

- Controlled and uncontrolled value (value / defaultValue)
- Half-icon precision (hasHalfIcons) and fractional read-only display
- Read-only (isReadOnly) and disabled (isDisabled) states
- Configurable max, size (sm/md/lg), and color (warning/accent/neutral)
- Custom filled/empty icons; defaults to a star glyph
- Optional value label and custom formatter
- Hidden input for native form submission (htmlName)

Accessibility: interactive ratings use the WAI-ARIA slider role with
arrow-key / Home / End support; read-only ratings use role="img" with a
descriptive label — mirroring the existing Slider component.

Includes colocated tests (16), typed docs (docs/docsZh/docsDense),
Storybook stories, and a CLI showcase block.
@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown

@leomega1 is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

@cixzhang cixzhang added area:cli needs:code-review High-risk change (new package/component/API) — needs human code review before merge needs:design-review Affects visuals — Design should review labels Jul 8, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 8, 2026
Make Rating a single source of truth for scores across products.

- Modes: interactive (slider) and display (read-only img)
- Configurable max and precision (1, 0.5, 0.25, 0.1) with clean fractional values
- Icons from the project icon system (solid filled clipped over outline empty);
  default star vendored from Heroicons; custom filled/empty/partial supported
- Semantic colors (gold/brand/warning/positive/neutral) or any CSS color
- Label placement (top/bottom/left/right/hidden), value text, review count,
  descriptive labels (Poor…Excellent), tooltips
- Density (compact/comfortable/spacious) and animations (fill/scale/bounce)
- States incl. loading skeleton; RTL-aware fill and pointer math
- Full a11y: slider role, arrows/Home/End/Space/Enter, aria-value*, live region
- Forwards pass-through props (id/data-*/aria-*); onChange fires only on change

Grouped config (icons) and enums keep the API clean. Colocated tests (25),
typed docs, and Storybook stories covering every variant.
@github-actions github-actions Bot added the community Authored by a community contributor (not on the eng/design team) label Jul 11, 2026

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, @leomega1 — and welcome. There's genuinely careful work here: the Slider-modeled slider/img a11y, colocated tests, controlled/uncontrolled handling, and a changeset. Strong first-contribution instinct.

I can't merge a new @astryxdesign/core component from a PR alone, though. Every new core component goes through a specification protocol before code is written — issue first, API agreed in the thread, then build. This isn't a formality: core API decisions need cross-codebase usage evidence (which props are actually used and how often, how the concept maps across the systems we're converging, where the industry has settled). A finished PR skips the step where that shaping happens, and the API shape is the expensive thing to get wrong once it's public and versioned. (See Contributing with AI Assistants → "Building components without prior discussion" and the Component Specification Protocol.)

If you'd like to pursue a Rating component, the path that lands:

  1. File an issue describing the problem, not the solution — who needs a rating input, on what surfaces, how it's handled today, and any usage evidence. (There's no tracking issue for this yet.)
  2. Once the API is agreed in that thread, the build is the easy part — and much of what you've already written should transfer.

Would you like to go through that process? If so, open the issue and I'm happy to help shape the spec. If we don't hear back we'll let this PR close out, but the door's open either way.

Thanks again for the effort.

@cixzhang

Copy link
Copy Markdown
Contributor

It's been some time so closing for now. Please file an issue if you'd like to collaborate on a new component!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants