import { SvelteComponentTyped } from "svelte"; import type { SvelteHTMLElements } from "svelte/elements"; type $RestProps = SvelteHTMLElements["div"]; type $Props = { /** * Specify the rating, from `0` (not rated) to `max`. * A `readonly` rating can be fractional, such as `4.5`. * @default 0 */ value?: number; /** * Specify the number of stars * @default 5 */ max?: number; /** * Specify the legend text. * Alternatively, use the named slot "legendChildren". * @default "" */ legendText?: string; /** * Set to `true` to visually hide the legend * @default false */ hideLegend?: boolean; /** * Specify the helper text * @default "" */ helperText?: string; /** * Set to `true` to indicate an invalid state * @default false */ invalid?: boolean; /** * Specify the invalid state text * @default "" */ invalidText?: string; /** * Set to `true` to indicate a warning state * @default false */ warn?: boolean; /** * Specify the warning state text * @default "" */ warnText?: string; /** * Set to `true` to disable the rating * @default false */ disabled?: boolean; /** * Set to `true` to require a rating. */ required?: boolean | undefined; /** * Set to `true` to display the rating instead of asking for one, such as * a product's average. Unlike `readonly` on other fields, a read-only * rating is an image named by the legend and the value: it isn't * focusable or submitted with a form, and it fills partial stars. * @default false */ readonly?: boolean; /** * Set to `true` so clicking the current rating clears it. * @default false */ allowDeselect?: boolean; /** * Set the size of the stars: 16, 24 or 32 pixels. * @default "md" */ size?: "sm" | "md" | "lg"; /** * Specify the text that names a rating, read by screen readers for each * star and for a read-only rating. * @default (value, max) => `${value} out of ${max} stars` */ valueText?: (value: number, max: number) => string; /** * Specify a name attribute for the radio inputs, for form submission. */ name?: string | undefined; /** * Specify the id of a form element outside the component to associate * the radio inputs with. */ form?: string | undefined; /** * Set an id for the rating's legend and messages * @default uniqueId() */ id?: string; legendChildren?: (this: void) => void; /** Text beside the stars, such as a word for the rating or a review count. `value` previews a hovered star. */ children?: (this: void, ...args: [{ value: number }]) => void; [key: `data-${string}`]: unknown; }; export type StarRatingProps = Omit<$RestProps, keyof $Props> & $Props; export default class StarRating extends SvelteComponentTyped< StarRatingProps, { change: CustomEvent }, { /** Text beside the stars, such as a word for the rating or a review count. `value` previews a hovered star. */ default: { value: number }; legendChildren: Record; } > {}