# `<ixfx-range-input>`

A label-free, fully styled range slider wrapping `<input type="range">`. Supports horizontal and vertical orientations, CSS variable theming, gradient fills, custom thumb shapes, and an optional value tooltip.

---

## Basic usage

```html
<ixfx-range-input value="0.5"></ixfx-range-input>
```

```js
const slider = document.querySelector('ixfx-range-input');
slider.addEventListener('input', e => console.log(e.detail.value));
```

---

## Attributes / properties

| Attribute / Property  | Type                        | Default        | Description                                      |
|-----------------------|-----------------------------|----------------|--------------------------------------------------|
| `value`               | `number`                    | `0`            | Current value within `min`..`max`                |
| `min`                 | `number`                    | `0`            | Minimum value                                    |
| `max`                 | `number`                    | `1`            | Maximum value                                    |
| `step`                | `number`                    | `0.01`         | Step increment                                   |
| `orientation`         | `"horizontal" \| "vertical"` | `"horizontal"` | Slider axis                                     |
| `tooltip`             | `boolean`                   | `false`        | Show value tooltip on hover/focus                |
| `tooltip-orientation` | `"top" \| "right"`          | `"top"`        | Tooltip position relative to thumb               |
| `labelFormatter`      | `(raw, scaled) => string`   | —              | JS property (not an attribute) — custom tooltip formatter. `raw` is the value within `min`..`max`; `scaled` is the normalised 0..1 position. |

---

## Events

Both events are `CustomEvent` instances with `{ bubbles: true, composed: true }`.

| Event    | `detail` type          | Description                                        |
|----------|------------------------|----------------------------------------------------|
| `input`  | `{ value: number }`    | Fires continuously while dragging                  |
| `change` | `{ value: number }`    | Fires once on release (same semantics as native)   |

`value` in both events is the raw value within `min`..`max` (not normalised).

---

## Sizing

The component fills whatever dimensions you give it via `--width` / `--height`, or explicit CSS sizing.

| CSS variable | Default (horizontal) | Default (vertical) | Description              |
|---|---|---|---|
| `--width`    | `200px`              | `2em`              | Component width          |
| `--height`   | `2em`                | `200px`            | Component height         |

```html
<!-- Full-width, default height -->
<ixfx-range-input style="--width:100%"></ixfx-range-input>

<!-- Tall horizontal slider -->
<ixfx-range-input style="--width:100%; --height:4em"></ixfx-range-input>

<!-- Vertical, filling a flex container -->
<div style="height:160px; display:flex; align-items:stretch">
  <ixfx-range-input orientation="vertical" style="--width:2em; --height:100%"></ixfx-range-input>
</div>
```

---

## Track CSS variables

| Variable                                    | Default                       | Description                              |
|---------------------------------------------|-------------------------------|------------------------------------------|
| `--track-thickness`                         | `100%`                        | Track cross-axis size (% of component height in horizontal mode) |
| `--background-track`                        | `var(--surface-ll)`           | Unfilled track background                |
| `--background-track-hover`                  | `--background-track`          | Unfilled track on hover                  |
| `--background-track-value`                  | `var(--surface-hh)`           | Filled track color (supports gradients)  |
| `--background-track-value-hover`            | `var(--accent)`               | Filled track on hover                    |
| `--background-track-value-active`           | `var(--accent)`               | Filled track while dragging              |

### Vertical-only overrides

When `orientation="vertical"` these take precedence over the horizontal vars (falling back to them when unset):

| Variable                                         | Falls back to                        |
|--------------------------------------------------|--------------------------------------|
| `--background-track-vertical`                    | `--background-track`                 |
| `--background-track-value-vertical`              | `--background-track-value`           |
| `--background-track-value-hover-vertical`        | `--background-track-value-hover`     |
| `--background-track-value-active-vertical`       | `--background-track-value-active`    |

---

## Thumb CSS variables

| Variable              | Default                   | Description                                     |
|-----------------------|---------------------------|-------------------------------------------------|
| `--thumb-thickness`   | `2em`                     | Thumb size along the track axis                 |
| `--thumb-size`        | `--track-thickness`       | Thumb size across the track axis                |
| `--thumb-color`       | `var(--surface-text)`     | Thumb fill at rest                              |
| `--thumb-color-active`| `var(--accent)`           | Thumb fill on hover / active                    |
| `--thumb-radius`      | `0`                       | `border-radius` of the thumb                    |
| `--thumb-border`      | `none`                    | `border` shorthand for the thumb                |
| `--thumb-shadow`      | `none`                    | `box-shadow` for the thumb                      |

