AI field
FreeA one-line field for asking about what the agent did, with a still gradient rim and the send button inset as far from the edge as from the top and bottom.
npx shadcn@latest add https://pixilui.com/r/ai-field.jsonPreview
A still gradient rim marks the field that asks the agent.
Size
import { useState } from "react";
import { IconAi } from "@/components/pixilui/icons/ai";
import { IconSendStop } from "@/components/pixilui/icons/send-stop";
import { AiField } from "@/components/pixilui/ai-field";
// The first option of each knob is the demo's default; the docs preview starts there.
export const knobs = {
size: ["xl", "lg", "md"],
} as const;
/** A question about today's runs; the last one asked shows under it. */
export default function AiFieldDemo({ size = "xl" }: KnobValues<typeof knobs>) {
const [asked, setAsked] = useState<string | null>(null);
return (
<div className="flex w-full max-w-md flex-col gap-3">
<AiField label="Ask about these runs" icon={<IconAi />} sendIcon={<IconSendStop />} placeholder="Why did three refunds fail today?" onSubmit={setAsked} size={size} />
<p className="type-caption text-muted">{asked ? `Asked: ${asked}` : "Nothing asked yet"}</p>
</div>
);
}When to use
Use it when
- Asking a question about runs, a table or a trace, in a page header or a panel.
Use something else when
- A full chat composer with attachments: use the composer.
Installation
Terminal
npx shadcn@latest add https://pixilui.com/r/ai-field.jsonAdds ai-field.tsx with field.tsx, and installs clsx and tailwind-merge. The URL works in any app with a components.json, with no registry to add first.
components/pixilui/ai-field.tsx
"use client";
/*
The AI field, locked 1 Dec 2026 (design/explorations/components/locked/inputs, B8): ask a question about
what the agent did. The frame is the Field's (../field/field); the look is foundation.css section 8.
Rim lively: a still gradient rim, focus blue through the running and waiting hues, fully there at
rest (no motion, no glow). Quiet: the plain rim, and the focus ring on focus.
Send a round action inside the field, as far from the right edge as from the top and bottom.
Enter sends too, never in the middle of composing (Japanese, Chinese input).
Typing native: nothing animates on keys.
*/
import { forwardRef, useImperativeHandle, useRef, useState, type ChangeEvent, type ComponentPropsWithoutRef, type KeyboardEvent, type ReactNode } from "react";
import { cn } from "./lib/utils";
import { Field, FieldControl, FieldInput, FieldPrefix, FieldSuffix, type FieldSize } from "./field";
export type AiFieldProps = Omit<ComponentPropsWithoutRef<"input">, "size" | "prefix" | "onSubmit"> & {
/** The label above the field ("Ask about these runs"). */
label?: ReactNode;
/** The icon before the text (the animated ai icon). */
icon?: ReactNode;
/** The send button's icon (the animated send-stop icon). */
sendIcon: ReactNode;
/** The send button's name. */
sendLabel?: string;
/** Runs with the trimmed question on Enter or the send button. Nothing runs for an empty field. */
onSubmit?: (question: string) => void;
/** The button height of the same name; xl (44) by default, as the locked page shows it. */
size?: FieldSize;
/** Classes for the field. Native attributes and the ref go to the input. */
className?: string;
};
/** A field for asking about the agent's work, with a still gradient rim and a send inside it. */
export const AiField = forwardRef<HTMLInputElement, AiFieldProps>(function AiField(
{ label, icon, sendIcon, sendLabel = "Ask", onSubmit, size = "xl", className, value, defaultValue, onChange, onKeyDown, id, ...props },
ref,
) {
const input = useRef<HTMLInputElement | null>(null);
useImperativeHandle(ref, () => input.current!, []);
const [inner, setInner] = useState(String(defaultValue ?? ""));
const current = value != null ? String(value) : inner;
const send = () => {
const q = (input.current?.value ?? current).trim();
if (q) onSubmit?.(q);
};
return (
<Field className={className} label={label} glow="ai" size={size} filled={current.length > 0} inputId={id}>
<FieldControl>
{icon != null ? <FieldPrefix>{icon}</FieldPrefix> : null}
<FieldInput
ref={input}
type="text"
value={value}
defaultValue={defaultValue}
onChange={(event: ChangeEvent<HTMLInputElement>) => {
if (value == null) setInner(event.target.value);
onChange?.(event);
}}
onKeyDown={(event: KeyboardEvent<HTMLInputElement>) => {
onKeyDown?.(event);
if (event.defaultPrevented || event.nativeEvent.isComposing || event.key !== "Enter") return;
event.preventDefault();
send();
}}
{...props}
/>
<FieldSuffix>
{/* the send: the accent disc with the light icon, as the locked page draws it (inputs.page.css .in-send) */}
<button type="button" aria-label={sendLabel} onClick={send} className={cn("pixilui-field-action cursor-pointer rounded-full bg-accent-solid text-accent-contrast [&_svg]:size-4")}>
{sendIcon}
</button>
</FieldSuffix>
</FieldControl>
</Field>
);
});
It uses Field: add it the same way. Then npm i clsx tailwind-merge, and add the foundation once per app, as in Installation.
Usage
example.tsx
import { AiField } from "@/components/pixilui/ai-field";
<AiField sendIcon={sendIcon} onSubmit={onSubmit} />Fills its container's width; the label row and the message wrap.
API reference
PropTypeDefault
sendIconRequiredReactNode–The send button's icon (the animated send-stop icon).labelReactNode–The label above the field ("Ask about these runs").iconReactNode–The icon before the text (the animated ai icon).sendLabelstring"Ask"The send button's name.onSubmit(question: string) => void–Runs with the trimmed question on Enter or the send button. Nothing runs for an empty field.sizeFieldSize"xl"The button height of the same name; xl (44) by default, as the locked page shows it.classNamestring–Classes for the field. Native attributes and the ref go to the input.Also takes every native <input> attribute except size, prefix, onSubmit, and a ref.
Keyboard
EnterSends the question, never in the middle of composing.
Accessibility
- The send button is labelled (sendLabel, "Ask").
Motion
- None of its own: the rim is still, by design. Quiet keeps the plain rim and the focus ring.