# `<ixfx-labelled-range-input>`

A composite range input that pairs an editable label (`ixfx-editable-number`) with a slider (`ixfx-range-input`). The two controls are always in sync — dragging the slider updates the number, and editing the number moves the slider.

## Basic usage

```html
<ixfx-labelled-range-input label="Volume" value="0.5" min="0" max="1" step="0.01">
</ixfx-labelled-range-input>
```

## Layout

Layout is driven by a container query on the component's own height.

| Height          | Layout                          |
|-----------------|---------------------------------|
| >= 80px (default) | **Vertical** — label above slider |
| < 80px          | **Horizontal** — label beside slider |

The component defaults to `height: 100px`, so unconstrained usage shows the vertical layout. Constrain the height in your CSS to switch to horizontal.

### Force a layout with `--flow`

Override the container query entirely:

```html
<ixfx-labelled-range-input style="--flow: row" ...>   <!-- always horizontal -->
<ixfx-labelled-range-input style="--flow: column" ...> <!-- always vertical   -->
```

### Control label width (horizontal layout)

```html
<ixfx-labelled-range-input style="--label-width: 8em" ...>
```

## Mini mode

When the component is very small the label is hidden and only the slider is shown, with the tooltip forced on.

Mini mode activates when **both** of the following are true:
- `width < mini-width-threshold` (default 120px)
- `height < mini-height-threshold` (default 40px)

Override with a CSS variable:

```html
<ixfx-labelled-range-input style="--mini: 1" ...> <!-- always mini  -->
<ixfx-labelled-range-input style="--mini: 0" ...> <!-- never mini   -->
```

## Formatter

Apply a function to format the displayed value and tooltip. Set it as a JS property — it cannot be set as an HTML attribute.

```js
const el = document.querySelector('ixfx-labelled-range-input');
el.formatter = (v) => `${Math.round(Number(v))}%`;
```

The formatter receives the raw string value and returns the string to display. When set, it applies to both the editable-number label and the slider tooltip.

## Properties / attributes

| Attribute              | Type                                          | Default      | Description                                         |
|------------------------|-----------------------------------------------|--------------|-----------------------------------------------------|
| `label`                | `string`                                      | `""`         | Label text shown in the editable-number             |
| `value`                | `number`                                      | `0`          | Current value                                       |
| `min`                  | `number`                                      | `0`          | Minimum value                                       |
| `max`                  | `number`                                      | `1`          | Maximum value                                       |
| `step`                 | `number`                                      | `0.01`       | Step increment                                      |
| `drag-sensitivity`     | `number`                                      | `1`          | Steps per pixel when dragging the number label      |
| `precision`            | `number`                                      | `0`          | Decimal places shown                                |
| `orientation`          | `"horizontal" \| "vertical"`                  | `"horizontal"` | Slider track orientation                          |
| `tooltip`              | `boolean`                                     | `false`      | Show slider tooltip                                 |
| `tooltip-orientation`  | `"top" \| "right"`                            | `"top"`      | Tooltip position relative to the slider thumb       |
| `switch-height`        | `number`                                      | `80`         | Height (px) at which layout switches vertical↔horizontal |
| `mini-width-threshold` | `number`                                      | `120`        | Width (px) below which mini mode can activate       |
| `mini-height-threshold`| `number`                                      | `40`         | Height (px) below which mini mode can activate      |
| `display-text-logic`   | `"hidden" \| "show" \| "override" \| "transient"` | `"transient"` | Controls when label text vs value is shown    |
| `formatter`            | `(value: string) => string`                   | —            | JS property only — formats value for display and tooltip |

### `display-text-logic` values

| Value       | Behaviour                                              |
|-------------|--------------------------------------------------------|
| `transient` | Shows the label when idle, value on hover/interaction  |
| `show`      | Always shows the value                                 |
| `hidden`    | Always shows the label text, never the value           |
| `override`  | Label text replaces value at all times                 |

## Events

