({
code,
editable = false,
onChange = () => {},
})
| 11 | } |
| 12 | |
| 13 | export const CodeBlock: FC<Props> = ({ |
| 14 | code, |
| 15 | editable = false, |
| 16 | onChange = () => {}, |
| 17 | }) => { |
| 18 | const [copyText, setCopyText] = useState<string>('Copy'); |
| 19 | |
| 20 | useEffect(() => { |
| 21 | const timeout = setTimeout(() => { |
| 22 | setCopyText('Copy'); |
| 23 | }, 2000); |
| 24 | |
| 25 | return () => clearTimeout(timeout); |
| 26 | }, [copyText]); |
| 27 | |
| 28 | return ( |
| 29 | <div className="relative"> |
| 30 | <button |
| 31 | className="absolute right-0 top-0 z-10 rounded bg-[#1A1B26] p-1 text-xs text-white hover:bg-[#2D2E3A] active:bg-[#2D2E3A]" |
| 32 | onClick={() => { |
| 33 | navigator.clipboard.writeText(code); |
| 34 | setCopyText('Copied!'); |
| 35 | }} |
| 36 | > |
| 37 | {copyText} |
| 38 | </button> |
| 39 | |
| 40 | <CodeMirror |
| 41 | editable={editable} |
| 42 | value={code} |
| 43 | minHeight="500px" |
| 44 | extensions={[StreamLanguage.define(go)]} |
| 45 | theme={tokyoNight} |
| 46 | onChange={(value) => onChange(value)} |
| 47 | /> |
| 48 | </div> |
| 49 | ); |
| 50 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected