Prompts to start an empty chat from, as cards.
What can I help with?
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { PromptSuggestions, promptOf } from "./ui/uicontext/components/chat/PromptSuggestions.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, space } from "./ui/uicontext/components/tokens.stylex.ts"const Message = UiSchema.TaggedEnum({ PickedSuggestion: { prompt: Schema.String } })const styles = stylex.create({ frame: { display: "grid", gap: space.xl, inlineSize: "min(100%, 40rem)" }, greeting: { margin: 0, fontSize: font.xl, fontWeight: 600, textAlign: "center" }, picked: { margin: 0, color: color.muted, fontSize: font.sm, textAlign: "center", minHeight: "1.5em" },})const suggestions = [ { id: "retry", title: "Write a retry helper", detail: "with exponential backoff in TypeScript" }, { id: "compare", title: "Compare Postgres and SQLite", detail: "for a small team's internal tool" }, { id: "plan", title: "Plan a product launch", detail: "for a mobile app in six weeks" }, { id: "explain", title: "Explain a concept", detail: "like CRDTs, to a new engineer" },]export const EmptyChat = Html.component({ name: "EmptyChat", model: Schema.Struct({ picked: Schema.String }), message: Message,}).make({ init: () => ({ picked: "" }), update: { PickedSuggestion: ($, { prompt }) => $.evolve({ picked: prompt }) }, view: (h, model) => h.div.attrs(sx(styles.frame)).children( h.h2.attrs(sx(styles.greeting)).children("What can I help with?"), PromptSuggestions(h, { suggestions, onPick: (s) => Message.PickedSuggestion({ prompt: promptOf(s) }) }), h.p.attrs({ role: "status", ...sx(styles.picked) }).children(model.picked === "" ? "" : `Sends “${model.picked}”`), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/prompt-suggestionsUsage
import { type PromptSuggestion, PromptSuggestions, promptOf } from "./ui/uicontext/components/chat/PromptSuggestions.ts"const Message = UiSchema.TaggedEnum({ PickedSuggestion: { prompt: Schema.String } })export const Starters = (h: Html.H<typeof Message.Type>, suggestions: ReadonlyArray<PromptSuggestion>) => PromptSuggestions(h, { suggestions, onPick: (s) => Message.PickedSuggestion({ prompt: promptOf(s) }) })API reference
Options
| Name | Type | Default | Description |
|---|---|---|---|
suggestionsrequired | PromptSuggestion[] | — | — |
onPickrequired | (suggestion: PromptSuggestion) => Message | — | — |
label | string | "Suggestions" | The list's accessible name: "Suggestions" by default |