import { html } from '@webjsdev/core';
import { cn } from '#lib/utils/cn.ts';
import { buttonClass } from '#components/ui/button.ts';
import {
inputGroupClass, inputGroupAddonClass, inputGroupButtonClass, inputGroupTextareaClass,
} from '#components/ui/input-group.ts';
import { ArrowUpIcon, PlusIcon } from '#lib/ui/lucide.ts';
const suggestions = [
'Add a dark mode toggle',
'Fix the failing build',
'Write tests for the form',
'Upgrade to Next.js 16',
'Add a loading state',
'Find unused dependencies',
];
// Before anything is sent: the row of suggestions above an empty prompt
// field. Sending a suggestion is the app's to wire, as the AI SDK section
// below shows.
export default function SuggestionDemo() {
return html`
<div class="mx-auto flex w-full max-w-lg flex-col gap-6 py-6 text-sm">
<div class="flex flex-col gap-2">
<div class="flex scroll-fade-x scrollbar-none gap-2 overflow-x-auto overscroll-x-contain">
${suggestions.map((suggestion) => html`
<button type="button" data-slot="button" data-variant="outline" data-size="sm" class=${cn(buttonClass({ variant: 'outline', size: 'sm' }), 'shrink-0')}>
${suggestion}
</button>
`)}
</div>
<form>
<div data-slot="input-group" role="group" class=${inputGroupClass()}>
<textarea data-slot="input-group-control" name="prompt" aria-label="Prompt" placeholder="Ask the agent to change your code..." class=${cn(inputGroupTextareaClass(), 'p-3')}></textarea>
<div role="group" data-slot="input-group-addon" data-align="block-end" class=${inputGroupAddonClass({ align: 'block-end' })}>
<button type="button" data-slot="input-group-button" data-variant="outline" data-size="icon-sm" aria-label="Attach files" class=${cn(inputGroupButtonClass({ size: 'icon-sm', variant: 'outline' }), 'rounded-full')}>
${PlusIcon()}
</button>
<button type="submit" data-slot="input-group-button" data-variant="default" data-size="icon-sm" aria-label="Send" disabled class=${cn(inputGroupButtonClass({ size: 'icon-sm', variant: 'default' }), 'ml-auto rounded-full')}>
${ArrowUpIcon()}
</button>
</div>
</div>
</form>
</div>
</div>
`;
}
View Code
Suggestion is a prompt you send without typing. Each one is a Button with the prompt as its label. Put a row of them above the Prompt Input.
Installation
Suggestion is built with the Button component.
Install the following dependencies:
Copy and paste the following code into your project.
/**
* Button: styled native `<button>`. Tier-1 class helper. Compose with a
* real `<button>` (or `<a>` for link-styled buttons) so form submission,
* focus, keyboard activation, and screen-reader semantics all "just work".
*
* shadcn parity:
* Button (variant: default | destructive | outline | secondary | ghost | link)
* (size: default | xs | sm | lg | icon | icon-xs | icon-sm | icon-lg)
* → buttonClass({ variant, size })
*
* shadcn React's `asChild` (Slot) prop has no equivalent here: just call
* `buttonClass(...)` and spread the classes onto whatever element you want.
*
* A11y (required for accessible output): an icon-only button (the `icon`,
* `icon-xs`, `icon-sm`, `icon-lg` sizes) has no visible text, so it MUST
* carry an accessible name via aria-label (or aria-labelledby). A button
* that opens an overlay should also set aria-haspopup and aria-expanded.
* Native <button> focus and keyboard activation are already correct.
*
* Design tokens used: --primary, --primary-foreground, --destructive,
* --secondary, --secondary-foreground, --accent, --accent-foreground,
* --background, --input, --ring.
*
* @example
* ```html
* <button class=${buttonClass()} type="submit">Save</button>
* <button class=${buttonClass({ variant: 'outline', size: 'sm' })}>Cancel</button>
* <button class=${buttonClass({ size: 'icon' })} aria-label="Settings">⚙</button>
* <a class=${buttonClass({ variant: 'link' })} href="/about">About</a>
* ```
*/
import { cn } from '../lib/utils.ts';
// Base form (#1666): the semantic `cn-button*` names carry the look, and
// the style named in components.json supplies it when the file is installed
// (styles/style-<name>.css, baked by `add`). What stays inline is the layout
// shadcn's base form keeps inline in every style.
//
// The default new-york style puts cursor-pointer on `cn-button`, so every
// variant gets the right hover affordance. Native <button> defaults to the OS
// arrow cursor in Chromium and Firefox, and shadcn's modern Button has
// gravitated toward an explicit cursor-pointer in the real world (see the open
// issue shadcn-ui/ui#1791). disabled:pointer-events-none below already
// suppresses the cursor on a disabled button.
const BASE =
"cursor-pointer gap-2 rounded-md text-sm font-medium focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg:not([class*='size-'])]:size-4 group/button inline-flex shrink-0 items-center justify-center whitespace-nowrap transition-all outline-none select-none disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0";
const VARIANTS = {
default: 'bg-primary text-primary-foreground hover:bg-primary/90',
destructive: 'bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40',
outline: 'border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50',
secondary: 'bg-secondary text-secondary-foreground hover:bg-secondary/80',
ghost: 'hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50',
link: 'text-primary underline-offset-4 hover:underline',
} as const;
const SIZES = {
default: 'h-9 px-4 py-2 has-[>svg]:px-3',
xs: "h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3",
sm: 'h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5',
lg: 'h-10 rounded-md px-6 has-[>svg]:px-4',
icon: 'size-9',
'icon-xs': "size-6 rounded-md [&_svg:not([class*='size-'])]:size-3",
'icon-sm': 'size-8',
'icon-lg': 'size-10',
} as const;
export type ButtonVariant = keyof typeof VARIANTS;
export type ButtonSize = keyof typeof SIZES;
export interface ButtonClassOptions {
variant?: ButtonVariant;
size?: ButtonSize;
}
/** Compose Tailwind classes for a button. Stable shape: object-arg, both optional. */
export function buttonClass(opts: ButtonClassOptions & { className?: string } = {}): string {
const variant = opts.variant ?? 'default';
const size = opts.size ?? 'default';
return cn(BASE, VARIANTS[variant], SIZES[size], opts.className);
}
/**
* shadcn's name for {@link buttonClass}, so shadcn code ports verbatim
* (`buttonVariants({ ... })` is shadcn's `cva` export for `Button`). Like cva, it
* merges a `className` into the result.
*/
export function buttonVariants(opts: ButtonClassOptions & { className?: string } = {}): string {
return buttonClass(opts);
}
Update the import paths to match your project setup.
Usage
import { buttonClass } from '#components/ui/button.ts';
<div class="scrollbar-none flex scroll-fade-x gap-2 overflow-x-auto overscroll-x-contain">
${suggestions.map((suggestion) => html`
<button type="button" data-slot="button" data-variant="outline" data-size="sm"
class=${cn(buttonClass({ variant: 'outline', size: 'sm' }), 'shrink-0')}
@click=${() => this.send(suggestion)}>
${suggestion}
</button>
`)}
</div>
Scrolling
The row scrolls sideways when the suggestions do not fit. scroll-fade-x fades the edge that has more to show, and shrink-0 keeps each label on one line.
AI SDK
The label is the message. Send it as is, through the same method your chat component calls with the text the person typed.
@click=${() => this.sendMessage({ text: suggestion })}
sendMessage is your component's own method. See AI SDK for streaming the reply from a 'use server' action.
Migrating from AI SDK Elements
If you used Suggestion from AI SDK Elements, its wrapper lives in components/ai-elements/suggestion.tsx. In a WebJs app it becomes this pattern, built from WebJs UI components. Each export of the wrapper maps onto a part: