@molecule/app-rating-display-svelte
Feature · rating-display · App (browser) · v1.1.2 · Apache-2.0
Read-only and interactive star rating display with half-star support
npm install @molecule/app-rating-display-svelteHow it works
@molecule/app-rating-display-svelte is a ready-made rating-display feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.
<script lang="ts">
import { RatingDisplay } from '@molecule/app-rating-display-svelte'
let rating = $state(0)
const scrollToReviews = (): void => {
document.getElementById('reviews')?.scrollIntoView()
}
</script>
<!-- Read-only with review count, then interactive: the user picks a rating. -->
<RatingDisplay value={4.5} reviewCount={128} onReviewsClick={scrollToReviews} />
<RatingDisplay value={rating} size="lg" onChange={(v) => (rating = v)} />Works with: @molecule/app-svelte, @molecule/app-ui, @molecule/app-ui-svelte
Reference
Svelte star-rating display.
Exports RatingDisplay — fractional star rendering (inline SVG), optional
review count tail, optional interactive mode via onChange. It is the
Svelte counterpart of @molecule/app-rating-display-react: same props
(React names), same DOM for the same input.
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Quick Start
<script lang="ts">
import { RatingDisplay } from '@molecule/app-rating-display-svelte'
let rating = $state(0)
const scrollToReviews = (): void => {
document.getElementById('reviews')?.scrollIntoView()
}
</script>
<!-- Read-only with review count, then interactive: the user picks a rating. -->
<RatingDisplay value={4.5} reviewCount={128} onReviewsClick={scrollToReviews} />
<RatingDisplay value={rating} size="lg" onChange={(v) => (rating = v)} />
Type
feature
Installation
npm install @molecule/app-rating-display-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte
API
Interfaces
RatingDisplayProps
Props for RatingDisplay.
interface RatingDisplayProps {
/** Rating value (0–max). Fractional supported. */
value: number
/** Maximum rating. Defaults to 5. */
max?: number
/** Optional review count shown after the stars. */
reviewCount?: number
/**
* Called when the review-count is clicked (renders it as a button). React
* passes the click event, so this receives it too.
*/
onReviewsClick?: (event?: MouseEvent) => void
/** Size preset. */
size?: 'sm' | 'md' | 'lg'
/** Interactive mode — star clicks call `onChange(starIndex + 1)`. */
onChange?: (value: number) => void
/** Accessible label override; defaults to the translated `Rating: {value} of {max}`. */
ariaLabel?: string
/** Extra classes. */
className?: string
}
Constants
RatingDisplay
const RatingDisplay: LegacyComponentType
Injection Notes
Requirements
Peer dependencies:
@molecule/app-svelte^3.5.0 || ^4.0.0@molecule/app-ui^1.0.1@molecule/app-ui-svelte^1.1.0svelte^5.0.0
Runtime Dependencies
@molecule/app-svelte@molecule/app-ui@molecule/app-ui-sveltesvelte
Stars are inline SVG filled with currentColor — set a text color on the
wrapper (e.g. a warning/amber token) to tint them; unfilled portions render
at 25% opacity of the same color. Accessible labels are translated through
useTranslation(), matching the React package and following a locale switch:
the container label (ratingDisplay.aria.rating, overridable via ariaLabel)
and the per-star "Rate N of M" button labels in interactive mode
(ratingDisplay.aria.rate). Requires a wired ClassMap bond.
Translations
Translation strings are provided by @molecule/app-locales-rating-display.