Spaces:
Configuration error
Configuration error
File size: 1,051 Bytes
7bbd534 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import ReactMarkdown from 'react-markdown';
import { FC, useEffect, useState } from 'react';
interface Props {
code: string;
editable?: boolean;
onChange?: (value: string) => void;
}
export const MarkdownBlock: FC<Props> = ({
code,
editable = false,
onChange = () => {},
}) => {
const [copyText, setCopyText] = useState<string>('Copy');
useEffect(() => {
const timeout = setTimeout(() => {
setCopyText('Copy');
}, 2000);
return () => clearTimeout(timeout);
}, [copyText]);
return (
<div className="relative">
<button
className="absolute right-0 top-0 z-10 rounded bg-[#1A1B26] p-1 text-xs text-white hover:bg-[#2D2E3A] active:bg-[#2D2E3A]"
onClick={() => {
navigator.clipboard.writeText(code);
setCopyText('Copied!');
}}
>
{copyText}
</button>
<div className="p-4 h-500px bg-[#1A1B26] text-white overflow-scroll rounded-md">
<ReactMarkdown className="font-normal">{code}</ReactMarkdown>
</div>
</div>
);
};
|