# 프롬프트 입력

채팅과 에이전트 화면에서 쓰는 메시지 입력창이에요. 글에 맞춰 늘어나고 첨부, 모드, 보내기 버튼이 있어요.

- Type: component
- Theme: base
- Tags: component, prompt, chat, composer, ai, input, liquid-glass
- English title: Prompt input
- Version: 1.0.0 (updated 2026-11-26)
- URL: https://dsui.vercel.app/items/prompt-input

## Version history

- 1\.0.0 (2026-11-26): First release.

## Used items

- [리퀴드 글래스](https://dsui.vercel.app/items/liquid-glass): 빛이 굴절하고 물결이 흐르는 유리 면이에요. 원하는 내용을 감싸거나 글자를 유리로 채울 수 있어요.

## Controls

| Key | Type | Label | Default |
| --- | --- | --- | --- |
| variant | select | 변형 | default |
| mode | text | 모드 | 에이전트 |
| busy | boolean | 답을 기다리는 중 | false |
| disabled | boolean | 비활성 | false |

## Source

### prompt-input.module.css

```css
/* The wrapper draws the field. Following the input rule, focus fills it with the accent and the ink flips; the box never changes size. */
.root { --prompt-ink: var(--foreground); --prompt-soft: var(--text-muted); --prompt-chip: var(--surface-muted); --prompt-send: var(--accent); --prompt-send-ink: var(--accent-foreground); position: relative; display: grid; gap: var(--space-2); box-sizing: border-box; width: min(100%, 36rem); border: 1px solid var(--border-strong); border-radius: var(--radius-panel); padding: var(--space-3); background: var(--surface); color: var(--prompt-ink); cursor: text; transition: background-color var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard); }
@media (hover: hover) and (pointer: fine) { .root:hover:not(:focus-within, [data-disabled]) { border-color: var(--foreground); } }
.root:focus-within:not(.glass) { --prompt-ink: var(--accent-foreground); --prompt-soft: var(--accent-foreground-muted); --prompt-chip: color-mix(in oklab, var(--accent-foreground) 16%, transparent); --prompt-send: var(--accent-foreground); --prompt-send-ink: var(--accent); border-color: var(--accent); background: var(--accent); }
.root[data-disabled] { cursor: not-allowed; background: var(--surface-muted); opacity: .6; }
.field { display: block; width: 100%; min-height: 3rem; max-height: 12rem; resize: none; border: 0; padding: var(--space-2) var(--space-2) 0; background: transparent; color: inherit; caret-color: currentColor; font: inherit; font-size: var(--text-base); line-height: var(--leading-body); outline: none; }
.field::placeholder { color: var(--prompt-soft); }
.field:disabled { cursor: not-allowed; }
.bar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.tools { display: flex; min-width: 0; align-items: center; gap: var(--space-2); }
.tool, .send { display: grid; flex: none; width: var(--control-height-sm); height: var(--control-height-sm); place-items: center; border: 0; border-radius: var(--radius-pill); padding: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: background-color var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard), opacity var(--duration-fast) var(--ease-standard); }
.tool { background: var(--prompt-chip); color: var(--prompt-ink); }
.mode { display: inline-flex; min-width: 0; height: var(--control-height-sm); align-items: center; overflow: hidden; border: 0; border-radius: var(--radius-pill); padding: 0 var(--space-4); background: var(--prompt-chip); color: var(--prompt-ink); font: inherit; font-size: var(--label-sm); font-weight: var(--label-weight); text-overflow: ellipsis; white-space: nowrap; -webkit-tap-highlight-color: transparent; transition: background-color var(--duration-fast) var(--ease-standard); }
button.mode { cursor: pointer; }
@media (hover: hover) and (pointer: fine) { .tool:hover:not(:disabled), button.mode:hover:not(:disabled) { background: color-mix(in oklab, var(--prompt-ink) 16%, transparent); } }
.tool:active:not(:disabled), button.mode:active:not(:disabled) { background: color-mix(in oklab, var(--prompt-ink) 24%, transparent); }
.send { background: var(--prompt-send); color: var(--prompt-send-ink); }
.send:disabled { cursor: not-allowed; opacity: .4; }
.send[aria-busy="true"] { cursor: progress; }
@media (hover: hover) and (pointer: fine) { .send:hover:not(:disabled) { opacity: .9; } }
.tool:disabled, .mode:disabled { cursor: not-allowed; }
.spinner { width: var(--space-4); height: var(--space-4); border: 1.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: prompt-spin .7s linear infinite; }
@keyframes prompt-spin { to { transform: rotate(360deg); } }
/* Liquid glass: the layer paints the slab, so focus keeps the glass instead of filling it. The chips become thin glass tints. */
.glass { --prompt-chip: color-mix(in oklab, var(--foreground) 10%, transparent); --prompt-soft: color-mix(in oklab, var(--foreground) 62%, transparent); --prompt-send: var(--foreground); --prompt-send-ink: var(--background); }
@media (prefers-reduced-motion: reduce) { .root, .tool, .send, .mode { transition: none; } .spinner { animation-duration: .01ms; animation-iteration-count: 1; } }

```

### prompt-input.tsx

```tsx
"use client";

import { forwardRef, useCallback, useLayoutEffect, useRef, useState } from "react";
import type { FormEvent, KeyboardEvent } from "react";
import { motion } from "motion/react";
import { useReducedMotion } from "../lib/use-reduced-motion";
import { motionTokens } from "../lib/motion-tokens";
import { UiIcon } from "../theme/ui-icon";
import { playUiSound } from "../sound/play";
import { LiquidGlassLayer, liquidGlassHost } from "../liquid-glass/liquid-glass-layer";
import styles from "./prompt-input.module.css";

export interface PromptInputProps {
  value?: string;
  defaultValue?: string;
  onValueChange?: (value: string) => void;
  /** Called with the trimmed text on Enter or the send button. The field clears itself when it is uncontrolled. */
  onSubmit?: (value: string) => void;
  placeholder?: string;
  /** Accessible name of the text field. */
  label?: string;
  /** Shows the add button. Use it to attach a file or pick context. */
  onAttach?: () => void;
  /** A small pill next to the add button, such as the current mode or agent. */
  mode?: string;
  onModeClick?: () => void;
  /** Waiting for an answer: the send button spins and Enter does nothing. */
  busy?: boolean;
  disabled?: boolean;
  /** `liquid-glass` draws the composer as a slab of glass. Put it over a photo, a gradient or a busy page. */
  variant?: "default" | "liquid-glass";
  className?: string;
}

/** A message composer for chat and agent screens: a field that grows with its text, an add button, a mode pill and a send button. */
export const PromptInput = forwardRef<HTMLTextAreaElement, PromptInputProps>(function PromptInput(
  { value, defaultValue = "", onValueChange, onSubmit, placeholder = "무엇이든 물어보세요", label = "메시지 입력", onAttach, mode, onModeClick, busy = false, disabled = false, variant = "default", className },
  ref,
) {
  const reduced = useReducedMotion() ?? false;
  const [internal, setInternal] = useState(defaultValue);
  const text = value ?? internal;
  const field = useRef<HTMLTextAreaElement | null>(null);
  const setRefs = useCallback((node: HTMLTextAreaElement | null) => {
    field.current = node;
    if (typeof ref === "function") ref(node); else if (ref) ref.current = node;
  }, [ref]);
  const glass = variant === "liquid-glass";
  const ready = text.trim().length > 0 && !busy && !disabled;

  // The field is as tall as its text, up to the cap in the stylesheet; past that it scrolls.
  useLayoutEffect(() => {
    const node = field.current;
    if (!node) return;
    node.style.height = "auto";
    node.style.height = `${node.scrollHeight}px`;
  }, [text]);

  const change = (next: string) => { if (value === undefined) setInternal(next); onValueChange?.(next); };
  const send = () => {
    if (!ready) return;
    playUiSound("confirm");
    onSubmit?.(text.trim());
    if (value === undefined) setInternal("");
  };
  const onKeyDown = (event: KeyboardEvent<HTMLTextAreaElement>) => {
    // Enter sends; Shift+Enter breaks the line. A key press that is still composing Korean must not send.
    if (event.key !== "Enter" || event.shiftKey || event.nativeEvent.isComposing) return;
    event.preventDefault();
    send();
  };
  const press = reduced || disabled ? undefined : { scale: .9 };

  return (
    <form
      className={[styles.root, glass ? `${liquidGlassHost} ${styles.glass}` : undefined, className].filter(Boolean).join(" ")}
      data-disabled={disabled || undefined}
      onSubmit={(event: FormEvent) => { event.preventDefault(); send(); }}
      onClick={event => { if (event.target === event.currentTarget) field.current?.focus(); }}
    >
      {glass ? <LiquidGlassLayer preset="prompt" /> : null}
      <textarea ref={setRefs} className={styles.field} rows={1} value={text} placeholder={placeholder} aria-label={label} disabled={disabled} onChange={event => change(event.target.value)} onKeyDown={onKeyDown} />
      <div className={styles.bar}>
        <div className={styles.tools}>
          {onAttach ? <motion.button type="button" className={styles.tool} aria-label="첨부하기" disabled={disabled} whileTap={press} transition={motionTokens.spring.snappy} onClick={() => { playUiSound("click"); onAttach(); }}><UiIcon iconRole="plus" width={18} height={18} aria-hidden="true" /></motion.button> : null}
          {mode ? onModeClick
            ? <motion.button type="button" className={styles.mode} disabled={disabled} whileTap={reduced || disabled ? undefined : { scale: .94 }} transition={motionTokens.spring.snappy} onClick={() => { playUiSound("click"); onModeClick(); }}>{mode}</motion.button>
            : <span className={styles.mode}>{mode}</span> : null}
        </div>
        <motion.button type="submit" className={styles.send} aria-label={busy ? "답을 기다리는 중이에요" : "보내기"} aria-busy={busy || undefined} disabled={!ready && !busy} aria-disabled={busy || undefined} whileHover={reduced || !ready ? undefined : { scale: 1.04 }} whileTap={ready ? press : undefined} transition={motionTokens.spring.snappy}>
          {busy ? <span className={styles.spinner} aria-hidden="true" /> : <UiIcon iconRole="arrow-up" width={18} height={18} aria-hidden="true" />}
        </motion.button>
      </div>
    </form>
  );
});

PromptInput.displayName = "PromptInput";

export default PromptInput;

```