| Event    | Detail                    | Description                                              |
|----------|---------------------------|----------------------------------------------------------|
| `change` | `{ value: string }`       | Fired when the value is committed (slider release or number edit) |
| `input`  | `{ value: number }`       | Fired on every slider move                               |

Both events bubble and are composed (cross shadow boundary).

## CSS variables

### Layout

| Variable                 | Default      | Description                                               |
|--------------------------|--------------|-----------------------------------------------------------|
| `--height`               | `100px`      | Component height. Set to `100%` to fill a constrained parent |
| `--width`                | `auto`       | Component width                                           |
| `--min-height`           | `20px`       | Minimum height                                            |
| `--min-width`            | `50px`       | Minimum width                                             |
| `--flow`                 | *(container query)* | `row` or `column` — overrides the automatic layout |
| `--label-width`          | `5ch`        | Width of the editable-number in horizontal layout         |
| `--mini`                 | *(auto)*     | `1` to force mini mode, `0` to disable it                 |

### Label (passed to `ixfx-editable-number`)

| Variable              | Default                    | Description              |
|-----------------------|----------------------------|--------------------------|
| `--label-font-size`   | `var(--text-m)`            | Font size                |
| `--label-font-family` | `var(--font-family)`       | Font family              |
| `--label-color`       | `var(--surface-text)`      | Text colour              |
| `--label-muted-color` | `var(--surface-muted-text)`| Muted text colour        |
| `--label-padding`     | `var(--space-xs) var(--space-s)` | Padding             |
| `--label-radius`      | `var(--radius-s)`          | Border radius            |
| `--label-align`       | `center`                   | Text alignment           |

### Slider track (passed to `ixfx-range-input`)

| Variable                          | Default                  | Description                              |
|-----------------------------------|--------------------------|------------------------------------------|
| `--track-thickness`               | `1.5em`                  | Track cross-axis size                    |
| `--thumb-color`                   | `var(--surface-text)`    | Thumb colour                             |
| `--thumb-color-active`            | `var(--accent)`          | Thumb colour while active                |
| `--thumb-size`                    | `var(--track-thickness)` | Thumb size along the track axis          |
| `--thumb-thickness`               | `2em`                    | Thumb size on the cross axis             |
| `--thumb-radius`                  | `0`                      | Thumb border radius                      |
| `--thumb-border`                  | `none`                   | Thumb border                             |
| `--thumb-shadow`                  | `none`                   | Thumb box shadow                         |
| `--background-track`              | `var(--surface-ll)`      | Track background                         |
| `--background-track-hover`        | `--background-track`     | Track background on hover                |
| `--background-track-value`        | `var(--surface-hh)`      | Filled (value) portion of the track      |
| `--background-track-value-hover`  | `var(--accent)`          | Filled portion on hover                  |
| `--background-track-value-active` | `var(--accent)`          | Filled portion while dragging            |

## Examples

### Horizontal layout with percentage formatter

```html
<ixfx-labelled-range-input
  id="my-slider"
  label="Mix"
  value="0.75"
  style="height: 50px"
></ixfx-labelled-range-input>

<script type="module">
  document.querySelector('#my-slider').formatter = (v) =>
    `${Math.round(Number(v) * 100)}%`;
</script>
```

### Custom slider colours

```html
<ixfx-labelled-range-input
  label="Intensity"
  value="0.7"
  style="
    --background-track-value: linear-gradient(to right, hsl(200 80% 40%), hsl(260 80% 50%));
    --thumb-radius: 999px;
  "
></ixfx-labelled-range-input>
```

### Force mini mode

```html
<ixfx-labelled-range-input label="Vol" value="0.5" style="--mini: 1">
</ixfx-labelled-range-input>
```

### Listen for changes

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

// Committed value (slider release or number edit)
el.addEventListener('change', (e) => console.log(e.detail.value));

// Every slider move
el.addEventListener('input', (e) => console.log(e.detail.value));
```
