Skip to main content
BlocksAI ChatAssistant composer with voice dictation

shadcn/ui AI Chat block for Base UIAssistant composer with voice dictation

A pill-shaped shadcn/ui AI chat composer that expands into a rounded card as the prompt grows. Includes an attachments menu with agent and research modes, microphone and waveform buttons for voice dictation, and a send button that enables once text is entered. Built with shadcn/ui Button, DropdownMenu, and Textarea using only semantic tokens, so it adapts to any shadcn/ui theme.

Free@shadcnpro/base/ai-chat-01

Preview

Installation

npx shadcn@latest add @shadcnpro/base/ai-chat-01

First time? Add the @shadcnpro registry to components.json as shown in Installation. Free blocks install without a license key.

Let your AI editor install it

The shadcn/ui Pro MCP server lets Cursor, Claude Code and VS Code find and install blocks like Assistant composer with voice dictation from one prompt. It is included in every Pro plan.

Add the shadcn/ui components

Assistant composer with voice dictation uses Button, Dropdown Menu and Textarea, from the Base UI components set up in your components.json.

npx shadcn@latest add button dropdown-menu textarea

Install the npm packages

npm install lucide-react

Copy the code

Paste it into components/blocks/ai-chat-01.tsx.

components/blocks/ai-chat-01.tsx
'use client';

import * as React from 'react';
import {
  AudioLinesIcon,
  FlaskConicalIcon,
  MicIcon,
  PaperclipIcon,
  PlusIcon,
  SendIcon,
  SparklesIcon,
} from 'lucide-react';
import { Button } from '@/components/ui/button';
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuGroup,
  DropdownMenuItem,
  DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import { Textarea } from '@/components/ui/textarea';
import { cn } from '@/lib/utils';

/**
 * Assistant composer with voice dictation.
 * A pill-shaped prompt input that expands into a card once the message grows.
 */
