# Prompt Hero
*URL: https://www.grettech.com/components/prompt-hero*

A hero built around a prompt box on a fluid gradient: the page colour flows into deep blue with drifting light, while example prompts type themselves out.

- Fluid gradient with drifting fields, a light streak and grain
- Typewriter placeholder that cycles example prompts
- Glass suggestion chips and a glowing animated border
- Enter to send, Shift + Enter for a new line, with loading state

## Install with the shadcn CLI
```bash
npx shadcn@latest add https://www.grettech.com/api/registry/prompt-hero
```
With its demo: `npx shadcn@latest add https://www.grettech.com/api/registry/prompt-hero-demo`

**Dependencies:** npm: motion, clsx, tailwind-merge

## Manual installation
**Step 1: Install dependencies**
Install the packages this component uses and the shadcn/ui components it builds on. It also needs the `cn` helper in `lib/utils.ts`, which `npx shadcn@latest init` adds.

```bash
npm install motion clsx tailwind-merge
```

**Step 2: Copy the source code**
Add these files to your project components directory.

File: `components/ui/prompt-hero.tsx`
```tsx
"use client"

import { cn } from "@/lib/utils"
import { motion, useReducedMotion } from "motion/react"
import * as React from "react"

export interface PromptHeroProps extends Omit<
  React.HTMLAttributes<HTMLElement>,
  "title" | "onSubmit"
> {
  eyebrow?: string
  title: React.ReactNode
  description?: string
  /** Example prompts typed out in the empty box, one after another */
  placeholders?: string[]
  /** Chips under the box; clicking one fills it in */
  suggestions?: string[]
  /** Called with the prompt; a returned promise shows a loading state */
  onSubmit?: (prompt: string) => void | Promise<void>
  /** Accessible name for the box */
  inputLabel?: string
  /** Small print under the box */
  note?: React.ReactNode
  /** Two colours for the glowing border and the light behind it */
  glowColors?: [string, string]
  /** Light, middle and deep colours of the fluid gradient behind the box */
  fluidColors?: [string, string, string]
}

/** An endless, eased back-and-forth; nothing for reduced motion */
const sway = (
  still: boolean,
  frames: Record<string, (number | string)[]>,
  seconds: number
) =>
  still
    ? {}
    : {
        animate: frames,
        transition: {
          duration: seconds,
          ease: "easeInOut" as const,
          repeat: Infinity,
        },
      }

// Fine film grain as an inline SVG, so there's no image to ship
const GRAIN = `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E")`

const REDUCED = "(prefers-reduced-motion: reduce)"
function subscribeReducedMotion(onChange: () => void) {
  const media = window.matchMedia(REDUCED)
  media.addEventListener("change", onChange)
  return () => media.removeEventListener("change", onChange)
}

/** Types each line out, pauses, deletes it and moves to the next */
function useTypewriter(lines: string[], running: boolean) {
  const joined = lines.join("\n")
  const list = React.useMemo(() => joined.split("\n").filter(Boolean), [joined])
  const [state, setState] = React.useState({
    line: 0,
    chars: 0,
    deleting: false,
  })
  const reduced = React.useSyncExternalStore(
    subscribeReducedMotion,
    () => window.matchMedia(REDUCED).matches,
    () => false
  )

  React.useEffect(() => {
    if (!running || list.length === 0) return
    const text = list[state.line % list.length]
    let delay = 300
    let next = {
      line: (state.line + 1) % list.length,
      chars: 0,
      deleting: false,
    }
    if (reduced)
      delay = 3500 // whole lines, swapped slowly
    else if (!state.deleting && state.chars < text.length)
      [delay, next] = [38, { ...state, chars: state.chars + 1 }]
    else if (!state.deleting)
      [delay, next] = [1800, { ...state, deleting: true }]
    else if (state.chars > 0)
      [delay, next] = [16, { ...state, chars: state.chars - 1 }]
    const timer = window.setTimeout(() => setState(next), delay)
    return () => window.clearTimeout(timer)
  }, [state, running, list, reduced])

  const text = list[state.line % Math.max(1, list.length)] ?? ""
  return reduced ? text : text.slice(0, state.chars)
}

