@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
| Prop | Type | Default | Description |
|---|---|---|---|
onSubmit | (question: string) => void | — | Handles 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. |
placeholder | string | — | Placeholder (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…". |
disabled | boolean | — | Disable the input + submit (e.g. while an answer generates). Submitting is a no-op while set. |
locked | boolean | — | Override the locked state. Defaults to the surrounding lockable card's state, or unlocked when used outside one. While locked the whole compound renders nothing. |
defaultOpen | boolean | — | Start 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.
| Part | Description |
|---|---|
Ask.Collapsed | Shown while the input is collapsed — wraps the trigger. |
Ask.Expanded | Shown while the input is expanded — wraps the form. |
Parts
| Part | Description |
|---|---|
Ask.TriggerasChild? | The collapsed affordance; clicking it expands the input in place (the input autofocuses). |
Ask.FormasChild? | The expanded row. Submitting it (Enter, or the Submit part) asks the question. |
Ask.InputasChild? | 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.SubmitasChild? | Submits the question. Disabled until non-whitespace text is entered. Defaults its aria-label to "Ask". |
Hooks
| Part | Description |
|---|---|
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; thelockedprop overrides it either way. Asknever fetches —scopesis empty. The host'sonSubmitowns what a question costs and requires.