PromptSuggestion
Suggested prompts and starter cards for chat empty states
Usage
import {PromptSuggestion} from "@peakui-pro/react";Anatomy
import {PromptSuggestion} from "@peakui-pro/react";
export default () => (
<PromptSuggestion>
<PromptSuggestion.Header>
<PromptSuggestion.Title>What can I help with?</PromptSuggestion.Title>
<PromptSuggestion.Description>Start from a suggested prompt.</PromptSuggestion.Description>
</PromptSuggestion.Header>
{/* A plain div: `role` and `aria-label` are yours to add. */}
<PromptSuggestion.Items aria-label="Suggested prompts" role="group">
<PromptSuggestion.Item>
<PromptSuggestion.ItemTitle>Summarize this document</PromptSuggestion.ItemTitle>
<PromptSuggestion.ItemDescription>Create a concise summary.</PromptSuggestion.ItemDescription>
<PromptSuggestion.ItemMeta>Used 12 times this week</PromptSuggestion.ItemMeta>
<PromptSuggestion.ItemTags>...</PromptSuggestion.ItemTags>
<PromptSuggestion.ItemFooter>About 2 minutes</PromptSuggestion.ItemFooter>
</PromptSuggestion.Item>
</PromptSuggestion.Items>
</PromptSuggestion>
);Examples
Cards
variant="card" lays the item slots out as cards in a grid.
Cards With All Slots
Compose ItemMeta, ItemTags and ItemFooter after the title and description.
Named Group
Items has no group semantics by default; add role="group" and a label.
Disabled
isDisabled dims one suggestion and takes it out of the tab order.
Press Handler
onPress hands the host the chosen prompt, to send to a composer.
Customization
Tailwind CSS
<PromptSuggestion className="[--prompt-suggestion-gap:1.5rem] [--prompt-suggestion-pill-radius:var(--radius-xl)]">
<PromptSuggestion.Items aria-label="Suggested prompts" role="group">
<PromptSuggestion.Item>Draft a weekly project update email</PromptSuggestion.Item>
</PromptSuggestion.Items>
</PromptSuggestion>Global CSS
@layer components {
.prompt-suggestion {
--prompt-suggestion-gap: 1.5rem;
--prompt-suggestion-pill-radius: var(--radius-xl);
}
.prompt-suggestion--card {
--prompt-suggestion-card-min-width: 18rem;
--prompt-suggestion-card-padding: 1.25rem;
}
}Styling Reference
PeakUI follows the BEM methodology, so variants and states are plain class names you can target.
CSS Classes
The PromptSuggestion component uses these CSS classes (view source styles):
Base Classes
.prompt-suggestion- Root.prompt-suggestion--pill- Default layout: a grid of two columns, then one.prompt-suggestion--card- Card layout: a grid that adds columns as the width allows
Element Classes
.prompt-suggestion__header- Title and description wrapper.prompt-suggestion__title- Header title.prompt-suggestion__description- Header description.prompt-suggestion__items- Suggestion grid.prompt-suggestion__item- One suggestion, beside the core.buttonclasses.prompt-suggestion__item-label- Pill text wrapper.prompt-suggestion__item-end-icon- Pill chevron.prompt-suggestion__item-title- Card title.prompt-suggestion__item-description- Card description.prompt-suggestion__item-meta- Card meta line.prompt-suggestion__item-tags- Card tag row.prompt-suggestion__item-footer- Card footer
Modifier Classes
.prompt-suggestion__items--pill,.prompt-suggestion__items--card- Grid per layout.prompt-suggestion__item--pill,.prompt-suggestion__item--card- Item per layout
Slots
[data-slot="prompt-suggestion"][data-slot="prompt-suggestion-header"][data-slot="prompt-suggestion-title"][data-slot="prompt-suggestion-description"][data-slot="prompt-suggestion-items"][data-slot="prompt-suggestion-item"][data-slot="prompt-suggestion-item-label"][data-slot="prompt-suggestion-item-end-icon"][data-slot="prompt-suggestion-item-title"][data-slot="prompt-suggestion-item-description"][data-slot="prompt-suggestion-item-meta"][data-slot="prompt-suggestion-item-tags"][data-slot="prompt-suggestion-item-footer"]
CSS Variables
| Variable | Purpose |
|---|---|
--prompt-suggestion-gap | Space between the header and the items; defaults to 2rem |
--prompt-suggestion-items-gap | Space between items; defaults to 0.5rem, 0.75rem in the card layout |
--prompt-suggestion-pill-min-width | Narrowest pill column; defaults to 18rem |
--prompt-suggestion-pill-radius | Pill corner radius; defaults to var(--radius-2xl) |
--prompt-suggestion-card-min-width | Narrowest card column; defaults to 14rem |
--prompt-suggestion-card-padding | Card padding; defaults to 1rem |
--prompt-suggestion-card-radius | Card corner radius; defaults to var(--radius-2xl) |
Interactive States
The item is the core button and takes its states:
- Hover:
:hoveror[data-hovered] - Pressed:
:activeor[data-pressed], scaled to0.97by the core button - Focus:
:focus-visibleor[data-focus-visible] - Disabled:
:disabled,[data-disabled]or[aria-disabled="true"], dimmed by the core button - Forced colors:
@media (forced-colors: active)paints the chevron and the card text inButtonText, so an enabled item never reads as disabled
API Reference
PromptSuggestion
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'pill' | 'card' | 'pill' | Layout: a grid of short prompts with a chevron, or a grid of cards that compose the item slots |
className | string | - | Additional classes |
render | DOMRenderFunction<'div', undefined> | - | Replaces the rendered <div> with your own element |
...rest | ComponentProps<'div'> | - | Native <div> attributes |
PromptSuggestion.Header
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional classes |
render | DOMRenderFunction<'div', undefined> | - | Replaces the rendered <div> with your own element |
...rest | ComponentProps<'div'> | - | Native <div> attributes |
PromptSuggestion.Title
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional classes |
render | DOMRenderFunction<'h2', undefined> | - | Replaces the rendered <h2>, to set the heading level your page needs |
...rest | ComponentProps<'h2'> | - | Native <h2> attributes |
PromptSuggestion.Description
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional classes |
render | DOMRenderFunction<'p', undefined> | - | Replaces the rendered <p> with your own element |
...rest | ComponentProps<'p'> | - | Native <p> attributes |
PromptSuggestion.Items
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional classes |
role | string | - | None by default; pass "group" with aria-label so a screen reader announces the set |
render | DOMRenderFunction<'div', undefined> | - | Replaces the rendered <div> with your own element |
...rest | ComponentProps<'div'> | - | Native <div> attributes |
PromptSuggestion.Item
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | (values: ButtonRenderProps) => React.ReactNode | - | The prompt text, or the item slots in the card layout. The accessible name is the whole content, not the title alone |
variant | 'primary' | 'secondary' | 'tertiary' | 'outline' | 'ghost' | 'danger' | 'danger-soft' | 'outline' | Core button style, which sets only the fill and the border: the item always sets its text to the foreground colour. In pill, outline, ghost, secondary, tertiary and danger-soft work; primary and danger put that text on a solid fill, under 4.5:1 in the light theme, so do not use them. In card, none works: the surface fill and the surface shadow are fixed and every variant renders alike |
isDisabled | boolean | false | Whether the suggestion is disabled |
onPress | (e: PressEvent) => void | - | Handler called when the suggestion is pressed |
className | string | (values: ButtonRenderProps) => string | - | Additional classes, or a function of the button's state |
render | DOMRenderFunction<'button', ButtonRenderProps> | - | Replaces the rendered element; receives the props with data-slot set |
...rest | ButtonProps | - | Every other core Button prop |
PromptSuggestion.ItemTitle, ItemDescription, ItemMeta, ItemTags, ItemFooter
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional classes |
render | DOMRenderFunction<'span', undefined> | - | Replaces the rendered <span>; the slots are spans because a button holds phrasing content only |
...rest | ComponentProps<'span'> | - | Native <span> attributes |
Render Props
| Prop | Type | Description |
|---|---|---|
isPending | boolean | Whether the item is waiting on an operation |
isPressed | boolean | Whether the item is currently pressed |
isHovered | boolean | Whether the item is hovered |
isFocused | boolean | Whether the item is focused |
isFocusVisible | boolean | Whether the item is focused by keyboard |
isDisabled | boolean | Whether the item is disabled |