@molecule/app-rating-form-svelte

Feature · rating-form · App (browser) · v1.1.4 · Apache-2.0

Interactive star rating + textarea + submit form for collecting reviews

npm install @molecule/app-rating-form-svelte

npm · Source on GitHub

How it works

@molecule/app-rating-form-svelte is a ready-made rating-form 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 { RatingForm } from '@molecule/app-rating-form-svelte'

  async function submitReview(rating: number, comment: string): Promise<void> {
    await fetch('/api/reviews', { method: 'POST', body: JSON.stringify({ rating, comment }) })
  }
</script>

<RatingForm
  title="Leave a review"
  onSubmit={submitReview}
  requireComment={false}
  submitLabel="Submit review"
/>

Works with: @molecule/app-svelte, @molecule/app-ui, @molecule/app-ui-svelte

Reference

Svelte interactive star-rating + comment form.

Exports RatingForm — a star radiogroup, a comment textarea and a submit button. It is the Svelte counterpart of @molecule/app-rating-form-react: same props (React names) and the 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.ts JSDoc, not this file.

Quick Start

<script lang="ts">
  import { RatingForm } from '@molecule/app-rating-form-svelte'

  async function submitReview(rating: number, comment: string): Promise<void> {
    await fetch('/api/reviews', { method: 'POST', body: JSON.stringify({ rating, comment }) })
  }
</script>

<RatingForm
  title="Leave a review"
  onSubmit={submitReview}
  requireComment={false}
  submitLabel="Submit review"
/>

Type

feature

Installation

npm install @molecule/app-rating-form-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte

API

Interfaces

RatingFormProps

Props accepted by RatingForm — the same props (React names) as @molecule/app-rating-form-react, with node-valued props as snippets (or plain strings).

interface RatingFormProps {
  /** Called with the submitted rating + optional comment. */
  onSubmit: (rating: number, comment: string) => void | Promise<void>
  /** Maximum stars. Defaults to 5. */
  max?: number
  /** Initial rating (uncontrolled). */
  defaultRating?: number
  /** Whether a comment is required. Defaults to false. */
  requireComment?: boolean
  /** Form heading — a snippet or a plain string. */
  title?: Snippet | string
  /** Comment placeholder. */
  commentPlaceholder?: string
  /** Submit-button label — a snippet or a plain string. */
  submitLabel?: Snippet | string
  /** Extra classes. */
  className?: string
}

Constants

RatingForm

const RatingForm: 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.6.0
  • svelte ^5.0.0

Runtime Dependencies

  • @molecule/app-svelte
  • @molecule/app-ui
  • @molecule/app-ui-svelte
  • svelte

Companion locale bond: @molecule/app-locales-rating-form. The submit button stays disabled until a star rating is selected, and requireComment blocks submission on blank comments silently (no inline error is rendered). Rejected onSubmit promises propagate — handle errors in your handler. Requires a bonded ClassMap and @molecule/app-svelte's i18n provider above it.

Translations

Translation strings are provided by @molecule/app-locales-rating-form.