# `ixfx-unit-input`

One control for a number plus a unit: a number field joined to a unit picker, styled as a single input.

```html
<ixfx-unit-input unit="MB" placeholder="size"></ixfx-unit-input>
```

```js
import { SIZE_UNITS } from '@ixfx/components/unit-input';

const el = document.querySelector('ixfx-unit-input');
el.units = SIZE_UNITS;
el.addEventListener('change', e => console.log(e.detail)); // { value: 4, unit: 'KB', baseValue: 4096 }
```

| Attribute / Property | Type | Default | Description |
|---|---|---|---|
| `units` (property) | `UnitInputUnit[]` | `[]` | `{ id, label, factor? }`; `factor` is how many base units one of this unit is (default 1) |
| `unit` | `string` | first unit | Id of the selected unit |
| `value` | `number \| null` | `null` | The number, in the selected unit |
| `min`, `max`, `step` | `number` | | Passed to the number field |
| `placeholder` | `string` | `''` | |
| `disabled` | `boolean` | `false` | |
| `baseValue` (property) | `number \| null` | | `value` times the unit's `factor` |

`setBaseValue(n)` sets the control from a base-unit amount, choosing the largest unit it divides evenly into.

Presets: `SIZE_UNITS` (B / KB / MB / GB, base unit the byte) and `AGE_UNITS` (minutes / hours / days / weeks, base unit the minute).

### Events

| Event | Detail | Description |
|---|---|---|
| `change` | `{ value: number \| null, unit: string, baseValue: number \| null }` | The number or the unit changed |

### CSS custom properties

`--unit-input-padding`, `--unit-input-background`, `--unit-input-border`, `--unit-input-border-radius`.
