TokenInput
HkTokenInput is the standalone token-budget editor: a value segment that shows the current count ("128K", "1.5M", "—" when unset) plus a unit suffix dropdown (auto / K / M / B). It carries no outer chrome of its own, so hosts drop it into any slot — most often the trailing slot of a slider field, where the composition lives in the host.
- An amount of money in canonical decimal text is HkMoneyInput; a token budget is an absolute number with a unit, not a formatted currency.
- An ordered set of tag keys is HkTagInput.
- A {{ token }} fill template is HkTemplateField.
Import
;
use *; // TokenInput, TokenUnitChoice, ParsedTokenCommit, …
use *; // rsx!, VNode, SelectOption, EventHandler
modelValue is the absolute count (null = unset), and update:modelValue / update:unit are the two writes the host must apply.
Display units
unit="auto" compacts the value to its natural magnitude; an explicit unit divides and appends its letter, so 1500000 reads 1500K, 1.5M or 2.5B depending on the suffix. format overrides the built-in compaction with the host's own (value, unit) => string function.
An unset value renders the em dash; the unit picker is the shared Select composition, so it brings its own trigger and popout.
A host formatter
format wins over every built-in branch — pass compactTokenCount through a wrapper to add a suffix, or return any string the surface needs. In the Rust mirror format is a Callback, because Vue's function prop carries a return value.
Editing behaviour
Pressing the value segment asks for the precision editor (editor_open in the Rust mirror); the editor's arithmetic follows fixed semantics: it opens in the value's natural magnitude, a unit flip re-expresses the same absolute budget (1.5M ⇄ 1500K) instead of rescaling it, a deliberately emptied field unsets, and a transiently unparseable intermediate ("1e", "-") commits nothing. The Rust mirror exposes that algebra as free functions — seed_editor_unit, rescale_editor_text, parse_editor_commit, switch_unit_expression — which a host-side editor can reuse; the Vue form keeps the same behaviour inside its own internals.
The Vue form mounts the editor in an adaptive dialog (a draggable desktop window / mobile sheet) and accepts an #editor slot for a custom body. The Rust mirror has no dialog host in this wave: the value button only emits onupdate_editor_open(true) and the host renders the body — the pure functions above are the whole arithmetic of that editor.
API
Vue
Props
| Name | Type | Default | Required |
|---|---|---|---|
| modelValue | <code>Number as () => number | null</code> | null | — |
| unit | <code>String as () => "auto" | TokenUnit</code> | "auto" | — |
| disabled | Boolean | false | — |
| editorTitle | String | undefined | — |
| format | <code>Function as PropType<(value: number | null, unit: "auto" | TokenUnit) => string></code> | undefined | — |
| ariaLabel | String | undefined | — |
Emits
| Event | Payload |
|---|---|
| update:modelValue | <code>number | null</code> |
| update:unit | <code>"auto" | TokenUnit</code> |
Rust
Props — TokenInput
| Prop | Type | Default | Description |
|---|---|---|---|
| model_value | Option<f64> | None | Vue: modelValue — the absolute token count; None = unset (null). |
| unit | TokenUnitChoice | TokenUnitChoice::Auto | Vue: unit, default auto. |
| disabled | bool | false | — |
| editor_title | Option<String> | None | The precision editor's title (Vue: editorTitle); falls back to t("hikari::tokenField.editValue", "Edit value"). |
| aria_label | Option<String> | None | Accessible name of the whole group (Vue: ariaLabel). |
| format | Option<Callback<(Option<f64>, TokenUnitChoice), String>> | None | Vue's format — a host display formatter (value, unit) => string that wins over the built-in compaction. |
| editor_open | bool | false | The precision editor's open flag (Vue: the local editorOpen ref); the dialog body itself is host-side (see the deltas). |
| unit_open | bool | false | The nested unit picker's open flag (the mirrored Select's controlled contract; Vue's HkSelect owns this internally). |
| unit_highlighted_index | i32 | -1 | The nested unit picker's highlight index (-1 = none), same contract. |
| onupdate_model_value | Option<EventHandler<Option<f64>>> | None | Vue: update:modelValue (fired by the host's editor, using the pure commit rules this module exposes). |
| onupdate_unit | Option<EventHandler<TokenUnitChoice>> | None | Vue: update:unit — the suffix picker asked for another unit. |
| onupdate_editor_open | Option<EventHandler<bool>> | None | The value button asked to open the precision editor (Vue: openEditor). |
| on_unit_open_change | Option<EventHandler<bool>> | None | Nested unit picker: update:open. |
| on_unit_highlight_change | Option<EventHandler<i32>> | None | Nested unit picker: the highlight moved. |
Accessibility
- The root is a role="group" named by ariaLabel; give it one, because the value segment alone is a glyph-plus-number trigger.
- The value trigger is a real <button> with aria-haspopup="dialog", and its accessible name is "{editor title}: {display}" — so an unset field is announced as "Edit value: —" rather than as an empty control.
- The suffix dropdown is the shared select, with its own trigger semantics and keyboard navigation.
Related components
- HkMoneyInput — a currency amount over canonical decimal text.
- HkTagInput — an ordered tag field with a searchable catalog.
- HkTemplateField — the editor for {{ token }} fill templates.
- HkPlaceholderMarquee — the overflow strategy for a placeholder that does not fit.