Components / AI Chat Interfaces

AI Response Actions

An action bar for AI responses with copy, regenerate, thumbs up/down, and share buttons with tooltip labels.

Live Preview — ai-response-actions-01
C
This is a sample AI response with interactive actions.

Installation

Dependencies

Install the core libraries required for this component.

npm
npm install react lucide-react

Shadcn UI Setup

Add the necessary Shadcn UI primitives.

npm
npx shadcn-ui@latest add card avatar button tooltip

Source Code

ai-response-actions-01.tsx
import { useState } from "react";
import { Card, CardContent } from "@/components/ui/card";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button";
import { Tooltip, TooltipTrigger, TooltipContent } from "@/components/ui/tooltip";
import { Copy, RefreshCcw, ThumbsUp, ThumbsDown, Share2 } from "lucide-react";

interface AIResponseWithActionsProps {
    author?: string;
    avatar?: string;
    text?: string;
}

export default function AIResponseWithActions({
    author = "ChatGPT",
    avatar = "https://i.pravatar.cc/40?img=12",
    text = "This is a sample AI response with interactive actions.",
}: AIResponseWithActionsProps) {
    const [copied, setCopied] = useState(false);
    const [liked, setLiked] = useState(false);
    const [disliked, setDisliked] = useState(false);

    const handleCopy = () => {
        navigator.clipboard.writeText(text);
        setCopied(true);
        setTimeout(() => setCopied(false), 1500);
    };

    const handleLike = () => {
        setLiked((prev) => !prev);
        if (disliked) setDisliked(false);
    };

    const handleDislike = () => {
        setDisliked((prev) => !prev);
        if (liked) setLiked(false);
    };

    const handleRegenerate = () => {
        console.log("Regenerate response clicked");
    };

    const handleShare = () => {
        console.log("Share response clicked");
    };

    return (
        <Card className="border-0 w-full">
            <CardContent className="flex flex-col gap-2 p-3">
                {/* Message Bubble */}
                <div className="flex items-start gap-3">
                    <Avatar>
                        <AvatarImage src={avatar} />
                        <AvatarFallback>{author[0]}</AvatarFallback>
                    </Avatar>
                    <div className="bg-gray-100 text-gray-900 p-3 rounded-lg flex-1">
                        {text}
                    </div>
                </div>

                {/* Action Bar */}
                <div className="flex items-center gap-2 mt-1">
                    {/* Copy */}
                    <Tooltip>
                        <TooltipTrigger asChild>
                            <Button size="sm" variant="outline" onClick={handleCopy}>
                                <Copy className="w-4 h-4" />
                            </Button>
                        </TooltipTrigger>
                        <TooltipContent>{copied ? "Copied!" : "Copy"}</TooltipContent>
                    </Tooltip>

                    {/* Regenerate */}
                    <Tooltip>
                        <TooltipTrigger asChild>
                            <Button size="sm" variant="outline" onClick={handleRegenerate}>
                                <RefreshCcw className="w-4 h-4" />
                            </Button>
                        </TooltipTrigger>
                        <TooltipContent>Regenerate</TooltipContent>
                    </Tooltip>

                    {/* Thumbs Up */}
                    <Tooltip>
                        <TooltipTrigger asChild>
                            <Button
                                size="sm"
                                variant={liked ? "default" : "outline"}
                                onClick={handleLike}
                            >
                                <ThumbsUp className="w-4 h-4" />
                            </Button>
                        </TooltipTrigger>
                        <TooltipContent>{liked ? "Liked" : "Like"}</TooltipContent>
                    </Tooltip>

                    {/* Thumbs Down */}
                    <Tooltip>
                        <TooltipTrigger asChild>
                            <Button
                                size="sm"
                                variant={disliked ? "destructive" : "outline"}
                                onClick={handleDislike}
                            >
                                <ThumbsDown className="w-4 h-4" />
                            </Button>
                        </TooltipTrigger>
                        <TooltipContent>{disliked ? "Disliked" : "Dislike"}</TooltipContent>
                    </Tooltip>

                    {/* Share */}
                    <Tooltip>
                        <TooltipTrigger asChild>
                            <Button size="sm" variant="outline" onClick={handleShare}>
                                <Share2 className="w-4 h-4" />
                            </Button>
                        </TooltipTrigger>
                        <TooltipContent>Share</TooltipContent>
                    </Tooltip>
                </div>
            </CardContent>
        </Card>
    );
}

Shadcn Components

Primitives required in your @/components/ui directory.

Component Path
card @/components/ui/card
avatar @/components/ui/avatar
button @/components/ui/button
tooltip @/components/ui/tooltip

Type Reference

Types and interfaces defined in this component.

AIResponseWithActionsProps
interface AIResponseWithActionsProps {
    author?: string;
    avatar?: string;
    text?: string;
}

Functional Logic

Internal functions used to handle component logic.

Function Parameters
handleCopy() None
handleLike() None
handleDislike() None
handleRegenerate() None
handleShare() None
AIResponseWithActions() { author = "ChatGPT", avatar = "https://i.pravatar.cc/40?img=12", text = "This is a sample AI response with interactive actions.", }: AIResponseWithActionsProps

State Management

React state variables managed within this component.

Variable Initial Value
copied false
liked false
disliked false

JSX Tags Usage

Every JSX/HTML tag used in this component, with usage count and source.

Tag Count Type Source
<Avatar> Library @/components/ui/avatar
<AvatarFallback> Library @/components/ui/avatar
<AvatarImage> Library @/components/ui/avatar
<Card> Library @/components/ui/card
<CardContent> Library @/components/ui/card
<Copy> Library lucide-react
<RefreshCcw> Library lucide-react
<Share2> Library lucide-react
<ThumbsDown> Library lucide-react
<ThumbsUp> Library lucide-react
<Tooltip> Library @/components/ui/tooltip
<TooltipContent> Library @/components/ui/tooltip
<TooltipTrigger> Library @/components/ui/tooltip
<Button> Native Native HTML
<div> Native Native HTML

Related Components

  • AI Chat Bubble — A conversational chat bubble component with typing indicator, avatar support, and message timestamps for AI chat interfaces.
  • AI Chat Input Bar — A modern chat input bar with send button, attachment support, and auto-resize textarea for AI conversation interfaces.
  • AI Chat Window — A full-featured AI chat window with message history, streaming response animation, and conversation management.
  • AI Streaming Text — A typewriter-style streaming text component that simulates token-by-token AI response generation with cursor animation.
  • AI Chat Sidebar — A conversation history sidebar listing previous AI chat sessions with search, date grouping, and active state indicators.
  • AI Model Selector — A dropdown model selector for choosing between AI models (GPT-4, Claude, Gemini) with model info badges and capability indicators.