Message Actions
SaveThe action row under an AI reply: copy with a drawn check, thumbs up and down with a reason picker for thumbs down, regenerate, edit, branch, read aloud, and a version pager.
- Category
- AI elements
- Version
- 0.1.1
- Frameworks
- Next.js, Vite + React
- Styling
- Tailwind CSS v4
Preview
Message Actions preview
Installation
npx @shakenui/cli add message-actionsReview the plan first. A dry run lists every file and package without changing anything:
npx @shakenui/cli add message-actions --dry-runUsage
message-actions-example.tsx
"use client";
import { useState } from "react";
import { MessageActions, type MessageFeedback } from "@/components/shaken/agent/message-actions";
const replies = [
"The invoice is off by a cent because proration rounds each line before adding them up. Two half cents both round down, so the total shows $12.33 instead of $12.34. Rounding once, after the sum, fixes it.",
"Proration rounds every line item on its own, then adds the rounded amounts. With two lines ending in half a cent, both round down and the invoice loses a cent. Sum first and round the total once.",
];
export default function MessageActionsExample() {
const [version, setVersion] = useState(2);
const [feedback, setFeedback] = useState<MessageFeedback>(null);
const text = replies[version - 1]!;
return (
<div className="group/message w-full max-w-xl">
<p className="text-sm leading-relaxed text-zinc-800 dark:text-zinc-200">{text}</p>
<MessageActions
className="mt-1.5 -ml-1.5"
visibility="always"
text={text}
feedback={feedback}
onFeedback={(next) => setFeedback(next)}
versions={{ current: version, total: replies.length, onChange: setVersion }}
onRetry={() => {}}
onEdit={() => {}}
onBranch={() => {}}
readAloud
/>
</div>
);
}States
Every state, rendered from local fixture data.
Message Actions states
No feedback yet
Marked good
Marked bad
With a custom action
API
| Prop | Type | Default | Description |
|---|---|---|---|
| text | string | — | Text for Copy and Read aloud. Without it there is no Copy action. |
| onCopy | (text) => void | — | Called after copying. |
| onRetry / onEdit / onBranch | () => void | — | Each one shows its action: Regenerate, Edit, Branch in new chat. |
| readAloud | boolean | false | Shows Read aloud using the browser's speech synthesis on text. |
| onReadAloud / speaking | () => void / boolean | — | Handle read aloud yourself and pass the speaking state. |
| feedback / defaultFeedback | "up" | "down" | null | — | Controlled or initial feedback. |
| onFeedback | (feedback, details?: { reasons, comment }) => void | — | Called when a thumb is pressed or cleared, and again with details when the thumbs down form is sent. |
| reasons | string[] | — | Choices in the thumbs down form. |
| versions | { current, total, onChange } | — | Shows a pager for regenerated replies. |
| visibility | "hover" | "always" | "hover" | hover shows the row while an ancestor with group/message is hovered or focused, and always on touch screens. |
| children | ReactNode | — | Extra actions; use MessageAction for matching icon buttons. |
Accessibility
- The row is role="toolbar" labeled Message actions; Left, Right, Home, and End move between actions, and Tab reaches each one.
- Every action is an icon button with an aria-label and a tooltip on hover and focus. Thumbs and Read aloud are toggles with aria-pressed.
- Thumbs down opens a Base UI Popover form (focus moves in, Escape closes) with reason toggles, an optional labeled textarea, Skip, and Send feedback. Pressing thumbs down again clears it.
- Copied, feedback sent, and feedback removed are announced in a polite live region.
- In hover mode the row also appears whenever focus is inside the message, while feedback is set, and on devices without hover.
- With reduced motion the copy check, thumb fill, and chip entrances are instant, and the thumb tip, ring, and regenerate turn do not play.
Files
Installed into src/components/shaken, or components/shaken when the project has no src directory.
src/components/shaken/agent/message-actions.tsxmessage-actions- Also installs popover@0.2.2registry dependency
- Also installs tooltip@0.1.1registry dependency
- npm packages: @base-ui/react@^1.9.0, motion@^14.14.0React and Tailwind CSS v4 required
Source
The exact source the CLI installs, from /r/items/react/message-actions/0.1.1.json.
agent/message-actions.tsxShowHide
agent/message-actions.tsx
"use client";
import { useAnimate, useReducedMotion } from "motion/react";
import { type ComponentProps, type ReactNode, useEffect, useId, useRef, useState } from "react";
import { Popover, PopoverContent, PopoverTitle, PopoverTrigger } from "../ui/popover";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../ui/tooltip";
function cx(...classes: (string | false | null | undefined)[]) {
return classes.filter(Boolean).join(" ");
}
const ease = "ease-[cubic-bezier(0.23,1,0.32,1)]";
const quint = [0.23, 1, 0.32, 1] as const;
/*
* Message actions: the row under an AI reply.
*
* Copy swaps to a check that draws itself. A thumb tips in its direction and settles while it
* fills, with one faint ring spreading from it; thumbs down then opens a small reason picker.
* Regenerate turns its arrow once. Under reduced motion the swaps and fills are instant and
* nothing tips, spins, or spreads.
*/
export type MessageFeedback = "up" | "down" | null;
export interface FeedbackDetails {
/** The reasons picked in the thumbs down form. */
reasons: string[];
/** Free text from the form, trimmed. */
comment: string;
}
export interface MessageVersions {
/** 1 based index of the version shown. */
current: number;
total: number;
/** Called with the 1 based version to show. */
onChange: (version: number) => void;
}
export interface MessageActionsProps extends Omit<ComponentProps<"div">, "children" | "onCopy"> {
/** Text for Copy and Read aloud. Without it there is no Copy action. */
text?: string;
onCopy?: (text: string) => void;
/** Shows Regenerate. */
onRetry?: () => void;
/** Shows Edit. */
onEdit?: () => void;
/** Shows Branch, which starts a new chat from this message. */
onBranch?: () => void;
/** Shows Read aloud using the browser's speech synthesis on `text`. */
readAloud?: boolean;
/** Handles Read aloud yourself, for example with your own text to speech. Pair with `speaking`. */
onReadAloud?: () => void;
/** Controlled speaking state for `onReadAloud`. */
speaking?: boolean;
/** Controlled feedback. */
feedback?: MessageFeedback;
defaultFeedback?: MessageFeedback;
/**
* Called when a thumb is pressed or cleared, and again with details when the thumbs down form
* is sent. Shows the thumbs.
*/
onFeedback?: (feedback: MessageFeedback, details?: FeedbackDetails) => void;
/** Choices in the thumbs down form. */
reasons?: string[];
/** Shows a version pager, for replies that were regenerated. */
versions?: MessageVersions;
/**
* `hover` shows the row while the message (an ancestor with `group/message`) is hovered or holds
* focus, and always on touch screens. `always` keeps it visible.
*/
visibility?: "hover" | "always";
/** Extra actions after the built in ones. Use `MessageAction`. */
children?: ReactNode;
}
const defaultReasons = ["Not accurate", "Didn't follow instructions", "Too long", "Out of date", "Unsafe or harmful"];
/** The action row under an assistant reply: copy, feedback, regenerate, edit, branch, read aloud, and a version pager. */
export function MessageActions({
text,
onCopy,
onRetry,
onEdit,
onBranch,
readAloud = false,
onReadAloud,
speaking: speakingProp,
feedback: feedbackProp,
defaultFeedback = null,
onFeedback,
reasons = defaultReasons,
versions,
visibility = "hover",
className,
children,
...props
}: MessageActionsProps) {
const [localFeedback, setLocalFeedback] = useState<MessageFeedback>(defaultFeedback);
const feedback = feedbackProp !== undefined ? feedbackProp : localFeedback;
const [formOpen, setFormOpen] = useState(false);
const [announcement, setAnnouncement] = useState("");
const [thanks, setThanks] = useState(false);
const thanksTimer = useRef<ReturnType<typeof setTimeout>>(undefined);
const speech = useSpeech(text);
const speaking = speakingProp ?? speech.speaking;
const showFeedback = onFeedback !== undefined || feedbackProp !== undefined;
useEffect(() => () => clearTimeout(thanksTimer.current), []);
function setFeedback(next: MessageFeedback, details?: FeedbackDetails) {
if (feedbackProp === undefined) setLocalFeedback(next);
onFeedback?.(next, details);
}
function sayThanks() {
setThanks(true);
setAnnouncement("Thanks for the feedback");
clearTimeout(thanksTimer.current);
thanksTimer.current = setTimeout(() => setThanks(false), 2400);
}
function pressUp() {
const next = feedback === "up" ? null : "up";
setFeedback(next);
if (next) sayThanks();
else setAnnouncement("Feedback removed");
}
const active = feedback !== null || formOpen || speaking || thanks;
return (
<div
role="toolbar"
aria-label="Message actions"
data-active={active || undefined}
onKeyDown={(event) => {
// Toolbar pattern: arrows, Home, and End move between the actions.
const keys = ["ArrowLeft", "ArrowRight", "Home", "End"];
if (!keys.includes(event.key)) return;
const buttons = [...event.currentTarget.querySelectorAll<HTMLButtonElement>("button:not(:disabled)")];
const at = buttons.indexOf(document.activeElement as HTMLButtonElement);
if (at < 0) return;
event.preventDefault();
const next = event.key === "Home" ? 0 : event.key === "End" ? buttons.length - 1 : (at + (event.key === "ArrowRight" ? 1 : -1) + buttons.length) % buttons.length;
buttons[next]?.focus();
}}
className={cx(
"flex min-h-8 flex-wrap items-center gap-0.5 text-zinc-500",
visibility === "hover" &&
cx(
"opacity-0 transition-opacity duration-150 ease-out motion-reduce:transition-none",
"group-hover/message:opacity-100 group-focus-within/message:opacity-100 focus-within:opacity-100 data-active:opacity-100 [@media(hover:none)]:opacity-100",
),
className,
)}
{...props}
>
<TooltipProvider>
{versions ? <VersionPager {...versions} /> : null}
{text ? <CopyButton text={text} onCopy={onCopy} onAnnounce={setAnnouncement} /> : null}
{showFeedback ? (
<>
<ThumbButton direction="up" pressed={feedback === "up"} onClick={pressUp} />
<Popover
open={formOpen}
onOpenChange={(open, details) => {
if (open && details.reason === "trigger-press" && feedback === "down") {
// A second press clears the thumbs down instead of reopening the form.
setFeedback(null);
setAnnouncement("Feedback removed");
return;
}
if (open && feedback !== "down") setFeedback("down");
setFormOpen(open);
}}
>
<ThumbButton direction="down" pressed={feedback === "down"} popover />
<PopoverContent side="bottom" align="start" className="w-[min(20rem,calc(100vw-2rem))] p-0">
<ReasonForm
reasons={reasons}
onCancel={() => setFormOpen(false)}
onSubmit={(details) => {
setFeedback("down", details);
setFormOpen(false);
sayThanks();
}}
/>
</PopoverContent>
</Popover>
</>
) : null}
{readAloud || onReadAloud ? (
<IconButton
label={speaking ? "Stop reading" : "Read aloud"}
pressed={speaking}
onClick={() => (onReadAloud ? onReadAloud() : speech.toggle())}
disabled={!onReadAloud && !speech.supported}
>
{speaking ? (
<>
<path d="M2.75 6.25h2l3-2.5v8.5l-3-2.5h-2z" />
<rect x="10.25" y="5.75" width="4" height="4.5" rx="1" />
</>
) : (
<path d="M2.75 6.25h2l3-2.5v8.5l-3-2.5h-2zM10.5 6a2.75 2.75 0 0 1 0 4M12.25 4.25a5.25 5.25 0 0 1 0 7.5" />
)}
</IconButton>
) : null}
{onEdit ? (
<IconButton label="Edit" onClick={onEdit}>
<path d="M10.25 3.25 12.75 5.75M3.25 12.75l.6-2.75 7.4-7.4a1.4 1.4 0 0 1 2 2l-7.4 7.4z" />
</IconButton>
) : null}
{onBranch ? (
<IconButton label="Branch in new chat" onClick={onBranch}>
<circle cx="4.75" cy="3.75" r="1.5" />
<circle cx="4.75" cy="12.25" r="1.5" />
<circle cx="11.25" cy="5.75" r="1.5" />
<path d="M4.75 5.25v5.5M11.25 7.25c0 2.25-1.5 3-3.5 3.25-1.5.2-2.6.6-3 1.3" />
</IconButton>
) : null}
{onRetry ? <RetryButton onRetry={onRetry} /> : null}
{children}
</TooltipProvider>
{thanks ? (
<span
aria-hidden="true"
className={cx("ml-1.5 text-xs text-zinc-500 transition-[opacity,translate] duration-300 motion-reduce:transition-none", ease, "starting:-translate-x-1 starting:opacity-0")}
>
Thanks for the feedback
</span>
) : null}
<span className="sr-only" aria-live="polite">
{announcement}
</span>
</div>
);
}
// ---------------------------------------------------------------------------
// Buttons
const buttonClass = cx(
"relative inline-flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-lg text-zinc-500",
"transition-[background-color,color,scale] duration-150 ease-out active:duration-100 motion-safe:active:scale-[0.94] motion-reduce:transition-none",
"hover:bg-zinc-950/[0.04] hover:text-zinc-950 dark:hover:bg-white/[0.06] dark:hover:text-white",
"aria-pressed:text-zinc-950 dark:aria-pressed:text-white",
"focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-sky-500",
"disabled:pointer-events-none disabled:opacity-45",
);
export interface MessageActionProps extends Omit<ComponentProps<"button">, "children"> {
/** Accessible name and tooltip text. */
label: string;
/** For toggles. */
pressed?: boolean;
/** SVG content in a 16 unit box, drawn with a 1.5 stroke. */
children: ReactNode;
}
/** A 32px icon button with a tooltip, matching the built in actions. Pass extras as children of MessageActions. */
export function MessageAction({ label, pressed, children, className, ...props }: MessageActionProps) {
return <IconButton label={label} pressed={pressed} className={className} {...props}>{children}</IconButton>;
}
function IconButton({
label,
pressed,
children,
className,
...props
}: Omit<ComponentProps<"button">, "children"> & { label: string; pressed?: boolean; children: ReactNode }) {
return (
<Tooltip>
<TooltipTrigger
render={<button type="button" />}
aria-label={label}
aria-pressed={pressed}
className={cx(buttonClass, className)}
{...props}
>
<svg aria-hidden="true" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" className="size-4">
{children}
</svg>
</TooltipTrigger>
<TooltipContent side="top">{label}</TooltipContent>
</Tooltip>
);
}
function CopyButton({ text, onCopy, onAnnounce }: { text: string; onCopy?: (text: string) => void; onAnnounce: (message: string) => void }) {
const [copied, setCopied] = useState(false);
const timer = useRef<ReturnType<typeof setTimeout>>(undefined);
useEffect(() => () => clearTimeout(timer.current), []);
async function copy() {
try {
await navigator.clipboard.writeText(text);
setCopied(true);
onAnnounce("Copied");
onCopy?.(text);
clearTimeout(timer.current);
timer.current = setTimeout(() => setCopied(false), 1600);
} catch {
onAnnounce("Could not copy");
}
}
const swap = cx("origin-center transition-[opacity,scale,filter] duration-200 motion-reduce:transition-none", ease);
return (
<Tooltip>
<TooltipTrigger render={<button type="button" />} aria-label={copied ? "Copied" : "Copy"} onClick={copy} className={buttonClass}>
<svg aria-hidden="true" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" className="size-4 overflow-visible">
<g className={cx(swap, copied ? "scale-50 opacity-0 blur-[1px]" : "scale-100 opacity-100")}>
<rect x="5.25" y="5.25" width="8" height="8" rx="1.75" />
<path d="M10.75 5.25V3.5c0-.97-.78-1.75-1.75-1.75H3.5c-.97 0-1.75.78-1.75 1.75V9c0 .97.78 1.75 1.75 1.75h1.75" />
</g>
{/* The check draws itself: dashoffset runs from the full length to 0. */}
<path
d="m3.5 8.5 3 3 6-7"
pathLength={1}
className={cx(
"text-emerald-600 [stroke-dasharray:1] dark:text-emerald-400",
"transition-[stroke-dashoffset,opacity] motion-reduce:transition-none",
ease,
copied ? "opacity-100 [stroke-dashoffset:0] delay-75 duration-300" : "opacity-0 [stroke-dashoffset:1] duration-150",
)}
/>
</svg>
</TooltipTrigger>
<TooltipContent side="top">{copied ? "Copied" : "Copy"}</TooltipContent>
</Tooltip>
);
}
function ThumbButton({
direction,
pressed,
popover = false,
onClick,
}: {
direction: "up" | "down";
pressed: boolean;
popover?: boolean;
onClick?: () => void;
}) {
const [scope, animate] = useAnimate();
const reduce = useReducedMotion();
const was = useRef(pressed);
useEffect(() => {
if (pressed && !was.current && !reduce && scope.current) {
const tip = direction === "up" ? -18 : 18;
const lift = direction === "up" ? -2 : 2;
// Tip toward its direction, then settle; the ring spreads once.
void animate("[data-thumb]", { rotate: [0, tip, 0], y: [0, lift, 0], scale: [1, 1.12, 1] }, { duration: 0.42, ease: quint, times: [0, 0.35, 1] });
void animate("[data-ring]", { scale: [0.6, 1.5], opacity: [0.35, 0] }, { duration: 0.5, ease: quint });
}
was.current = pressed;
}, [pressed, reduce, direction, animate, scope]);
const label = direction === "up" ? "Good response" : "Bad response";
const path =
"M5.25 7.25 7.6 2.6a1.35 1.35 0 0 1 2.5.9l-.5 2.75h2.9a1.5 1.5 0 0 1 1.47 1.8l-.9 4.5a1.5 1.5 0 0 1-1.47 1.2H5.25zM5.25 7.25h-2a.5.5 0 0 0-.5.5v5.5a.5.5 0 0 0 .5.5h2";
const content = (
<span ref={scope} className="relative flex size-4 items-center justify-center">
<span data-ring aria-hidden="true" className="pointer-events-none absolute -inset-2 rounded-full border border-current opacity-0" />
<svg
data-thumb
aria-hidden="true"
viewBox="0 0 16 16"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
className="size-4 overflow-visible"
style={{ transformOrigin: "50% 55%" }}
>
{/* Thumbs down is the same glyph turned over, so both tip toward where they point. */}
<path
d={path}
transform={direction === "down" ? "rotate(180 8 8)" : undefined}
fill="currentColor"
style={{ fillOpacity: pressed ? 0.9 : 0 }}
className={cx("transition-[fill-opacity] duration-200 motion-reduce:transition-none", ease)}
/>
</svg>
</span>
);
const shared = { "aria-label": label, "aria-pressed": pressed, className: buttonClass };
return (
<Tooltip>
<TooltipTrigger
render={popover ? <PopoverTrigger render={<button type="button" />} /> : <button type="button" onClick={onClick} />}
{...shared}
>
{content}
</TooltipTrigger>
<TooltipContent side="top">{label}</TooltipContent>
</Tooltip>
);
}
function RetryButton({ onRetry }: { onRetry: () => void }) {
const [scope, animate] = useAnimate();
const reduce = useReducedMotion();
return (
<Tooltip>
<TooltipTrigger
render={<button type="button" />}
aria-label="Regenerate"
className={buttonClass}
onClick={() => {
if (!reduce && scope.current) void animate(scope.current, { rotate: [0, -360] }, { duration: 0.5, ease: quint });
onRetry();
}}
>
<svg ref={scope} aria-hidden="true" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" className="size-4">
<path d="M12.75 8a4.75 4.75 0 1 1-1.39-3.36M12.75 2.75v2.5h-2.5" />
</svg>
</TooltipTrigger>
<TooltipContent side="top">Regenerate</TooltipContent>
</Tooltip>
);
}
function VersionPager({ current, total, onChange }: MessageVersions) {
const arrow = cx(buttonClass, "size-7");
return (
<span className="mr-1 flex items-center border-r border-zinc-950/[0.07] pr-1 dark:border-white/[0.08]">
<button type="button" aria-label="Previous version" disabled={current <= 1} onClick={() => onChange(current - 1)} className={arrow}>
<svg aria-hidden="true" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" className="size-4">
<path d="M9.75 4.5 6.25 8l3.5 3.5" />
</svg>
</button>
<span className="min-w-8 text-center font-mono text-xs text-zinc-600 tabular-nums dark:text-zinc-400">
<span className="sr-only">Version </span>
{current}/{total}
</span>
<button type="button" aria-label="Next version" disabled={current >= total} onClick={() => onChange(current + 1)} className={arrow}>
<svg aria-hidden="true" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" className="size-4">
<path d="m6.25 4.5 3.5 3.5-3.5 3.5" />
</svg>
</button>
</span>
);
}
// ---------------------------------------------------------------------------
// Thumbs down form
function ReasonForm({ reasons, onSubmit, onCancel }: { reasons: string[]; onSubmit: (details: FeedbackDetails) => void; onCancel: () => void }) {
const [picked, setPicked] = useState<string[]>([]);
const [comment, setComment] = useState("");
const commentId = useId();
return (
<form
className="flex flex-col"
onSubmit={(event) => {
event.preventDefault();
onSubmit({ reasons: picked, comment: comment.trim() });
}}
>
<div className="px-4 pt-3.5 pb-3">
<PopoverTitle>What went wrong?</PopoverTitle>
<div role="group" aria-label="Reasons" className="mt-3 flex flex-wrap gap-1.5">
{reasons.map((reason, index) => {
const on = picked.includes(reason);
return (
<button
key={reason}
type="button"
aria-pressed={on}
onClick={() => setPicked((current) => (on ? current.filter((item) => item !== reason) : [...current, reason]))}
style={{ transitionDelay: `0ms, 0ms, 0ms, 0ms, ${index * 24}ms, ${index * 24}ms` }}
className={cx(
"inline-flex h-7 cursor-pointer items-center gap-1 rounded-md border px-2 text-xs font-medium select-none",
"transition-[background-color,border-color,color,scale,opacity,translate] duration-200 motion-reduce:transition-none",
ease,
"starting:translate-y-1 starting:opacity-0 motion-safe:active:scale-[0.97]",
"focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-sky-500",
on
? "border-zinc-950 bg-zinc-950 text-white dark:border-white dark:bg-white dark:text-black"
: "border-zinc-950/12 text-zinc-700 hover:border-zinc-950/25 hover:bg-zinc-950/[0.03] dark:border-white/15 dark:text-zinc-300 dark:hover:border-white/30 dark:hover:bg-white/[0.06]",
)}
>
{reason}
</button>
);
})}
</div>
<label htmlFor={commentId} className="mt-3 block text-xs font-medium text-zinc-500">
Details, optional
</label>
<textarea
id={commentId}
value={comment}
onChange={(event) => setComment(event.target.value)}
rows={2}
placeholder="What should the answer have said?"
className={cx(
"mt-1.5 block w-full resize-none rounded-lg border border-zinc-950/12 bg-white px-2.5 py-1.5 text-sm text-zinc-950 placeholder:text-zinc-500",
"transition-[border-color] duration-150 ease-out hover:border-zinc-950/20 motion-reduce:transition-none",
"dark:border-white/15 dark:bg-black dark:text-white dark:hover:border-white/25",
"focus-visible:border-sky-500/60 focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-0 focus-visible:outline-sky-500/40",
)}
/>
</div>
<div className="flex justify-end gap-1.5 border-t border-zinc-950/[0.07] px-3 py-2.5 dark:border-white/[0.08]">
<button
type="button"
onClick={onCancel}
className={cx(
"inline-flex h-8 cursor-pointer items-center rounded-lg px-3 text-sm font-medium text-zinc-600 select-none",
"transition-[background-color,color,scale] duration-150 ease-out motion-safe:active:scale-[0.97] motion-reduce:transition-none",
"hover:bg-zinc-950/[0.04] hover:text-zinc-950 dark:text-zinc-400 dark:hover:bg-white/[0.06] dark:hover:text-white",
"focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-sky-500",
)}
>
Skip
</button>
<button
type="submit"
className={cx(
"inline-flex h-8 cursor-pointer items-center rounded-lg px-3 text-sm font-medium select-none",
"bg-zinc-950 text-white shadow-[inset_0_1px_0_rgb(255_255_255/0.12),0_1px_2px_rgb(0_0_0/0.2)] hover:bg-zinc-800",
"dark:bg-white dark:text-black dark:shadow-[inset_0_-1px_0_rgb(0_0_0/0.12)] dark:hover:bg-zinc-200",
"transition-[background-color,scale] duration-150 ease-out motion-safe:active:scale-[0.97] motion-reduce:transition-none",
"focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-sky-500",
)}
>
Send feedback
</button>
</div>
</form>
);
}
// ---------------------------------------------------------------------------
// Speech
function useSpeech(text: string | undefined) {
const [speaking, setSpeaking] = useState(false);
const [supported, setSupported] = useState(false);
useEffect(() => {
setSupported(typeof window !== "undefined" && "speechSynthesis" in window);
return () => {
if (typeof window !== "undefined" && "speechSynthesis" in window) window.speechSynthesis.cancel();
};
}, []);
function toggle() {
if (!supported || !text) return;
const synth = window.speechSynthesis;
if (speaking) {
synth.cancel();
setSpeaking(false);
return;
}
synth.cancel();
const utterance = new SpeechSynthesisUtterance(text);
utterance.onend = () => setSpeaking(false);
utterance.onerror = () => setSpeaking(false);
synth.speak(utterance);
setSpeaking(true);
}
return { speaking, supported, toggle };
}