copy button
This commit is contained in:
@@ -1,8 +1,54 @@
|
||||
import React from "react";
|
||||
// import { cn } from "../../../lib/cn";
|
||||
import React, { FC } from "react";
|
||||
import { cn } from "../../../lib/cn";
|
||||
import LaTextContainer from "./LaTextContainer";
|
||||
import { CopyIcon } from "../../../assets/icons/missions";
|
||||
// import FullLatexRenderer from "./FullLatexRenderer";
|
||||
|
||||
|
||||
|
||||
import { useState } from "react";
|
||||
|
||||
interface CopyableDivPropd{
|
||||
content: string;
|
||||
}
|
||||
|
||||
const CopyableDiv: FC<CopyableDivPropd> = ({ content }) => {
|
||||
const [hovered, setHovered] = useState(false);
|
||||
|
||||
const handleCopy = async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(content);
|
||||
alert("Скопировано!");
|
||||
} catch (err) {
|
||||
console.error("Ошибка копирования:", err);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className="relative p-[10px] bg-liquid-lighter rounded-[10px] whitespace-pre-line"
|
||||
onMouseEnter={() => setHovered(true)}
|
||||
onMouseLeave={() => setHovered(false)}
|
||||
>
|
||||
{content}
|
||||
|
||||
|
||||
<img
|
||||
src={CopyIcon}
|
||||
alt="copy"
|
||||
className={cn("absolute top-2 right-2 w-6 h-6 cursor-pointer opacity-0 transition-all duration-300 hover:h-7 hover:w-7 hover:top-[6px] hover:right-[6px]",
|
||||
hovered && " opacity-100"
|
||||
)}
|
||||
onClick={handleCopy}
|
||||
/>
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
export interface StatementData {
|
||||
id?: number;
|
||||
name?: string;
|
||||
@@ -75,9 +121,9 @@ const Statement: React.FC<StatementData> = ({
|
||||
{sampleTests.map((v, i) =>
|
||||
<div key={i} className="flex flex-col gap-[10px]">
|
||||
<div className="text-[14px] font-bold">Входные данные</div>
|
||||
<div className="p-[10px] bg-liquid-lighter rounded-[10px] whitespace-pre-line">{v.input}</div>
|
||||
<CopyableDiv content={v.input}/>
|
||||
<div className="text-[14px] font-bold">Выходные данные</div>
|
||||
<div className="p-[10px] bg-liquid-lighter rounded-[10px] whitespace-pre-line">{v.output}</div>
|
||||
<CopyableDiv content={v.output}/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user