# `ixfx-rating`

A rating input that renders a row of glyphs (star / heart / square). Supports half-step increments, keyboard control, per-rank theming via CSS variables, and prominence-based hover feedback. Clicking the current value clears it to `0` (unrated).

```html
<ixfx-rating value="3"></ixfx-rating>
<ixfx-rating allow-half value="2.5"></ixfx-rating>
<ixfx-rating max="10" value="7"></ixfx-rating>
<ixfx-rating variant="heart" value="4"></ixfx-rating>
<ixfx-rating variant="square" value="3"></ixfx-rating>
<ixfx-rating disabled value="3"></ixfx-rating>
<ixfx-rating readonly value="3"></ixfx-rating>
```

### Properties / attributes

| Attribute / Property | Type | Default | Description |
|---|---|---|---|
| `value` | `number` | `0` | Current rating. `0` means unrated. Clamped `0..max` |
| `max` | `number` | `5` | Number of glyphs rendered |
| `allow-half` / `allowHalf` | `boolean` | `false` | When set, pointer position within a glyph selects `n` or `n+0.5`; keyboard step becomes `0.5` |
| `variant` | `"star"` \| `"heart"` \| `"square"` | `"star"` | Glyph shape |
| `disabled` | `boolean` | `false` | Disables interaction; muted via prominence filter and `pointer-events: none` |
| `readonly` | `boolean` | `false` | Prevents interaction but retains full visual prominence |

### Events

Both events bubble and are `composed`.

| Event | Detail | Description |
|---|---|---|
| `input` | `{ value: number, oldValue: number }` | Fired on commit |
| `change` | `{ value: number, oldValue: number }` | Fired on commit (same timing as `input` for this component) |

Clicking the glyph that already equals `value` clears to `0`. Both events carry the previous value as `oldValue`.

```ts
import type { RatingChangeEvent } from './rating.js';
el.addEventListener('change', (e: RatingChangeEvent) => {
  console.log(e.detail.value, e.detail.oldValue);
});
el.addEventListener('input', (e: RatingChangeEvent) => {
  console.log(e.detail.value, e.detail.oldValue);
});
```

### Interaction

**Pointer:** hovering previews the value that would be set (filled glyphs use the hover colour, host gains prominence saturation). Click commits; clicking the active value clears to `0`. With `allow-half`, the left/right half of a glyph resolves to `n+0.5` / `n+1`.

**Keyboard** (when focused, not `disabled`/`readonly`):

| Key | Action |
|---|---|
| `ArrowRight` / `ArrowUp` | Increase by `1` (or `0.5` with `allow-half`) |
| `ArrowLeft` / `ArrowDown` | Decrease by `1` (or `0.5`) |
| `Home` | Clear to `0` |
| `End` | Set to `max` |
| `0`–`9` | Set to that number (clamped to `max`) |

Accessibility: `role="slider"` with `aria-valuenow` / `aria-valuemin="0"` / `aria-valuemax` / `aria-disabled` / `aria-readonly`; `tabindex` is `0` when interactive, `-1` when `disabled` or `readonly`.

### CSS custom properties

| Property | Default | Description |
|---|---|---|
| `--ixfx-rating-size` | `1.5rem` | Glyph width/height |
| `--ixfx-rating-gap` | `0.2rem` | Gap between glyphs |
| `--ixfx-rating-color` | `var(--surface-4)` | Idle glyph colour |
| `--ixfx-rating-color-active` | `var(--accent)` | Filled glyph colour |
| `--ixfx-rating-color-hover` | `var(--accent)` | Hover-preview glyph colour |
| `--ixfx-rating-<n>-color` | — | Per-rank idle override (e.g. `--ixfx-rating-3-color`) |
| `--ixfx-rating-<n>-color-active` | — | Per-rank filled override |
| `--ixfx-rating-<n>-color-hover` | — | Per-rank hover override |

Per-rank variables are set **outside** the shadow DOM (e.g. on the `ixfx-rating` element or a parent) and bridged via inline `var()` fallbacks on each glyph, so they pierce the shadow boundary without extra plumbing.

```html
<style>
  ixfx-rating.saturated {
    --ixfx-rating-1-color-active: oklch(70% 0.05 280);
    --ixfx-rating-5-color-active: oklch(60% 0.25 30);
  }
</style>
<ixfx-rating class="saturated" value="4"></ixfx-rating>
```

### Prominence

Includes `prominenceStyles` from `src/styles/prominence.ts`: idle state is desaturated/dimmed, `:hover` / `:focus-within` raises opacity and saturation, `:active` removes the filter, `disabled` applies a heavy mute. `readonly` explicitly resets the filter so it remains visually full. Override via `--prominence-*` variables if needed.

### TypeScript types

```ts
import type { RatingElement, RatingVariant, RatingChangeDetail, RatingChangeEvent } from 'ixfxfun-components';
```

### Implementation notes

* Half-fill is a stacked pair ofidentical SVGs — a background glyph plus an absolutely-positioned foreground glyph clipped with `clip-path: inset(0 50% 0 0)`.
* Glyph paths are inline `d` strings (`star` is a 5-point star, `heart` a cardioid-like path, `square` a rect) sharing a single `24×24` viewBox.
* Preview is local `@state _preview: number | null`, derived into render via `_effective() = _preview ?? value`; `pointerleave` on the host clears it.
