# `ixfx-editable-label` & `ixfx-editable-number`

Inline editable text components. `ixfx-editable-number` extends `ixfx-editable-label` with drag-to-adjust and fill-bar visualization.

---

## `ixfx-editable-label`

An inline text label that can be edited in place.

### Modes

| `mode` attribute | Behaviour |
|---|---|
| `label` (default) | Renders as plain text; click to enter edit mode |
| `editor` | Always renders as a box; click or focus activates editing |

### Attributes

| Attribute | Type | Default | Description |
|---|---|---|---|
| `mode` | `label \| editor` | `label` | Display mode |
| `entry-mode` | `free \| text \| number \| percent` | `free` | Character filter during input |
| `value` | string | `""` | Current value |
| `disabled` | boolean | — | Disables interaction |
| `placeholder` | string | `""` | Shown when value is empty |

**Entry modes:**
- `free` — no restrictions
- `text` — letters and spaces only
- `number` — digits, `.`, `-`
- `percent` — digits, `.`, `%` (strips `%` on commit; appends `%` on display)

### JavaScript Properties

These are set on the element object, not as HTML attributes.

```js
const el = document.querySelector('ixfx-editable-label');

// Custom commit validator — return false to reject and revert
el.validator = (value) => value.trim().length >= 3;

// Transform committed value for display only (stored value unchanged)
el.formatter = (value) => value.toUpperCase();

// Override displayed text entirely (editing shows raw value)
el.displayText = '★ Hidden ★';
el.displayText = undefined; // clear override
```

### Events

| Event | Detail | When |
|---|---|---|
| `change` | `{ value: string }` | On commit (Enter or blur); not fired if value unchanged |

```js
el.addEventListener('change', (e) => {
  console.log(e.detail.value);
});
```

The event bubbles and is composed (crosses shadow DOM boundaries).

### CSS Variables

| Variable | Default | Description |
|---|---|---|
| `--label-font-size` | `var(--text-m, 12px)` | Font size |
| `--label-font-family` | `var(--font-family, system-ui)` | Font family |
| `--label-color` | `var(--surface-text)` | Text colour |
| `--label-muted-color` | `var(--surface-muted-text)` | Placeholder colour |
| `--label-padding` | `var(--space-xs, 3px) var(--space-s, 4px)` | Inner padding |
| `--label-radius` | `var(--radius-s, 3px)` | Border radius |
| `--label-align` | `center` | Text alignment: `left`, `center`, or `right` |

### Keyboard

| Key | Action |
|---|---|
| `Enter` | Commit value |
| `Escape` | Cancel and revert |

### Usage Examples

**Basic label (click to edit):**
```html
<ixfx-editable-label value="Hello"></ixfx-editable-label>
```

**Always-visible editor box:**
```html
<ixfx-editable-label mode="editor" value="Edit me"></ixfx-editable-label>
```

**Numbers only with placeholder:**
```html
<ixfx-editable-label
  mode="editor"
  entry-mode="number"
  placeholder="0"
  value="42"
></ixfx-editable-label>
```

**Custom validator and formatter:**
```html
<ixfx-editable-label id="name" value="Ada"></ixfx-editable-label>
<script>
  const el = document.querySelector('#name');
  el.validator = (v) => v.trim().length > 0;
  el.formatter = (v) => v.trim();
</script>
```

**Currency display:**
```html
<ixfx-editable-label id="price" entry-mode="number" value="9.99"></ixfx-editable-label>
<script>
  document.querySelector('#price').formatter =
    (v) => isNaN(parseFloat(v)) ? v : `$${parseFloat(v).toFixed(2)}`;
</script>
```

---

## `ixfx-editable-number`

Extends `ixfx-editable-label` with Ableton-style drag interaction and an optional fill-bar visualization. See above for all shared attributes, events, CSS variables, and JavaScript properties — only the differences are documented here.

### Interaction Model

