2026-08-22 04:28:13 +03:00
|
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
|
|
import { CornerDownLeftIcon, SquareIcon } from "lucide-react";
|
|
|
|
|
|
import { cn } from "@/lib/utils";
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2026-08-22 05:02:15 +03:00
|
|
|
|
* The chat composer — content row ONLY (the persistent rounded shell lives in
|
|
|
|
|
|
* the chat view's overlay, so the shell can later morph chat → question
|
|
|
|
|
|
* without remounting).
|
2026-08-22 04:28:13 +03:00
|
|
|
|
*
|
2026-08-22 05:02:15 +03:00
|
|
|
|
* Corner-radius math (concentric with the shell): shell rounded-2xl (16px) −
|
|
|
|
|
|
* row padding p-1.5 (6px) = button rounded-[10px] = 25% of the 40px button.
|
2026-08-22 04:28:13 +03:00
|
|
|
|
*/
|
|
|
|
|
|
export function Composer({
|
|
|
|
|
|
busy,
|
|
|
|
|
|
value,
|
|
|
|
|
|
onChange,
|
|
|
|
|
|
onSend,
|
|
|
|
|
|
onStop,
|
|
|
|
|
|
canSend,
|
|
|
|
|
|
autoFocus,
|
|
|
|
|
|
}: {
|
|
|
|
|
|
busy: boolean;
|
|
|
|
|
|
value: string;
|
|
|
|
|
|
onChange: (v: string) => void;
|
|
|
|
|
|
onSend: () => void;
|
|
|
|
|
|
onStop: () => void;
|
|
|
|
|
|
canSend: boolean;
|
|
|
|
|
|
autoFocus?: boolean;
|
|
|
|
|
|
}) {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<form
|
|
|
|
|
|
data-testid="composer"
|
2026-08-22 05:02:15 +03:00
|
|
|
|
className="flex items-end gap-1.5 p-1.5"
|
2026-08-22 04:28:13 +03:00
|
|
|
|
onSubmit={(e) => {
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
if (busy) onStop();
|
2026-08-22 05:02:15 +03:00
|
|
|
|
else if (canSend) onSend();
|
2026-08-22 04:28:13 +03:00
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<textarea
|
|
|
|
|
|
value={value}
|
|
|
|
|
|
onChange={(e) => onChange(e.target.value)}
|
2026-08-22 05:02:15 +03:00
|
|
|
|
onKeyDown={(e) => {
|
|
|
|
|
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
if (busy) onStop();
|
|
|
|
|
|
else if (canSend) onSend();
|
|
|
|
|
|
}
|
|
|
|
|
|
}}
|
|
|
|
|
|
placeholder="Ask, answer, or steer the lesson…"
|
2026-08-22 04:28:13 +03:00
|
|
|
|
autoFocus={autoFocus}
|
|
|
|
|
|
rows={1}
|
|
|
|
|
|
className="field-sizing-content max-h-48 min-h-10 flex-1 resize-none bg-transparent px-2.5 py-2 text-sm outline-none placeholder:text-muted-foreground"
|
|
|
|
|
|
/>
|
2026-08-22 05:02:15 +03:00
|
|
|
|
<button
|
|
|
|
|
|
type="submit"
|
|
|
|
|
|
aria-label={busy ? "Stop" : "Send"}
|
|
|
|
|
|
disabled={!busy && !canSend}
|
|
|
|
|
|
className={cn(
|
|
|
|
|
|
"flex size-10 shrink-0 items-center justify-center rounded-[10px] transition-colors",
|
|
|
|
|
|
busy
|
|
|
|
|
|
? "bg-secondary text-foreground hover:bg-accent"
|
|
|
|
|
|
: "bg-primary text-primary-foreground hover:opacity-90 disabled:opacity-40",
|
|
|
|
|
|
)}
|
|
|
|
|
|
>
|
|
|
|
|
|
{busy ? <SquareIcon className="size-4" /> : <CornerDownLeftIcon className="size-5" />}
|
|
|
|
|
|
</button>
|
2026-08-22 04:28:13 +03:00
|
|
|
|
</form>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|