copy button

This commit is contained in:
Виталий Лавшонок
2025-11-03 16:08:50 +03:00
parent db8828e32b
commit 8429bd4082
3 changed files with 57 additions and 5 deletions

View File

@@ -0,0 +1,4 @@
<svg width="800" height="800" viewBox="0 0 800 800" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M565.632 471.936C565.632 523.683 523.683 565.632 471.936 565.632H237.696C185.949 565.632 144 523.683 144 471.936V237.696C144 185.949 185.949 144 237.696 144H471.936C523.683 144 565.632 185.949 565.632 237.696V471.936Z" stroke="white" stroke-width="48" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M328.064 656H562.304C614.051 656 656 614.048 656 562.304V328.062" stroke="white" stroke-width="48" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 614 B

View File

@@ -1,4 +1,6 @@
import IconSuccess from "./icon-success.svg"
import IconError from "./icon-error.svg"
import CopyIcon from "./copy-icon.svg"
export {IconError, IconSuccess}
export {IconError, IconSuccess, CopyIcon}

View File

@@ -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>