function Icon({ name }: { name: "send" | "sent" | "busy" }) {
  if (name === "busy")
    return (
      <span className="size-4 animate-spin rounded-full border-2 border-current border-t-transparent" />
    )
  return (
    <svg
      viewBox="0 0 16 16"
      aria-hidden="true"
      className="size-4"
      fill="none"
      stroke="currentColor"
      strokeWidth="2"
      strokeLinecap="round"
      strokeLinejoin="round"
    >
      {name === "send" ? (
        <path d="M8 13V3M3.5 7.5L8 3l4.5 4.5" />
      ) : (
        <path d="M3 8.5l3 3 7-7" />
      )}
    </svg>
  )
}

/**
 * A hero built around a prompt box, for AI products and tools: the empty
 * box types out example prompts, suggestion chips fill it in, and a slow
 * glow runs around its border. Enter sends, Shift + Enter adds a line.
 */
export const PromptHero = React.forwardRef<HTMLElement, PromptHeroProps>(
  (
    {
      eyebrow,
      title,
      description,
      placeholders = [],
      suggestions = [],
      onSubmit,
      inputLabel = "Describe what you want to make",
      note,
      glowColors = ["#8b5cf6", "#22d3ee"],
      fluidColors = ["#8cc4ff", "#1a70ea", "#0a47c8"],
      className,
      ...props
    },
    ref
  ) => {
    const [value, setValue] = React.useState("")
    const [focused, setFocused] = React.useState(false)
    const [status, setStatus] = React.useState<"idle" | "sending" | "sent">(
      "idle"
    )
    const box = React.useRef<HTMLTextAreaElement>(null)
    const id = React.useId()
    const typed = useTypewriter(placeholders, value === "" && !focused)
    const [c1, c2] = glowColors
    const [light, mid, deep] = fluidColors
    const still = useReducedMotion() ?? false

    // Grow with the text, up to about six lines
    React.useLayoutEffect(() => {
      const el = box.current
      if (!el) return
      el.style.height = "auto"
      el.style.height = `${Math.min(el.scrollHeight, 200)}px`
    }, [value])

    const submit = async () => {
      const prompt = value.trim()
      if (!prompt || status === "sending") return
      try {
        setStatus("sending")
        await onSubmit?.(prompt)
        setValue("")
        setStatus("sent")
        window.setTimeout(() => setStatus("idle"), 2000)
      } catch {
        setStatus("idle")
      }
    }

    return (
      <section
        ref={ref}
        className={cn(
          "relative isolate flex w-full flex-col items-center overflow-hidden bg-background px-6 pt-24 pb-28 sm:pt-28 sm:pb-36",
          className
        )}
        {...props}
      >
        {/* Fluid gradient: the page colour at the top flowing into deep
          colour below, with drifting fields, a streak of light and grain */}
        <div
          aria-hidden="true"
          className="pointer-events-none absolute inset-0 -z-10 overflow-hidden"
        >
          <div
            className="absolute inset-0"
            style={{
              backgroundImage: `linear-gradient(175deg, transparent 0%, transparent 28%, ${light} 48%, ${mid} 64%, ${deep} 100%)`,
            }}
          />
          {/* Two fields of colour drifting slowly, and a streak of light */}
          <motion.div
            className="absolute -right-[15%] -bottom-[30%] h-[95%] w-[80%] rounded-full blur-3xl"
            style={{
              backgroundImage: `radial-gradient(closest-side, ${deep}, ${mid} 50%, transparent)`,
            }}
            {...sway(
              still,
              {
                x: ["0%", "-8%", "0%"],
                y: ["0%", "-6%", "0%"],
                scale: [1, 1.12, 1],
              },
              18
            )}
          />
          <motion.div
            className="absolute top-[35%] -left-[18%] h-[75%] w-[50%] rounded-full blur-3xl"
            style={{
              backgroundImage: `radial-gradient(closest-side, ${mid}, ${light} 60%, transparent)`,
            }}
            initial={{ scale: 1.08 }}
            {...sway(
              still,
              {
                x: ["0%", "10%", "0%"],
                y: ["0%", "4%", "0%"],
                scale: [1.08, 0.96, 1.08],
                rotate: [0, -6, 0],
              },
              22
            )}
          />
          <motion.div
            className="absolute top-[30%] left-[8%] h-[130%] w-[16%] bg-[linear-gradient(90deg,transparent,rgba(235,244,255,0.85),transparent)] blur-2xl"
            initial={{ x: "-6%", rotate: -34, opacity: 0.7 }}
            {...sway(
              still,
              {
                x: ["-6%", "8%", "-6%"],
                rotate: [-34, -30, -34],
                opacity: [0.7, 1, 0.7],
              },
              14
            )}
          />
          {/* Keep the title area the page colour, then deepen for dark mode */}
          <div className="absolute inset-x-0 top-0 h-[42%] bg-linear-to-b from-background from-40% to-transparent" />
          <div className="absolute inset-0 hidden bg-black/45 dark:block" />
          <div
            className="absolute inset-0 opacity-[0.14] mix-blend-overlay dark:opacity-[0.1]"
            style={{ backgroundImage: GRAIN }}
          />
        </div>

        <div className="flex w-full max-w-2xl flex-col items-center text-center">
          {eyebrow && (
            <p className="mb-5 rounded-full border bg-background/60 px-3 py-1 text-xs font-medium text-muted-foreground backdrop-blur">
              {eyebrow}
            </p>
          )}
          <h1 className="text-4xl leading-[1.08] font-semibold tracking-tight text-balance text-foreground sm:text-6xl">
            {title}
          </h1>
          {description && (
            <p className="mt-5 max-w-xl text-base text-pretty text-muted-foreground sm:text-lg">
              {description}
            </p>
          )}

          <form
            onSubmit={(e) => {
              e.preventDefault()
              void submit()
            }}
            className="relative mt-10 w-full text-left"
          >
            {/* Soft light under the box */}
            <div
              aria-hidden="true"
              className="absolute -inset-3 -z-10 rounded-[28px] opacity-30 blur-2xl dark:opacity-25"
              style={{
                backgroundImage: `linear-gradient(90deg, ${c1}, ${c2})`,
              }}
            />
            {/* Border: a faint ring with a bright arc travelling round it */}
            <div className="relative rounded-2xl bg-border p-px shadow-[0_20px_70px_-30px_rgba(0,0,0,0.35)]">
              <div
                aria-hidden="true"
                className="absolute inset-0 overflow-hidden rounded-2xl"
              >
                {/* A glow running round the border */}
                <motion.div
                  className="absolute top-1/2 left-1/2 aspect-square w-[200%] -translate-x-1/2 -translate-y-1/2"
                  style={{
                    backgroundImage: `conic-gradient(from 0deg, transparent 0deg, ${c1} 50deg, ${c2} 100deg, transparent 150deg, transparent 360deg)`,
                  }}
                  {...(!still && {
                    animate: { rotate: 360 },
                    transition: {
                      duration: 6,
                      ease: "linear",
                      repeat: Infinity,
                    },
                  })}
                />
              </div>

              <div className="relative rounded-[15px] bg-background p-3 sm:p-4">
                <label htmlFor={id} className="sr-only">
                  {inputLabel}
                </label>
                <div className="relative">
                  <textarea
                    ref={box}
                    id={id}
                    rows={2}
                    value={value}
                    onChange={(e) => setValue(e.target.value)}
                    onFocus={() => setFocused(true)}
                    onBlur={() => setFocused(false)}
                    onKeyDown={(e) => {
                      if (
                        e.key === "Enter" &&
                        !e.shiftKey &&
                        !e.nativeEvent.isComposing
                      ) {
                        e.preventDefault()
                        void submit()
                      }
                    }}
                    className="block w-full resize-none bg-transparent text-base text-foreground outline-none sm:text-lg"
                  />
                  {value === "" && (
                    <p
                      aria-hidden="true"
                      className="pointer-events-none absolute inset-0 text-base text-muted-foreground sm:text-lg"
                    >
                      {typed}
                      {/* A blinking caret */}
                      <motion.span
                        className="ml-px inline-block h-[1.1em] w-px translate-y-[0.18em] bg-muted-foreground"
                        {...(!still && {
                          animate: { opacity: [1, 1, 0, 0] },
                          transition: {
                            duration: 1,
                            times: [0, 0.5, 0.5, 1],
                            ease: "linear",
                            repeat: Infinity,
                          },
                        })}
                      />
                    </p>
                  )}
                </div>
                <div className="mt-3 flex items-center justify-between gap-3">
                  <span className="hidden text-xs text-muted-foreground sm:inline">
                    Enter to send · Shift + Enter for a new line
                  </span>
                  <button
                    type="submit"
                    aria-label={status === "sent" ? "Sent" : "Send"}
                    disabled={!value.trim() || status === "sending"}
                    className={cn(
                      "ml-auto flex size-9 items-center justify-center rounded-full bg-foreground text-background transition-opacity hover:opacity-90 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:outline-none disabled:opacity-30",
                      status === "sent" && "disabled:opacity-100"
                    )}
                  >
                    <Icon
                      name={
                        status === "sending"
                          ? "busy"
                          : status === "sent"
                            ? "sent"
                            : "send"
                      }
                    />
                  </button>
                </div>
              </div>
            </div>
          </form>

          {suggestions.length > 0 && (
            <div className="mt-5 flex flex-wrap justify-center gap-2">
              {suggestions.map((suggestion, i) => (
                <button
                  key={`${suggestion}-${i}`}
                  type="button"
                  onClick={() => {
                    setValue(suggestion)
                    box.current?.focus()
                  }}
                  className="rounded-full bg-white/15 px-3 py-1.5 text-xs font-medium text-white ring-1 ring-white/30 backdrop-blur-md transition-colors hover:bg-white/25 focus-visible:ring-2 focus-visible:ring-white focus-visible:outline-none"
                >
                  {suggestion}
                </button>
              ))}
            </div>
          )}

          {note && <p className="mt-6 text-xs text-white/75">{note}</p>}
        </div>
      </section>
    )
  }
)
PromptHero.displayName = "PromptHero"

