Mark Yo

Message Actions

AI chats

About

An action row below an AI assistant chat message with copy-to-clipboard, regenerate, thumbs up/down feedback (with a reason popover), share and a more-actions dropdown menu.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Message Actions to your project and fits it to your theme.

Code

How Message Actions is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

import { MessageActions } from "@/components/ui/message-actions";
import { Bookmark, Flag, GitBranch, Sparkles } from "lucide-react";
import { AnimatePresence, motion } from "motion/react";
import { useEffect, useRef, useState } from "react";

const FIRST =
  "Use a debounce of about 250ms on the search field so typing stays responsive while the request count drops.";
const LAST =
  "Yes — cancel the in-flight request with an AbortController whenever a newer query starts, so stale results never overwrite fresh ones.";

const MORE = [
  { value: "branch", label: "Branch from here", icon: <GitBranch /> },
  { value: "save", label: "Save to notes", icon: <Bookmark /> },
  { value: "report", label: "Report", icon: <Flag />, destructive: true },
];

export default function MessageActionsDemo() {
  const [notice, setNotice] = useState<string>();
  const timer = useRef<number | undefined>(undefined);

  useEffect(() => () => window.clearTimeout(timer.current), []);

  const flash = (text: string) => {
    setNotice(text);
    window.clearTimeout(timer.current);
    timer.current = window.setTimeout(() => setNotice(undefined), 1800);
  };

  const regenerate = () =>
    new Promise<void>((resolve) => {
      window.setTimeout(() => {
        flash("Regenerated a new version.");
        resolve();
      }, 1200);
    });

  const assistant = (text: string, last: boolean) => (
    <div className="group/message flex items-start gap-3">
      <span className="mt-0.5 grid size-7 shrink-0 place-items-center rounded-full bg-muted text-muted-foreground">
        <Sparkles className="size-3.5" />
      </span>
      <div className="flex flex-1 flex-col gap-1">
        <p className="text-sm leading-relaxed text-foreground">{text}</p>
        <MessageActions
          visibility={last ? "always" : "hover"}
          copyText={text}
          onRegenerate={regenerate}
          onShare={() => flash("Share link copied.")}
          onFeedbackSubmit={() => flash("Feedback sent.")}
          moreActions={MORE}
          onMoreAction={(value) =>
            flash(`${MORE.find((item) => item.value === value)?.label}.`)
          }
          className="-ml-1.5"
        />
      </div>
    </div>
  );

  const user = (text: string) => (
    <div className="flex justify-end">
      <div className="max-w-[80%] rounded-2xl bg-muted px-3.5 py-2 text-sm text-foreground">
        {text}
      </div>
    </div>
  );

  return (
    <div className="flex h-[440px] w-full max-w-xl flex-col justify-center gap-4">
      {user("How do I stop my search box from spamming the API?")}
      {assistant(FIRST, false)}
      {user("And if an older response arrives late?")}
      {assistant(LAST, true)}
      <div className="h-6 pt-2 text-center text-xs text-muted-foreground">
        <AnimatePresence mode="wait">
          {notice ? (
            <motion.p
              key={notice}
              initial={{ opacity: 0 }}
              animate={{ opacity: 1 }}
              exit={{ opacity: 0 }}
              transition={{ duration: 0.15 }}
            >
              {notice}
            </motion.p>
          ) : (
            <motion.p
              key="hint"
              initial={{ opacity: 0 }}
              animate={{ opacity: 0.7 }}
              exit={{ opacity: 0 }}
              transition={{ duration: 0.15 }}
            >
              Hover the first answer to reveal its actions.
            </motion.p>
          )}
        </AnimatePresence>
      </div>
    </div>
  );
}

Dependencies

More by Mark Yo

View all
  • Loader

    Loader

    72
  • Pricing Table

    Pricing Table

    29
  • Bento Grid

    Bento Grid

    18
  • Expandable Tabs

    Expandable Tabs

    18
  • Wallet Card

    Wallet Card

    15
  • Image Gallery

    Image Gallery

    11
  • CTA Section

    CTA Section

    10
  • Approval Queue

    Approval Queue

    9

More in AI chats

View all
  • AI Actions

    AI Actions

    369
  • Message Parts

    Message Parts

    4
  • Aquarium Prompt

    Aquarium Prompt

    195
  • Agent Chat

    Agent Chat

    21
  • AI Suggestions

    AI Suggestions

    24
  • Research Report

    Research Report

    8
  • Commit

    Commit

    45
  • Interactive LLM Token & Context Window Visualizer

    Interactive LLM Token & Context Window Visualizer

    20