# `LedgerUI.Components.Rating`
[🔗](https://github.com/devaction-labs/ledger_ui/blob/v0.2.0/lib/ledger_ui/components/rating.ex#L1)

A star rating: read-only, with a fractional value and the count of reviews, or interactive, as
a group of native radios; and `rating_distribution/1`, the summary with the average and a bar
per grade.

    <.rating value={4.5} />
    <.rating value={4.2} show_value count={38} />
    <.rating id="service" name="service" label="Como foi o atendimento?" value={@grade} on_change="rate" />
    <.rating field={@form[:grade]} label="Nota" />
    <.rating_distribution average={4.5} counts={[800, 310, 110, 40, 24]} />

A fractional value is drawn in half stars (the nearest half). The read-only rating is one
`role="img"` with the text `4,5 de 5 estrelas` (`aria_label` gives another).

Interactive ratings are a `radiogroup` of `max` native radios (Tab enters the group, the arrow
keys choose, the form submits `name`). `on_change` is an event name (pushed with
`%{"id", "value"}`, to `target` when given) or a `%JS{}`. The `LedgerUI.Rating` hook
(`priv/static/ledger_ui/hooks/rating.js`) previews the grade under the pointer.

# `rating`

Renders a rating.
## Attributes

* `id` (`:string`) - Defaults to `nil`.
* `name` (`:string`) - Defaults to `nil`.
* `value` (`:any`)
* `field` (`Phoenix.HTML.FormField`) - Defaults to `nil`.
* `max` (`:integer`) - Defaults to `5`.
* `variant` (`:string`) - Defaults to `"solid"`. Must be one of `"solid"`, or `"outline"`.
* `size` (`:string`) - Defaults to `"md"`. Must be one of `"sm"`, `"md"`, or `"lg"`.
* `count` (`:integer`) - Defaults to `nil`.
* `show_value` (`:boolean`) - Defaults to `false`.
* `decimal` (`:string`) - Defaults to `","`.
* `interactive` (`:boolean`) - Defaults to `nil`.
* `label` (`:string`) - Defaults to `nil`.
* `aria_label` (`:string`) - Defaults to `nil`.
* `help` (`:string`) - Defaults to `nil`.
* `errors` (`:list`) - Defaults to `[]`.
* `disabled` (`:boolean`) - Defaults to `false`.
* `loop` (`:boolean`) - Animated demo: adds `m-loop` and a staggered `--dl` delay per star (read-only, no on/off state). Defaults to `false`.
* `on_change` (`:any`) - Defaults to `nil`.
* `target` (`:any`) - Defaults to `nil`.
* `class` (`:any`) - Defaults to `nil`.
* Global attributes are accepted.

# `rating_distribution`

The summary of a rating: the average, its stars, the total and a bar per grade.
## Attributes

* `counts` (`:any`) (required) - A list, best grade first, or a map `%{grade => count}`.
* `average` (`:any`) - Defaults to `nil`.
* `total` (`:integer`) - Defaults to `nil`.
* `unit` (`:string`) - Defaults to `"avaliações"`.
* `decimal` (`:string`) - Defaults to `","`.
* `class` (`:any`) - Defaults to `nil`.
* Global attributes are accepted.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