```

**Step 3: Framework Adjustments (Optional)**
If you are manually copying this code into a Vite or Remix project (without using the CLI), make sure to remove the `"use client";` directive from the very top of the file.

## Props
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| `title` | `React.ReactNode` | - | Yes | The main headline. |
| `eyebrow` | `string` | - | No | Small label above the title. |
| `description` | `string` | - | No | Supporting text under the title. |
| `placeholders` | `string[]` | `[]` | No | Example prompts typed out in the empty box, one after another. |
| `suggestions` | `string[]` | `[]` | No | Chips under the box; clicking one fills it in. |
| `onSubmit` | `(prompt: string) => void \| Promise<void>` | - | No | Called with the prompt. A returned promise shows a loading state; the box clears when it resolves. |
| `inputLabel` | `string` | `"Describe what you want to make"` | No | Accessible name for the box. |
| `note` | `React.ReactNode` | - | No | Small print under the box. |
| `glowColors` | `[string, string]` | `["#8b5cf6", "#22d3ee"]` | No | Two colours for the border glow and the light behind it. |
| `fluidColors` | `[string, string, string]` | `["#8cc4ff", "#1a70ea", "#0a47c8"]` | No | Light, middle and deep colours of the fluid gradient. |
| `className` | `string` | - | No | Extra classes for the section. |

## Usage
```tsx
"use client"

import { PromptHero } from "@/components/ui/prompt-hero"

export default function PromptHeroDemo() {
  return (
    <PromptHero
      eyebrow="Draftly"
      title="What are we building today?"
      description="Describe your idea and Draftly turns it into a page plan, wireframes and a first draft of the copy."
      placeholders={[
        "A landing page for my yoga studio with class bookings",
        "An onboarding flow for a budgeting app",
        "A pricing page with three plans and an FAQ",
        "A portfolio for a wedding photographer",
      ]}
      suggestions={[
        "Landing page",
        "Pricing page",
        "Booking flow",
        "Portfolio",
      ]}
      onSubmit={() => new Promise((resolve) => setTimeout(resolve, 900))}
      note="Drafts stay private until you share them."
      className="rounded-3xl border bg-background"
    />
  )
}

```
