caelum0x d56639a594
Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

96 lines
2.5 KiB
TypeScript

"use client";
import * as React from "react";
import { Check, Copy } from "lucide-react";
import { Button, type ButtonProps } from "@/components/ui/button";
export interface CopyButtonProps {
/** Text written to the clipboard when pressed. */
value: string;
/** Accessible label describing what is copied (e.g. "Copy caption"). */
label: string;
className?: string;
variant?: ButtonProps["variant"];
size?: ButtonProps["size"];
/** Optional visible content shown next to the icon (e.g. a chip's text). */
children?: React.ReactNode;
}
/**
* Small copy-to-clipboard button with transient "copied" / "failed" feedback.
* Reused for the title, caption, each hashtag chip, and the "copy all" action.
* The clipboard write is guarded — an unavailable/denied Clipboard API surfaces a
* brief hint instead of throwing.
*/
export function CopyButton({
value,
label,
className,
variant = "outline",
size = "sm",
children,
}: Readonly<CopyButtonProps>) {
const [state, setState] = React.useState<"idle" | "copied" | "failed">("idle");
const timerRef = React.useRef<ReturnType<typeof setTimeout> | undefined>(
undefined,
);
React.useEffect(
() => () => {
if (timerRef.current) clearTimeout(timerRef.current);
},
[],
);
const flash = React.useCallback((next: "copied" | "failed") => {
setState(next);
if (timerRef.current) clearTimeout(timerRef.current);
timerRef.current = setTimeout(
() => setState("idle"),
next === "copied" ? 1500 : 2500,
);
}, []);
const handleCopy = React.useCallback(async () => {
try {
if (!navigator.clipboard?.writeText) {
throw new Error("Clipboard API unavailable");
}
await navigator.clipboard.writeText(value);
flash("copied");
} catch {
flash("failed");
}
}, [value, flash]);
const title =
state === "failed" ? "Couldn't copy — select and copy manually." : label;
return (
<Button
type="button"
variant={variant}
size={size}
className={className}
disabled={value.length === 0}
aria-label={label}
title={title}
onClick={() => void handleCopy()}
>
{state === "copied" ? (
<Check className="size-4" aria-hidden />
) : (
<Copy className="size-4" aria-hidden />
)}
{children}
<span className="sr-only" aria-live="polite">
{state === "copied"
? "Copied to clipboard"
: state === "failed"
? "Copy failed"
: ""}
</span>
</Button>
);
}