TokenInput

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

tsx
1
import { HkTokenInput, compactTokenCount, type TokenUnit } from "@celestia-island/hikari";
rust
1
2
use hikari_components::*;          // TokenInput, TokenUnitChoice, ParsedTokenCommit, …
use hikari_components::prelude::*; // 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

NameTypeDefaultRequired
modelValue<code>Number as () => number | null</code>null—
unit<code>String as () => "auto" | TokenUnit</code>"auto"—
disabledBooleanfalse—
editorTitleStringundefined—
format<code>Function as PropType<(value: number | null, unit: "auto" | TokenUnit) => string></code>undefined—
ariaLabelStringundefined—

Emits

EventPayload
update:modelValue<code>number | null</code>
update:unit<code>"auto" | TokenUnit</code>

Rust

Props — TokenInput

PropTypeDefaultDescription
model_valueOption<f64>NoneVue: modelValue — the absolute token count; None = unset (null).
unitTokenUnitChoiceTokenUnitChoice::AutoVue: unit, default auto.
disabledboolfalse—
editor_titleOption<String>NoneThe precision editor's title (Vue: editorTitle); falls back to t("hikari::tokenField.editValue", "Edit value").
aria_labelOption<String>NoneAccessible name of the whole group (Vue: ariaLabel).
formatOption<Callback<(Option<f64>, TokenUnitChoice), String>>NoneVue's format — a host display formatter (value, unit) => string that wins over the built-in compaction.
editor_openboolfalseThe precision editor's open flag (Vue: the local editorOpen ref); the dialog body itself is host-side (see the deltas).
unit_openboolfalseThe nested unit picker's open flag (the mirrored Select's controlled contract; Vue's HkSelect owns this internally).
unit_highlighted_indexi32-1The nested unit picker's highlight index (-1 = none), same contract.
onupdate_model_valueOption<EventHandler<Option<f64>>>NoneVue: update:modelValue (fired by the host's editor, using the pure commit rules this module exposes).
onupdate_unitOption<EventHandler<TokenUnitChoice>>NoneVue: update:unit — the suffix picker asked for another unit.
onupdate_editor_openOption<EventHandler<bool>>NoneThe value button asked to open the precision editor (Vue: openEditor).
on_unit_open_changeOption<EventHandler<bool>>NoneNested unit picker: update:open.
on_unit_highlight_changeOption<EventHandler<i32>>NoneNested 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