AI Welcome
Empty states for a new chat: a greeting face whose eyes follow you, a bento of animated starting points, and a centred prompt that glides down into a chat on the first send.
"use client"
import * as React from "react"
import { ArrowUp } from "lucide-react"
import {
AiKitStyles,
AiStyle,
cx,
Face,
Roll,
type AiMood,
type AiShape,
type AiTone,
} from "@/lib/ai-kit"
const CSS = `
.aik-wl-greet{display:grid;justify-items:center;gap:24px;width:min(100%,560px);container-type:inline-size;text-align:center}
.aik-wl-hello{display:grid;justify-items:center;gap:6px}
.aik-wl-hello .aik-face{margin-bottom:12px}
.aik-wl-hello h3{font-size:30px;line-height:36px;font-weight:600;letter-spacing:-.028em;text-wrap:balance}
.aik-wl-hello p{font-size:15px;line-height:22px;color:var(--aik-text-2);max-width:44ch;text-wrap:balance}
.aik-wl-starters{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px;width:100%}
.aik-wl-start{display:grid;grid-template-columns:38px minmax(0,1fr);column-gap:12px;align-items:center;padding:12px 14px 12px 12px;border-radius:17px;background:var(--aik-card);box-shadow:inset 0 0 0 1px var(--aik-line-2);text-align:left;
transition:box-shadow var(--aik-d-state) var(--aik-ease-out),transform var(--aik-d-press) var(--aik-ease-out)}
.aik-wl-start:active{transform:scale(.98)}
.aik-wl-start > i{grid-row:1 / span 2;display:grid;place-items:center;width:38px;height:38px;border-radius:12px;background:var(--aik-raised);color:var(--aik-text-2);transition:background var(--aik-d-state) var(--aik-ease-out),color var(--aik-d-state) var(--aik-ease-out),transform var(--aik-d-panel) var(--aik-ease-move)}
.aik-wl-start b{font-size:14.5px;line-height:20px;font-weight:600;letter-spacing:-.005em}
.aik-wl-start span{font-size:13px;line-height:18px;color:var(--aik-text-2);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.aik-wl-start:hover,.aik-wl-start:focus-visible,.aik-wl-start[data-cur]{box-shadow:inset 0 0 0 1.5px var(--aik-text)}
.aik-wl-start:hover > i,.aik-wl-start:focus-visible > i,.aik-wl-start[data-cur] > i{background:var(--aik-pri);color:var(--aik-pri-ink);transform:rotate(-6deg) scale(1.05)}
@container (max-width:430px){.aik-wl-starters{grid-template-columns:minmax(0,1fr)}.aik-wl-hello h3{font-size:25px;line-height:31px}}
.aik-wl-bento{display:grid;grid-template-columns:repeat(6,minmax(0,1fr));gap:10px;width:min(100%,580px);container-type:inline-size}
.aik-wl-tile{grid-column:span 2;display:grid;grid-template-rows:auto auto;align-content:start;gap:10px;padding:8px 8px 14px;border-radius:20px;background:var(--aik-card);box-shadow:inset 0 0 0 1px var(--aik-line-2);text-align:left;min-width:0;
transition:box-shadow var(--aik-d-state) var(--aik-ease-out),transform var(--aik-d-press) var(--aik-ease-out)}
.aik-wl-tile[data-big]{grid-column:span 3}
.aik-wl-tile:active{transform:scale(.985)}
.aik-wl-tile[data-live]{box-shadow:inset 0 0 0 1.5px var(--aik-text)}
.aik-wl-art{position:relative;display:grid;place-items:center;height:88px;border-radius:13px;background:var(--aik-raised);overflow:hidden;color:var(--aik-text)}
.aik-wl-tile[data-big] .aik-wl-art{height:132px}
.aik-wl-tile > b{padding:0 8px;font-size:14.5px;line-height:20px;font-weight:600;letter-spacing:-.005em}
.aik-wl-tile > span{margin-top:-8px;padding:0 8px;font-size:12.5px;line-height:17px;color:var(--aik-text-2)}
@container (max-width:440px){.aik-wl-tile,.aik-wl-tile[data-big]{grid-column:span 3}.aik-wl-tile:last-child{grid-column:span 6}.aik-wl-tile[data-big] .aik-wl-art{height:96px}}
.aik-wl-chart{width:min(170px,86%);height:auto;overflow:visible}
.aik-wl-chart rect{fill:var(--aik-line-3);transform-box:fill-box;transform-origin:50% 100%;transform:scaleY(.3);transition:transform 560ms var(--aik-ease-move),fill var(--aik-d-panel)}
.aik-wl-chart rect:nth-child(2){transition-delay:50ms}.aik-wl-chart rect:nth-child(3){transition-delay:100ms}.aik-wl-chart rect:nth-child(4){transition-delay:150ms}.aik-wl-chart rect:nth-child(5){transition-delay:200ms}
.aik-wl-chart path{fill:none;stroke:var(--aik-blue);stroke-width:2.5;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:1;stroke-dashoffset:1;transition:stroke-dashoffset 700ms var(--aik-ease-move) 180ms}
.aik-wl-chart circle{fill:var(--aik-blue);opacity:0;transition:opacity var(--aik-d-state) 760ms}
[data-live] .aik-wl-chart rect{transform:none}
[data-live] .aik-wl-chart rect:nth-child(4){fill:var(--aik-text)}
[data-live] .aik-wl-chart path{stroke-dashoffset:0}
[data-live] .aik-wl-chart circle{opacity:1}
.aik-wl-fan{position:relative;width:64px;height:84px}
.aik-wl-fan i{position:absolute;inset:0;border-radius:11px;background:var(--aik-card);box-shadow:0 0 0 1px var(--aik-line-2),0 3px 8px rgb(12 12 24 / 10%);transform-origin:50% 130%;transition:transform 520ms var(--aik-ease-move)}
.aik-wl-fan i::before{content:"";position:absolute;inset:8px 8px auto;height:26px;border-radius:6px;background:var(--t)}
.aik-wl-fan i::after{content:"";position:absolute;left:8px;right:22px;top:44px;height:5px;border-radius:3px;background:var(--aik-line-3);box-shadow:0 11px 0 var(--aik-line-2)}
[data-live] .aik-wl-fan i:nth-child(1){transform:rotate(-17deg) translateX(-22px)}
[data-live] .aik-wl-fan i:nth-child(3){transform:rotate(17deg) translateX(22px)}
[data-live] .aik-wl-fan i:nth-child(2){transform:translateY(-6px)}
.aik-wl-type{position:relative;display:inline-block;font:13px/22px var(--aik-mono);white-space:nowrap}
.aik-wl-type::after{content:"";position:absolute;inset:0 -2px 0 0;background:var(--aik-raised);border-left:2px solid var(--aik-blue);transform:translateX(0);transition:transform 0ms}
[data-live] .aik-wl-type::after{transform:translateX(100%);transition:transform 950ms steps(18)}
.aik-wl-switch{position:relative;width:58px;height:34px;border-radius:17px;background:var(--aik-line-3);transition:background var(--aik-d-panel) var(--aik-ease-out)}
.aik-wl-switch::after{content:"";position:absolute;left:4px;top:4px;width:26px;height:26px;border-radius:50%;background:#fff;box-shadow:0 1px 3px rgb(12 12 24 / 25%);transition:transform 420ms var(--aik-ease-move)}
[data-live] .aik-wl-switch{background:var(--aik-green)}
[data-live] .aik-wl-switch::after{transform:translateX(24px)}
.aik-wl-eq{display:flex;align-items:center;gap:4px;height:44px}
.aik-wl-eq i{width:4px;height:100%;border-radius:2px;background:var(--aik-text-3);transform:scaleY(var(--v));transition:background var(--aik-d-state)}
[data-live] .aik-wl-eq i{background:var(--aik-blue);animation:aik-wl-eq 900ms ease-in-out infinite alternate;animation-delay:calc(var(--n)*-130ms)}
@keyframes aik-wl-eq{to{transform:scaleY(calc(1.15 - var(--v)))}}
@media (prefers-reduced-motion: reduce){.aik-wl-chart rect,.aik-wl-chart path,.aik-wl-fan i,.aik-wl-switch::after{transition:none}[data-live] .aik-wl-eq i{animation:none}[data-live] .aik-wl-type::after{transition:none}}
.aik-wl-hero{position:relative;width:min(100%,560px);height:var(--h);container-type:inline-size}
.aik-wl-thread{position:absolute;inset:0 0 84px 0;display:flex;flex-direction:column;justify-content:flex-end;gap:12px;padding:0 6px 6px;overflow:hidden;opacity:0;transition:opacity var(--aik-d-exit) var(--aik-ease-in)}
.aik-wl-hero[data-docked] .aik-wl-thread{opacity:1;transition:opacity var(--aik-d-enter) var(--aik-ease-out) 300ms}
.aik-wl-mid{position:absolute;left:0;right:0;bottom:0;display:grid;gap:22px;transform:translateY(calc(50% - var(--h)/2));transition:transform 560ms var(--aik-ease-soft)}
.aik-wl-hero[data-docked] .aik-wl-mid{transform:none}
.aik-wl-pitch{display:grid;justify-items:center;gap:12px;text-align:center;transition:opacity var(--aik-d-state) var(--aik-ease-out),transform 560ms var(--aik-ease-soft)}
.aik-wl-pitch h3{font-size:27px;line-height:33px;font-weight:600;letter-spacing:-.026em;text-wrap:balance}
.aik-wl-hero[data-docked] .aik-wl-pitch{opacity:0;transform:translateY(-18px) scale(.96);pointer-events:none}
.aik-wl-dock{--aik-r-shell:27px;--aik-rim:6px}
.aik-wl-dbox{display:flex;align-items:center;gap:11px;height:58px;padding:0 10px 0 14px}
.aik-wl-field{position:relative;flex:1;min-width:0;height:100%}
.aik-wl-in{width:100%;height:100%;padding:0;border:0;outline:0;background:none;font-size:15.5px}
.aik .aik-wl-in:focus-visible{outline:none}
.aik-wl-ph{position:absolute;inset:0;display:flex;align-items:center;pointer-events:none;color:var(--aik-text-3);font-size:15.5px;overflow:hidden}
.aik-wl-ph .aik-roll{line-height:24px}
.aik-wl-send{display:grid;place-items:center;width:38px;height:38px;flex:none;border-radius:12px;color:var(--aik-pri-ink);background:color-mix(in oklab,var(--aik-raised) 78%,var(--aik-text) 22%);transition:background var(--aik-d-state) var(--aik-ease-out),transform var(--aik-d-press) var(--aik-ease-out)}
.aik-wl-send[data-ready]{background:var(--aik-pri)}
.aik-wl-send:active{transform:scale(.94)}
@container (max-width:400px){.aik-wl-pitch h3{font-size:23px;line-height:29px}}
@media (prefers-reduced-motion: reduce){.aik-wl-mid,.aik-wl-pitch{transition:none}}
`
interface AgentLook {
tone?: AiTone | (string & {})
shape?: AiShape
}
export interface AiStarter {
id: string
title: string
/** One short line under the title. */
hint: string
icon?: React.ReactNode
}
export interface AiWelcomeGreetingProps extends Omit<
React.HTMLAttributes<HTMLDivElement>,
"onSelect"
> {
/** The headline, such as "Good morning, Sam". */
greeting: string
/** A sentence under the headline. */
line?: string
starters: AiStarter[]
onPick?: (starter: AiStarter) => void
/** The id of a starter to show as highlighted, as hover does. */
active?: string | null
/** Where the face looks, each axis -1 to 1. Leave undefined to follow the pointer. */
look?: { x: number; y: number }
/** Overrides the mood the face picks for itself. */
mood?: AiMood
agent?: AgentLook
}
const clamp = (value: number) => Math.max(-1, Math.min(1, value))
// A portrait this large needs a wider glance than the face's default to read as looking.
const amplify = (look: { x: number; y: number }) => ({
x: look.x * 1.8,
y: look.y * 1.6,
})
/**
* An empty state with a face that watches. Its eyes follow the pointer, turn
* to whichever starter is hovered or focused, and it perks up when you pick one.
*/
export function AiWelcomeGreeting({
greeting,
line,
starters,
onPick,
active = null,
look,
mood,
agent,
className,
onPointerMove,
onPointerLeave,
...rest
}: AiWelcomeGreetingProps) {
const face = React.useRef<HTMLSpanElement>(null)
const [own, setOwn] = React.useState({ x: 0, y: 0 })
const [over, setOver] = React.useState<string | null>(null)
const lookAt = (x: number, y: number) => {
const node = face.current
if (!node) return
const box = node.getBoundingClientRect()
setOwn({
x: clamp((x - (box.left + box.width / 2)) / 170),
y: clamp((y - (box.top + box.height / 2)) / 150),
})
}
const current = active ?? over
return (
<div
{...rest}
className={cx("aik aik-wl-greet", className)}
onPointerMove={(event) => {
lookAt(event.clientX, event.clientY)
onPointerMove?.(event)
}}
onPointerLeave={(event) => {
setOwn({ x: 0, y: 0 })
setOver(null)
onPointerLeave?.(event)
}}
>
<AiKitStyles />
<AiStyle id="ai-welcome" css={CSS} />
<div className="aik-wl-hello">
<span ref={face} style={{ display: "inline-flex" }}>
<Face
size={96}
shape={agent?.shape ?? "blob"}
tone={agent?.tone ?? "blue"}
mood={mood ?? (current ? "listen" : "idle")}
look={amplify(look ?? own)}
/>
</span>
<h3>{greeting}</h3>
{line ? <p>{line}</p> : null}
</div>
<div className="aik-wl-starters">
{starters.map((starter, index) => (
<button
key={starter.id}
type="button"
className="aik-wl-start aik-in"
data-cur={starter.id === current ? "" : undefined}
style={{ "--i": index + 2 } as React.CSSProperties}
onPointerEnter={() => setOver(starter.id)}
onPointerLeave={() => setOver(null)}
onFocus={(event) => {
setOver(starter.id)
const box = event.currentTarget.getBoundingClientRect()
lookAt(box.left + box.width / 2, box.top + box.height / 2)
}}
onBlur={() => setOver(null)}
onClick={() => onPick?.(starter)}
>
<i>{starter.icon}</i>
<b>{starter.title}</b>
<span>{starter.hint}</span>
</button>
))}
</div>
</div>
)
}
export type AiBentoArtKind = "chart" | "cards" | "type" | "toggle" | "voice"
const EQ = [0.35, 0.6, 0.9, 0.5, 0.75, 1, 0.55, 0.8, 0.4, 0.65, 0.3]
/** The small illustrations the bento tiles ship with. Each plays when its tile is live. */
export function AiBentoArt({ kind }: { kind: AiBentoArtKind }) {
if (kind === "chart")
return (
<svg className="aik-wl-chart" viewBox="0 0 170 96" aria-hidden="true">
<rect x="10" y="52" width="22" height="40" rx="6" />
<rect x="42" y="36" width="22" height="56" rx="6" />
<rect x="74" y="46" width="22" height="46" rx="6" />
<rect x="106" y="16" width="22" height="76" rx="6" />
<rect x="138" y="30" width="22" height="62" rx="6" />
<path pathLength={1} d="M21 40 L53 24 L85 34 L117 6 L149 18" />
<circle cx="117" cy="6" r="4.5" />
</svg>
)
if (kind === "cards")
return (
<span className="aik-wl-fan" aria-hidden="true">
<i style={{ "--t": "var(--aik-f-violet)" } as React.CSSProperties} />
<i style={{ "--t": "var(--aik-f-blue)" } as React.CSSProperties} />
<i style={{ "--t": "var(--aik-f-amber)" } as React.CSSProperties} />
</span>
)
if (kind === "type")
return (
<span className="aik-wl-type" aria-hidden="true">
reveal word by word
</span>
)
if (kind === "toggle")
return <span className="aik-wl-switch" aria-hidden="true" />
return (
<span className="aik-wl-eq" aria-hidden="true">
{EQ.map((value, at) => (
<i
key={at}
style={{ "--v": value, "--n": at } as React.CSSProperties}
/>
))}
</span>
)
}
export interface AiBentoTile {
id: string
title: string
hint: string
/** One of the built-in illustrations, or your own node. */
art: AiBentoArtKind | React.ReactNode
/** Large tiles take half the row. Use two. */
big?: boolean
}
export interface AiWelcomeBentoProps extends Omit<
React.HTMLAttributes<HTMLDivElement>,
"onSelect"
> {
tiles: AiBentoTile[]
onPick?: (tile: AiBentoTile) => void
/** The id of a tile to play, as hover and focus do. */
active?: string | null
}
const KINDS: readonly string[] = ["chart", "cards", "type", "toggle", "voice"]
/**
* An empty state as a bento of things to try. Every tile is a button with a
* small illustration that plays under the pointer or on focus.
*/
export function AiWelcomeBento({
tiles,
onPick,
active = null,
className,
...rest
}: AiWelcomeBentoProps) {
const [over, setOver] = React.useState<string | null>(null)
const live = active ?? over
return (
<div {...rest} className={cx("aik aik-wl-bento", className)}>
<AiKitStyles />
<AiStyle id="ai-welcome" css={CSS} />
{tiles.map((tile, index) => (
<button
key={tile.id}
type="button"
className="aik-wl-tile aik-in"
data-big={tile.big ? "" : undefined}
data-live={tile.id === live ? "" : undefined}
style={{ "--i": index } as React.CSSProperties}
onPointerEnter={() => setOver(tile.id)}
onPointerLeave={() => setOver(null)}
onFocus={() => setOver(tile.id)}
onBlur={() => setOver(null)}
onClick={() => onPick?.(tile)}
>
<span className="aik-wl-art">
{typeof tile.art === "string" && KINDS.includes(tile.art) ? (
<AiBentoArt kind={tile.art as AiBentoArtKind} />
) : (
tile.art
)}
</span>
<b>{tile.title}</b>
<span>{tile.hint}</span>
</button>
))}
</div>
)
}
export interface AiHeroDockProps extends Omit<
React.HTMLAttributes<HTMLDivElement>,
"onSubmit"
> {
/** The headline over the centred prompt. */
greeting: string
/** Example prompts the empty field rolls through. */
placeholders: string[]
value: string
onValueChange: (value: string) => void
onSubmit?: (value: string) => void
/** False centres the prompt as an empty state; true glides it to the bottom and shows `children`. */
docked: boolean
/** Runs the edge light round the dock while the agent works. */
working?: boolean
/** The frame's height in pixels. The dock travels half of it. */
height?: number
agent?: AgentLook & { mood?: AiMood }
/** The conversation, shown above the dock once it is docked. */
children?: React.ReactNode
}
/**
* The empty state that becomes the chat. One centred prompt rolls through
* examples; on the first send it glides to the bottom and the thread opens above.
*/
export function AiHeroDock({
greeting,
placeholders,
value,
onValueChange,
onSubmit,
docked,
working = false,
height = 420,
agent,
children,
className,
style,
...rest
}: AiHeroDockProps) {
const [turn, setTurn] = React.useState(0)
const count = placeholders.length
React.useEffect(() => {
if (count < 2 || value || docked) return
const timer = window.setInterval(
() => setTurn((current) => (current + 1) % count),
2400
)
return () => window.clearInterval(timer)
}, [count, value, docked])
const ready = value.trim().length > 0
const send = () => {
if (ready) onSubmit?.(value.trim())
}
const hint = docked
? "Reply"
: (placeholders[turn % Math.max(count, 1)] ?? "")
return (
<div
{...rest}
className={cx("aik aik-wl-hero", className)}
data-docked={docked ? "" : undefined}
style={{ "--h": `${height}px`, ...style } as React.CSSProperties}
>
<AiKitStyles />
<AiStyle id="ai-welcome" css={CSS} />
<div className="aik-wl-thread" aria-live="polite" inert={!docked}>
{children}
</div>
<div className="aik-wl-mid">
<div className="aik-wl-pitch" aria-hidden={docked}>
<Face
size={64}
shape={agent?.shape ?? "blob"}
tone={agent?.tone ?? "blue"}
mood={agent?.mood ?? (ready ? "listen" : "idle")}
/>
<h3>{greeting}</h3>
</div>
<div className="aik-shell aik-wl-dock">
<div className="aik-surface aik-wl-dbox">
<Face
size={28}
shape="orb"
tone={agent?.tone ?? "blue"}
mood={working ? "work" : ready ? "listen" : "idle"}
/>
<div className="aik-wl-field">
<input
className="aik-wl-in"
value={value}
aria-label={hint || greeting}
onChange={(event) => onValueChange(event.target.value)}
onKeyDown={(event) => {
if (event.key === "Enter") {
event.preventDefault()
send()
}
}}
/>
{value ? null : (
<span className="aik-wl-ph" aria-hidden="true">
<Roll>{hint}</Roll>
</span>
)}
</div>
<button
type="button"
className="aik-wl-send"
data-ready={ready ? "" : undefined}
aria-label="Send"
onClick={send}
>
<ArrowUp size={18} />
</button>
<i className="aik-beam" data-on={working ? "" : undefined} />
</div>
</div>
</div>
</div>
)
}
Installation
One command adds ai-welcome and the shared AI Kit layer it is built on (tokens, faces, marks and brand icons). No animation library, light and dark built in.
$npx shadcn@latest add https://tweenui.dev/r/ai-welcome.json
ai-welcome-demo
"use client"
import * as React from "react"
import { Bug, LayoutGrid, Sparkles, WandSparkles } from "lucide-react"
import { AiDemo } from "@/lib/ai-demo"
import {
AiStyle,
Face,
Mark,
paceToken,
Roll,
typeInto,
useAiLoop,
useIdleHands,
type AiMood,
} from "@/lib/ai-kit"
import {
AiHeroDock,
AiWelcomeBento,
AiWelcomeGreeting,
type AiBentoTile,
type AiStarter,
} from "@/registry/tween/ai-welcome"
const CSS = `
.aik-wld-scene{display:grid;grid-template-columns:minmax(0,1fr);gap:14px;justify-items:center;width:min(100%,580px)}
.aik-wld-scene > *{min-width:0;max-width:100%}
.aik-wld-strip{display:inline-flex;align-items:center;gap:9px;height:36px;padding:0 14px 0 8px;border-radius:18px;background:var(--aik-card);box-shadow:var(--aik-sh-card);font-size:13.5px;max-width:100%}
.aik-wld-strip .aik-roll{color:var(--aik-text-2);line-height:20px}
.aik-wld-user{align-self:flex-end;max-width:80%;padding:10px 16px;border-radius:18px;background:var(--aik-raised);font-size:15px;line-height:22px;transform-origin:100% 100%;animation:aik-wld-launch 560ms var(--aik-ease-move) both}
.aik-wld-bot{display:grid;grid-template-columns:28px minmax(0,1fr);gap:10px;align-items:start;font-size:15px;line-height:24px;animation:aik-in var(--aik-d-enter) var(--aik-ease-out) both}
.aik-wld-bot p{padding-top:2px}
@keyframes aik-wld-launch{from{opacity:.2;transform:translateY(120px) scale(.9)}}
@media (prefers-reduced-motion: reduce){.aik-wld-user{animation:none}}
`
const wait = (ms: number) =>
new Promise<void>((resolve) => window.setTimeout(resolve, ms))
const STARTERS: AiStarter[] = [
{
id: "build",
title: "Build a section",
hint: "Pricing with a monthly toggle",
icon: <LayoutGrid size={18} />,
},
{
id: "reveal",
title: "Add a reveal",
hint: "Bring the hero in word by word",
icon: <WandSparkles size={18} />,
},
{
id: "fix",
title: "Fix a component",
hint: "Why does my slider jump?",
icon: <Bug size={18} />,
},
{
id: "polish",
title: "Polish the motion",
hint: "Make these eases consistent",
icon: <Sparkles size={18} />,
},
]
const TOUR: Array<[string, number, number]> = [
["build", -0.85, 0.75],
["reveal", 0.85, 0.75],
["polish", 0.85, 1],
["fix", -0.85, 1],
]
function Greeting() {
const root = React.useRef<HTMLDivElement>(null)
const [hands, touch] = useIdleHands()
const [active, setActive] = React.useState<string | null>(null)
const [look, setLook] = React.useState({ x: 0, y: 0 })
const [picked, setPicked] = React.useState<AiStarter | null>(null)
const run = React.useRef(0)
const choose = React.useCallback(
async (starter: AiStarter, sleep: (ms: number) => Promise<void>) => {
const mine = ++run.current
setPicked(starter)
await sleep(2600)
if (run.current === mine) setPicked(null)
},
[]
)
useAiLoop(
root,
async ({ sleep }) => {
run.current++
setPicked(null)
setActive(null)
setLook({ x: 0, y: 0 })
await sleep(1700)
for (const [id, x, y] of TOUR) {
setLook({ x, y })
setActive(id)
await sleep(950)
}
const starter = STARTERS[2]
setActive(null)
setLook({ x: 0, y: 0.2 })
if (starter) await choose(starter, sleep)
await sleep(400)
},
{ gap: 300, enabled: !hands }
)
const mood: AiMood | undefined = picked ? "happy" : undefined
return (
<div
ref={root}
className="aik-wld-scene"
onPointerDown={touch}
onKeyDown={touch}
>
<AiWelcomeGreeting
greeting={picked ? "On it." : "What are we building today?"}
line={
picked
? `Starting with “${picked.hint}”. I will show you a plan first.`
: "Mira knows this project. Pick a start, or just ask."
}
starters={STARTERS}
active={hands ? null : active}
look={hands ? undefined : look}
mood={mood}
onPick={(starter) => void choose(starter, wait)}
/>
</div>
)
}
const TILES: AiBentoTile[] = [
{
id: "chart",
title: "Chart my data",
hint: "Paste a table and get a chart you can restyle.",
art: "chart",
big: true,
},
{
id: "cards",
title: "Build a section",
hint: "Describe it and Mira lays it out from your registry.",
art: "cards",
big: true,
},
{
id: "type",
title: "Animate a headline",
hint: "Word by word, on load.",
art: "type",
},
{
id: "toggle",
title: "Add a toggle",
hint: "Monthly or yearly.",
art: "toggle",
},
{
id: "voice",
title: "Talk it through",
hint: "Say it out loud.",
art: "voice",
},
]
function Bento() {
const root = React.useRef<HTMLDivElement>(null)
const [hands, touch] = useIdleHands()
const [active, setActive] = React.useState<string | null>(null)
const [picked, setPicked] = React.useState<string | null>(null)
const run = React.useRef(0)
useAiLoop(
root,
async ({ sleep }) => {
run.current++
setPicked(null)
setActive(null)
await sleep(1200)
for (const tile of TILES) {
setActive(tile.id)
await sleep(1500)
}
setActive("cards")
await sleep(900)
setPicked("Build a section")
await sleep(2200)
},
{ gap: 300, enabled: !hands, still: () => setActive("chart") }
)
return (
<div
ref={root}
className="aik-wld-scene"
onPointerDown={touch}
onKeyDown={touch}
>
<div className="aik-wld-strip">
{picked ? (
<Mark status="run" />
) : (
<Face size={22} shape="orb" mood="idle" />
)}
<Roll>
{picked ? `Mira is starting: ${picked}` : "What should we try first?"}
</Roll>
</div>
<AiWelcomeBento
tiles={TILES}
active={hands ? null : active}
onPick={(tile) => {
const mine = ++run.current
setPicked(tile.title)
void wait(2600).then(() => {
if (run.current === mine) setPicked(null)
})
}}
/>
</div>
)
}
const PROMPT = "Add a pricing section with a toggle"
const REPLY =
"On it. I will reuse the cards from your registry and add a monthly and yearly toggle. Here is the plan."
function Hero() {
const root = React.useRef<HTMLDivElement>(null)
const [hands, touch] = useIdleHands()
const [value, setValue] = React.useState("")
const [docked, setDocked] = React.useState(false)
const [working, setWorking] = React.useState(false)
const [asked, setAsked] = React.useState("")
const [reply, setReply] = React.useState("")
const run = React.useRef(0)
const send = React.useCallback(
async (text: string, sleep: (ms: number) => Promise<void>) => {
const mine = ++run.current
const alive = () => run.current === mine
setAsked(text)
setReply("")
setValue("")
setDocked(true)
setWorking(true)
await sleep(1300)
let out = ""
for (const word of REPLY.split(" ")) {
if (!alive()) return
out += (out ? " " : "") + word
setReply(out)
await sleep(paceToken(word, 40))
}
if (!alive()) return
setWorking(false)
await sleep(2600)
if (!alive()) return
setDocked(false)
await sleep(500)
if (!alive()) return
setAsked("")
setReply("")
},
[]
)
useAiLoop(
root,
async ({ sleep }) => {
run.current++
setDocked(false)
setWorking(false)
setValue("")
setAsked("")
setReply("")
await sleep(3000)
await typeInto(setValue, PROMPT, sleep, 34)
await sleep(600)
await send(PROMPT, sleep)
await sleep(400)
},
{ gap: 300, enabled: !hands }
)
return (
<div
ref={root}
className="aik-wld-scene"
onPointerDown={touch}
onKeyDown={touch}
>
<AiHeroDock
greeting="What should we make?"
placeholders={[
"Add a pricing section with a toggle",
"Reveal the hero headline word by word",
"Find out why my slider jumps",
"Write the docs page for this component",
]}
value={value}
onValueChange={setValue}
docked={docked}
working={working}
height={430}
onSubmit={(text) => void send(text, wait)}
>
{asked ? (
<div key={asked} className="aik-wld-user">
{asked}
</div>
) : null}
{reply ? (
<div className="aik-wld-bot">
<Face size={28} shape="orb" mood={working ? "talk" : "happy"} />
<p>
{reply}
{working ? <i className="aik-caret" /> : null}
</p>
</div>
) : null}
</AiHeroDock>
</div>
)
}
export function AiWelcomeDemo({ only }: { only?: string }) {
return (
<>
<AiStyle id="ai-welcome-demo" css={CSS} />
<AiDemo
only={only}
tabs={[
{ name: "Greeting", node: <Greeting /> },
{ name: "Bento", node: <Bento /> },
{ name: "Hero dock", node: <Hero /> },
]}
/>
</>
)
}
Installation
Usage
import {
AiHeroDock,
AiWelcomeBento,
AiWelcomeGreeting,
} from "@/components/ui/ai-welcome"<AiWelcomeGreeting
greeting="What are we building today?"
line="Mira knows this project. Pick a start, or just ask."
starters={[
{
id: "build",
title: "Build a section",
hint: "Pricing with a monthly toggle",
icon: <LayoutGrid size={18} />,
},
// three more
]}
onPick={(starter) => send(starter.hint)}
/>const [docked, setDocked] = useState(false)
<AiHeroDock
greeting="What should we make?"
placeholders={["Add a pricing section", "Reveal the hero word by word"]}
value={value}
onValueChange={setValue}
docked={docked}
working={status === "streaming"}
onSubmit={(text) => {
setDocked(true)
send(text)
}}
>
{messages}
</AiHeroDock>Versions
AiWelcomeGreetingis an empty state with a face that watches. Its eyes follow the pointer and turn to whichever starter is hovered or focused. Passlookandactiveto drive it yourself.AiWelcomeBentois a bento of things to try. Each tile is a button with a small illustration that plays under the pointer or on focus: a chart draws, cards fan, a line types, a switch flips, a voice meter moves.AiHeroDockis the empty state that becomes the chat. One centred prompt rolls through examples. Setdockedon the first send and it glides to the bottom while the thread you pass as children opens above.
Props
AiWelcomeGreeting
| Prop | Type | Default | Description |
|---|---|---|---|
greeting | string | The headline. | |
line | string | A sentence under it. | |
starters | AiStarter[] | id, title, hint, icon. Four fill the grid. | |
onPick | (starter: AiStarter) => void | Called on click or Enter. | |
active | string | null | null | Highlights a starter, as hover does. |
look | { x: number; y: number } | Where the face looks, -1 to 1. Omit to follow the pointer. | |
mood | mood | Overrides the face's own mood. | |
agent | { tone?, shape? } | The face. |
AiWelcomeBento
| Prop | Type | Default | Description |
|---|---|---|---|
tiles | AiBentoTile[] | id, title, hint, art, big. Two big and three small. | |
onPick | (tile: AiBentoTile) => void | Called on click or Enter. | |
active | string | null | null | Plays a tile's illustration, as hover does. |
art is "chart", "cards", "type", "toggle", "voice", or your own node.
AiHeroDock
| Prop | Type | Default | Description |
|---|---|---|---|
greeting | string | The headline over the centred prompt. | |
placeholders | string[] | Examples the empty field rolls through. | |
value | string | The field's text. | |
onValueChange | (value: string) => void | Called on every edit. | |
onSubmit | (value: string) => void | Called on Enter or send. | |
docked | boolean | True glides the prompt to the bottom and shows children. | |
working | boolean | false | Runs the edge light round the dock. |
height | number | 420 | The frame's height in pixels. |