export default function AiChat01() {
  const [message, setMessage] = React.useState('');
  const [isExpanded, setIsExpanded] = React.useState(false);
  const textareaRef = React.useRef<HTMLTextAreaElement>(null);
  const fileInputRef = React.useRef<HTMLInputElement>(null);

  const send = () => {
    if (!message.trim()) return;
    setMessage('');
    setIsExpanded(false);
    if (textareaRef.current) {
      textareaRef.current.style.height = 'auto';
    }
  };

  const handleSubmit = (e: React.FormEvent) => {
    e.preventDefault();
    send();
  };

  const handleTextareaChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
    setMessage(e.target.value);
    if (textareaRef.current) {
      textareaRef.current.style.height = 'auto';
      textareaRef.current.style.height = `${textareaRef.current.scrollHeight}px`;
    }
    setIsExpanded(e.target.value.length > 100 || e.target.value.includes('\n'));
  };

  const handleKeyDown = (e: React.KeyboardEvent) => {
    if (e.key === 'Enter' && !e.shiftKey) {
      e.preventDefault();
      send();
    }
  };

  return (
    <div className="w-full px-4">
      <h1 className="mx-auto mb-6 max-w-2xl text-balance text-center font-semibold text-3xl text-foreground leading-tight tracking-tight">
        What are we working on today?
      </h1>

      <form className="group/composer w-full" onSubmit={handleSubmit}>
        <input className="sr-only" multiple ref={fileInputRef} type="file" />

        <div
          className={cn(
            'mx-auto grid w-full max-w-2xl cursor-text overflow-clip border border-border bg-background bg-clip-padding p-2.5 shadow-sm dark:bg-muted/50',
            isExpanded ? 'rounded-xl' : 'rounded-full'
          )}
          style={
            isExpanded
              ? {
                  gridTemplateAreas: "'header' 'primary' 'footer'",
                  gridTemplateColumns: '1fr',
                  gridTemplateRows: 'auto 1fr auto',
                }
              : {
                  gridTemplateAreas: "'header header header' 'leading primary trailing' '. footer .'",
                  gridTemplateColumns: 'auto 1fr auto',
                  gridTemplateRows: 'auto 1fr auto',
                }
          }
        >
          <div
            className={cn(
              'flex overflow-x-hidden',
              isExpanded ? 'px-2 pt-1.5 pb-2' : '-my-2.5 min-h-14 items-center px-1.5'
            )}
            style={{ gridArea: 'primary' }}
          >
            <div className="max-h-52 flex-1 overflow-auto">
              <Textarea
                className="min-h-0 resize-none rounded-none border-0 p-0 text-base shadow-none placeholder:text-muted-foreground focus-visible:ring-0 focus-visible:ring-offset-0 md:text-base dark:bg-transparent"
                onChange={handleTextareaChange}
                onKeyDown={handleKeyDown}
                placeholder="Describe a task or ask a question"
                ref={textareaRef}
                rows={1}
                value={message}
              />
            </div>
          </div>

          <div className={cn('flex items-center', { hidden: isExpanded })} style={{ gridArea: 'leading' }}>
            <DropdownMenu>
              <DropdownMenuTrigger
                render={
                  <Button
                    aria-label="Add attachments"
                    className="rounded-full transition-[scale,background-color] duration-150 ease-out active:scale-[0.96]"
                    size="icon-lg"
                    type="button"
                    variant="ghost"
                  />
                }
              >
                <PlusIcon className="size-5 text-muted-foreground" strokeWidth={1.5} />
              </DropdownMenuTrigger>

              <DropdownMenuContent align="start" className="w-64 rounded-xl p-1.5">
                <DropdownMenuGroup className="space-y-1">
                  <DropdownMenuItem className="rounded-lg px-2.5 py-2" onClick={() => fileInputRef.current?.click()}>
                    <PaperclipIcon className="opacity-60" />
                    Upload files or images
                  </DropdownMenuItem>
                  <DropdownMenuItem className="rounded-lg px-2.5 py-2">
                    <SparklesIcon className="opacity-60" />
                    Autopilot mode
                  </DropdownMenuItem>
                  <DropdownMenuItem className="rounded-lg px-2.5 py-2">
                    <FlaskConicalIcon className="opacity-60" />
                    Extended analysis
                  </DropdownMenuItem>
                </DropdownMenuGroup>
              </DropdownMenuContent>
            </DropdownMenu>
          </div>

          <div className="flex items-center gap-2" style={{ gridArea: isExpanded ? 'footer' : 'trailing' }}>
            <div className="ms-auto flex items-center gap-1.5">
              <Button
                aria-label="Dictate a message"
                className="rounded-full transition-[scale,background-color] duration-150 ease-out active:scale-[0.96]"
                size="icon-lg"
                type="button"
                variant="ghost"
              >
                <MicIcon className="size-5 text-muted-foreground" strokeWidth={1.5} />
              </Button>

              <Button
                aria-label="Start a voice session"
                className="rounded-full transition-[scale,background-color] duration-150 ease-out active:scale-[0.96]"
                size="icon-lg"
                type="button"
                variant="ghost"
              >
                <AudioLinesIcon className="size-5 text-muted-foreground" strokeWidth={1.5} />
              </Button>

              <Button
                aria-label="Send message"
                className="rounded-full transition-[scale,opacity,background-color] duration-150 ease-out active:scale-[0.96] disabled:opacity-40"
                disabled={!message.trim()}
                size="icon-lg"
                type="submit"
              >
                <SendIcon className="size-4.5" strokeWidth={1.5} />
              </Button>
            </div>
          </div>
        </div>
      </form>
    </div>
  );
}

Use it

Import it where you need it and update the import path to match your project.

Usage
import AiChat01 from '@/components/blocks/ai-chat-01';

export default function Page() {
  return <AiChat01 />;
}

Overview

Assistant composer with voice dictation is a free ai chat block for shadcn/ui and Base UI. It is built from the Button, Dropdown Menu and Textarea components with lucide-react, and installs as a single file you own and can edit.

It only uses semantic tokens such as bg-background, text-muted-foreground and border-border, so it follows your theme, radius and fonts and switches with dark mode. It is responsive from desktop to mobile; the width controls above the preview show each size. The same layout is in the shadcn/ui Pro Figma kit, so design and code start from one source.

Category
AI Chat
Component library
Base UI (@base-ui/react)
Also available for
Radix UI, React Aria
npm packages
lucide-react
Files
components/blocks/ai-chat-01.tsx
Access
Free, installs without a license key

Frequently asked questions

Pricing, installation and Base UI details for Assistant composer with voice dictation.