| Action | Effect |
|---|---|
| Click | Focuses the control |
| Drag up | Increases value |
| Drag down | Decreases value |
| Printable key while focused | Enters text-edit mode |
| Enter / blur | Commits typed value |
| Escape | Cancels typed edit and restores previous value |

### Additional Attributes

| Attribute | Type | Default | Description |
|---|---|---|---|
| `min` | number | — | Minimum value (no clamping if unset) |
| `max` | number | — | Maximum value (no clamping if unset) |
| `step` | number | — | Snap increment; also informs decimal-place display |
| `drag-sensitivity` | number | `1` | Steps changed per pixel of drag |
| `precision` | number | `0` | Decimal places used when rounding drag-produced values |
| `fill-style` | `linear` \| `circular` | — | Fill-bar style; omit to disable fill bar |
| `linear-style` | `range` \| `bipolar` \| `unipolar` | `range` | How value maps to fill (linear mode only) |
| `circular-style` | `grow` \| `offset` \| `dot` | `grow` | How value maps to fill (circular mode only) |
| `no-drag` | boolean | — | Disables drag interaction; text editing still works |

**`drag-sensitivity`** scales relative to `step`. With `step=0.01` and `drag-sensitivity=1`, each pixel of drag moves the value by 0.01 — sweeping `min=0` to `max=1` takes 100 px. Increase for faster/coarser control, decrease for finer.

**`precision`** only affects drag-produced values. Typed values are never precision-rounded — the user can always enter more decimal places than `precision` allows.

### CSS Variables (fill bar)

| Variable | Default | Description |
|---|---|---|
| `--fill-color` | `var(--accent)` | Fill bar colour |
| `--fill-opacity` | `0.25` | Fill bar opacity (0–1) |
| `--fill-image` | — | Override the entire `background-image`; use `var(--value)` for position |

The `--value` custom property (0–1) is set dynamically on the host element and is available in CSS expressions.

### Usage Examples

**Integer 0–100 with fill bar:**
```html
<ixfx-editable-number
  min="0" max="100" step="1"
  value="50"
  fill-style="linear"
></ixfx-editable-number>
```

**Fine-grained float (step=0.01, full range ~100px of drag):**
```html
<ixfx-editable-number
  min="0" max="1" step="0.01"
  value="0.5"
  fill-style="linear"
></ixfx-editable-number>
```

**No step — drag rounds to 1 decimal place, typed values unrestricted:**
```html
<ixfx-editable-number
  min="0" max="10"
  precision="1"
  value="3.5"
></ixfx-editable-number>
```

**Custom accent colour:**
```html
<ixfx-editable-number
  min="0" max="100" value="60"
  fill-style="linear"
  style="--fill-color: oklch(60% 0.2 30); --fill-opacity: 0.35;"
></ixfx-editable-number>
```

**Green–yellow–red gradient that reveals with value:**
```html
<ixfx-editable-number
  min="0" max="100" value="50"
  fill-style="linear"
  style="
    --fill-image: linear-gradient(
      to right,
      oklch(55% 0.18 140),
      oklch(78% 0.2 100),
      oklch(60% 0.22 25)  calc(var(--value) * 100%),
      var(--surface-ll, oklch(22% 0.02 240)) calc(var(--value) * 100%)
    );
  "
></ixfx-editable-number>
```

**Saturation tied to value:**
```html
<ixfx-editable-number
  min="0" max="100" value="50"
  fill-style="linear"
  style="
    --fill-color: oklch(65% calc(var(--value) * 0.3) 250);
    --fill-opacity: 1;
  "
></ixfx-editable-number>
```

**Formatter (display as percentage):**
```html
<ixfx-editable-number id="vol" min="0" max="1" step="0.01" value="0.75"></ixfx-editable-number>
<script>
  document.querySelector('#vol').formatter = (v) => `${Math.round(parseFloat(v) * 100)}%`;
</script>
```