### Using container query units for thumb sizing

Because the component uses `container-type: size` internally, you can use `cqh` (1% of component height) and `cqw` (1% of component width) for reliable, dimension-agnostic sizing:

```css
/* Thumb is always a square equal to the component height */
ixfx-range-input {
  --thumb-thickness: 100cqh;
  --thumb-size: 100cqh;
}

/* Thumb is 80% of component height */
ixfx-range-input {
  --thumb-thickness: 80cqh;
  --thumb-size: 80cqh;
}
```

For vertical sliders, use `cqw` (component width) to size the thumb relative to the narrow dimension:

```css
ixfx-range-input[orientation="vertical"] {
  --thumb-thickness: 100cqw;
  --thumb-size: 100cqw;
}
```

---

## Tooltip

Add the `tooltip` attribute to show the current value above the thumb on hover/focus.

```html
<!-- Default: shows value rounded to 2 decimal places -->
<ixfx-range-input tooltip value="0.5"></ixfx-range-input>

<!-- Integer range: step=1 → no decimal places shown -->
<ixfx-range-input tooltip min="0" max="100" step="1" value="42"></ixfx-range-input>

<!-- Vertical slider: show tooltip to the right of the thumb -->
<ixfx-range-input orientation="vertical" tooltip tooltip-orientation="right" value="0.6"></ixfx-range-input>
```

### Custom tooltip formatter

Assign a function to the `labelFormatter` JS property:

```js
const slider = document.querySelector('ixfx-range-input');
slider.labelFormatter = (rawValue, scaledValue) =>
  `${Math.round(scaledValue * 100)}%`;
```

- `rawValue` — the value within `min`..`max`
- `scaledValue` — normalised 0..1 position

---

## Examples

### Accent colour override

```css
.my-slider {
  --background-track-value: hsl(280 60% 35%);
  --background-track-value-hover: hsl(280 80% 55%);
  --background-track-value-active: hsl(280 80% 55%);
  --thumb-color-active: hsl(280 80% 65%);
}
```

```html
<ixfx-range-input class="my-slider" value="0.5" style="--width:100%"></ixfx-range-input>
```

### Gradient fill

The filled-track area uses a CSS mask, so any gradient set on `--background-track-value` shows through only up to the current value position.

```css
.gradient-fire {
  --background-track-value: linear-gradient(to right, hsl(50 100% 45%), hsl(15 90% 50%));
  --background-track-value-hover: linear-gradient(to right, hsl(55 100% 55%), hsl(15 100% 60%));
  --background-track-value-active: linear-gradient(to right, hsl(55 100% 55%), hsl(15 100% 60%));
}
```

### Pill thumb

```css
.pill {
  --thumb-radius: 999px;
  --thumb-thickness: 20px;
  --thumb-size: 200cqh;
}
```

### Circle dot thumb

```css
.dot {
  --thumb-thickness: 100cqh;
  --thumb-size: 100cqh;
  --thumb-radius: 50%;
}
```

### Ghost (outlined) thumb

```css
.ghost {
  --thumb-color: transparent;
  --thumb-color-active: transparent;
  --thumb-border: 2px solid var(--accent);
  --thumb-radius: 3px;
  --thumb-shadow: 0 0 6px var(--accent);
}
```

### Orientation-specific colours

Both orientations can share one CSS class, with the vertical variant overriding only what it needs:

```css
.dual-color {
  --background-track-value: hsl(210 70% 40%);              /* horizontal → blue */
  --background-track-value-vertical: hsl(30 70% 45%);      /* vertical → orange */
}
```

```html
<ixfx-range-input class="dual-color" value="0.6" style="--width:100%"></ixfx-range-input>
<ixfx-range-input class="dual-color" orientation="vertical" value="0.6"></ixfx-range-input>
```

### Listening to events

```js
const slider = document.querySelector('ixfx-range-input');

// Fires on every move
slider.addEventListener('input', ({ detail }) => {
  console.log('moving:', detail.value);
});

// Fires once on release
slider.addEventListener('change', ({ detail }) => {
  console.log('settled:', detail.value);
});
```

### Setting value programmatically

```js
slider.value = 0.75;
```
