@get-asset/sdk

Ask

A standalone free-text ask affordance: a trigger that expands, in place, into an input + submit. Ask is headless about answering — the host supplies onSubmit and decides what a submitted question does (the insights panel routes it through its existing select()). Attach it to any component that can answer a question. Inside a lockable card it renders nothing while the card is locked.

Preview

Anatomy

Import the primitive and compose the parts you need.

<Ask.Root onSubmit={question => runQuestion(question)} placeholder="Ask about your cashflow…">
<Ask.Collapsed>
<Ask.Trigger>Ask something else</Ask.Trigger>
</Ask.Collapsed>
<Ask.Expanded>
<Ask.Form>
<Ask.Input />
<Ask.Submit>Ask</Ask.Submit>
</Ask.Form>
</Ask.Expanded>
</Ask.Root>

API reference

Root props

PropTypeDefaultDescription
onSubmit(question: string) => voidHandles a submitted question (already trimmed, never empty). The host decides what asking means — the insights panel calls its select() so the typed question runs through the same fetch path as a starter question.
placeholderstringPlaceholder (and accessible label) for the input. Pass a report-specific prompt (e.g. "Ask about your profit and loss…"). Defaults to "Ask about this report…".
disabledbooleanDisable the input + submit (e.g. while an answer generates). Submitting is a no-op while set.
lockedbooleanOverride the locked state. Defaults to the surrounding lockable card's state, or unlocked when used outside one. While locked the whole compound renders nothing.
defaultOpenbooleanStart on the expanded input instead of the trigger — for storybook/docs previews of the expanded state (e.g. alongside `disabled`).

Parts

State wrappers

The two mutually-exclusive views. Compose the trigger inside Collapsed and the form inside Expanded.

PartDescription
Ask.CollapsedShown while the input is collapsed — wraps the trigger.
Ask.ExpandedShown while the input is expanded — wraps the form.

Parts

PartDescription
Ask.Trigger
asChild?
The collapsed affordance; clicking it expands the input in place (the input autofocuses).
Ask.Form
asChild?
The expanded row. Submitting it (Enter, or the Submit part) asks the question.
Ask.Input
asChild?
The free-text input. Autofocused when the row expands; Escape or blurring while empty collapses back to the trigger (a draft keeps it open). Its placeholder and aria-label come from the Root's placeholder.
Ask.Submit
asChild?
Submits the question. Disabled until non-whitespace text is entered. Defaults its aria-label to "Ask".

Hooks

PartDescription
useAsk()Hook returning { open, value, canSubmit, disabled, placeholder, focusTrigger, expand, collapse, setValue, submit }. `collapse` takes an optional { focusTrigger } for keyboard-initiated cancels, and `focusTrigger` is true when the remounted trigger should take focus. Throws when used outside <Ask.Root>.

Behavior notes

  • Submitting trims the draft, collapses back to the trigger, clears the field, and calls onSubmit. An empty (or whitespace-only) submit is a no-op.
  • Escape or blurring while empty collapses and discards the draft; blurring with text keeps the input open.
  • Inside a lockable card's Root, Ask.Rootreads that card's locked state and renders nothing while locked — there's no data to ask about. No wiring needed; the locked prop overrides it either way.
  • Ask never fetches — scopes is empty. The host's onSubmit owns what a question costs and requires.