mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-19 14:40:53 +08:00
Comments, doc comments, UI labels, log and error messages, LLM prompt strings, markdown docs, test data and assertions. Identifiers, enum keys, routes, placeholders and code structure are unchanged. Notes: - docs/漏洞流量证据.md renamed to docs/vulnerability-traffic-evidence.md - tests that exercised CJK specific handling (GBK zip names, Chinese full text search) now use ASCII equivalents; go build passes and the test suite matches the pre translation baseline (remaining failures need a PostgreSQL DSN and fail identically on the original) - frontend mention syntax now uses English kinds (finding, asset, ...) matching the backend, chat mentions tests pass
68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
"use client";
|
|
|
|
import * as React from "react";
|
|
|
|
import { CheckIcon, CopyIcon } from "lucide-react";
|
|
import { toast } from "sonner";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import { cn, copyText } from "@/lib/utils";
|
|
|
|
type CopyButtonProps = {
|
|
// text to copy; empty disables the button.
|
|
text: string | null | undefined;
|
|
// toast message shown after a successful copy, defaults to "Copied".
|
|
successMessage?: string;
|
|
label?: React.ReactNode;
|
|
size?: React.ComponentProps<typeof Button>["size"];
|
|
variant?: React.ComponentProps<typeof Button>["variant"];
|
|
className?: string;
|
|
};
|
|
|
|
// CopyButton is the shared "copy to clipboard" button: built-in success/failure feedback, and in non-secure HTTP
|
|
// contexts it degrades automatically (see copyText).
|
|
export function CopyButton({
|
|
text,
|
|
successMessage = "Copied",
|
|
label = "Copy",
|
|
size = "sm",
|
|
variant = "outline",
|
|
className,
|
|
}: CopyButtonProps) {
|
|
const [copied, setCopied] = React.useState(false);
|
|
const timer = React.useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
|
|
React.useEffect(() => {
|
|
return () => {
|
|
if (timer.current) clearTimeout(timer.current);
|
|
};
|
|
}, []);
|
|
|
|
async function handleCopy() {
|
|
if (!text) return;
|
|
const ok = await copyText(text);
|
|
if (ok) {
|
|
setCopied(true);
|
|
toast.success(successMessage);
|
|
if (timer.current) clearTimeout(timer.current);
|
|
timer.current = setTimeout(() => setCopied(false), 1500);
|
|
} else {
|
|
toast.error("Copy failed; select the text manually to copy");
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Button
|
|
type="button"
|
|
size={size}
|
|
variant={variant}
|
|
className={cn(className)}
|
|
disabled={!text}
|
|
onClick={handleCopy}
|
|
>
|
|
{copied ? <CheckIcon /> : <CopyIcon />}
|
|
{label}
|
|
</Button>
|
|
);
|
|
}
|