The Pages list and the page editor show a copy button next to the page address. It copies the full URL (this site's origin plus the path) and reuses the existing copy labels, so no new labels or SQL are needed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import { Check, Copy } from "lucide-react";
|
|
import { Button } from "@/app/components/ui/button";
|
|
import { useT } from "@/app/lib/i18n/MessagesProvider";
|
|
|
|
/** A page address with a button that copies its full URL (this site's origin plus the path). */
|
|
export function CopyAddress({ address }: { address: string }) {
|
|
const t = useT();
|
|
const [state, setState] = useState<"idle" | "copied" | "failed">("idle");
|
|
|
|
async function copy() {
|
|
try {
|
|
await navigator.clipboard.writeText(`${window.location.origin}${address}`);
|
|
setState("copied");
|
|
setTimeout(() => setState("idle"), 2000);
|
|
} catch {
|
|
setState("failed");
|
|
}
|
|
}
|
|
|
|
return (
|
|
<span className="inline-flex items-center gap-1">
|
|
<span className="font-mono text-xs">{address}</span>
|
|
<Button type="button" variant="ghost" size="icon" className="size-7" aria-label={`${t("QrCopy")} ${address}`} title={t("QrCopy")} onClick={copy}>
|
|
{state === "copied" ? <Check className="size-3.5" aria-hidden /> : <Copy className="size-3.5" aria-hidden />}
|
|
</Button>
|
|
{state !== "idle" ? (
|
|
<span role="status" className={state === "failed" ? "text-xs text-destructive" : "text-xs text-muted-foreground"}>
|
|
{t(state === "copied" ? "QrCopied" : "CopyFailed")}
|
|
</span>
|
|
) : null}
|
|
</span>
|
|
);
|
|
}
|