Prompt Input
shadcn-collections/prompt-inputFreeComponent
Prompt Input
Install it
npx shadcn@latest add https://chatcn.me/r/prompt-input.jsonSource
1"use client";2import React, { useEffect, useRef } from "react";3import { Textarea } from "@/components/ui/textarea";4import { createContext, useContext, useState } from "react";5import {6 Tooltip,7 TooltipProvider,8 TooltipTrigger,9 TooltipContent,10} from "@/components/ui/tooltip";11import { cn } from "@/lib/utils";12import { Metadata } from "next";1314type PromptInputContext = {15 value: string;16 isLoading: boolean;17 disabled?: boolean;18 setValue: (value: string) => void;19 maxHeight: string | number;20 onSubmit?: () => void;21 textareaRef: React.RefObject<HTMLTextAreaElement | null>;22};2324const PromptInputContext = createContext<PromptInputContext>({25 value: "",26 isLoading: false,27 setValue: () => {},28 maxHeight: 240,29 disabled: false,30 textareaRef: React.createRef<HTMLTextAreaElement>(),31});3233function usePromptInputContext() {34 const ctx = useContext(PromptInputContext);35 if (!ctx) {36 throw Error("usePromptInputContext must be used within a PromptInput");37 }38 return ctx;39}4041type PromptInputTextAreaProps = {42 disableAutoSize?: boolean;43} & React.ComponentProps<typeof Textarea>;4445export const metadata: Metadata = {46 title: "Prompt Input — Chatcn",47 description:48 "A ready-made prompt input component for AI chat interfaces. Customizable, responsive, and built with shadcn.",49 openGraph: {50 images: [51 {52 url: "https://chatcn.me/og-default.png",53 width: 1200,54 height: 630,55 alt: "Prompt Input Component Preview",56 },57 ],58 },59 twitter: {60 images: ["https://chatcn.me/og-default.png"],61 },62};6364export function PromptInputTextArea({65 className,66 disableAutoSize = false,67 ...props68}: PromptInputTextAreaProps) {69 const { disabled, value, setValue, maxHeight, textareaRef } =70 usePromptInputContext();7172 useEffect(() => {73 if (disableAutoSize || !textareaRef.current) return;74 textareaRef.current.style.height = "auto";75 textareaRef.current.style.height =76 typeof maxHeight == "number"77 ? `${Math.min(textareaRef.current.scrollHeight, maxHeight)}px`78 : `min(${maxHeight},${textareaRef.current.scrollHeight}px)`;79 }, [value, maxHeight, disableAutoSize, textareaRef]);8081 return (82 <Textarea83 style={{ backgroundColor: "transparent" }}84 ref={textareaRef}85 value={value}86 onChange={(e) => setValue(e.target.value)}87 rows={1}88 className={cn(89// … truncated
What it pulls in
Other registry items
Files it writes
More from shadcn-collections
All 24 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Audio Visualizeraudio-visualizer | shadcn-collections | Components | Free | 4 deps | |
| Calendarcalendar | shadcn-collections | Components | Free | no deps | |
| Chat Containerchat-container | shadcn-collections | Components | Free | no deps | |
| Code Editorcode-editor | shadcn-collections | Components | Free | no deps | |
| Code Blockcodeblock | shadcn-collections | Components | Free | 1 dep | |
| Command Blockcommand-block | shadcn-collections | Components | Free | no deps | |
| Command Tabscommand-tabs | shadcn-collections | Components | Free | no deps | |
| Emailemail | shadcn-collections | Components | Free | no deps |
