Starter prompts

Suggested prompts on an empty chat: "Summarise this thread", "Draft a reply". A press puts the prompt in the reader's message box, or sends it, or follows a link. Chips on one line each, or cards with an icon and a description.

Starter prompts

Each suggestion works with no script at all: a link when it has an href, and otherwise a submit button posting prompt=<the text> in your form. With Alpine and the package's script, for writes the prompt into your message field instead, and every press dispatches choose.

Use it

Inside the form that sends a message, so a press sends it:

<form method="post" action="{{ route('chats.messages.store', $chat) }}">
    @csrf
    <x-ds::starter-prompts :prompts="[
        'Summarise this thread',
        ['label' => 'Draft a reply', 'prompt' => 'Draft a polite reply to the last message', 'icon' => 'pencil-square'],
    ]" />
    <x-ds::input as="textarea" id="message" name="prompt" label="Message" />
</form>

Fill the box rather than send, so the reader can edit first:

<x-ds::starter-prompts for="message" :prompts="$suggestions" />

As cards, in a grid that answers the width it is given:

<x-ds::starter-prompts variant="cards" :columns="2" label="Try asking" :prompts="[
    ['label' => 'Plan a trip', 'description' => 'Three days, one city, a budget', 'icon' => 'map'],
    ['label' => 'Explain a bill', 'description' => 'Line by line, in plain words', 'icon' => 'document-text'],
]" />

Livewire, sending straight away:

<x-ds::starter-prompts :prompts="$suggestions" x-on:choose.prevent="$wire.send($event.detail.prompt)" />

.prevent cancels the event, which tells the component the host has dealt with it: nothing is filled, posted or followed.

Props

PropTypeDefaultWhat it does
promptsarray[]Rows: label (the words), prompt (the text sent; the label when left out), icon, description (cards only), href (a link instead). A bare string is a label.
variantchips cardschipsOne line each, wrapping; or cards with an icon and a description.
columns1–42Cards: the most columns, reached as the container widens (container queries, not the window).
labelstringSuggested promptsNames the list. Shown above it.
hideLabelboolfalseKeep label as the list's name only.
forstring—The id of the field a choice is written into and focused. Needs Alpine and the script.
namestringpromptThe field name a button posts its prompt under.

Events

EventDetailWhen
choose{ prompt }Every press, from the suggestion, bubbling. Cancel it to stop the fill, the post or the link. Not select, which a field fires itself when text in it is selected.

Accessibility

  • A list of buttons (or links), not a listbox: each is one action, reached by Tab, pressed with Enter or Space. The list is named by label.
  • Filling the field moves focus into it, caret at the end, so the reader can edit and send. The field gets a native input event, so x-model and wire:model see the new text.
  • Every suggestion draws the focus ring.

Don't

  • Don't put the full prompt in label when it is long. Show a few words and send the rest as prompt.
  • Don't keep showing them once the conversation has started. They are for the empty state.

From the package repo: edit this page on GitHub.

Was this page helpful?