Skip to content

Commit

Permalink
Add copy event listener
Browse files Browse the repository at this point in the history
  • Loading branch information
shoonia committed Apr 29, 2024
1 parent 101a3ef commit 97126dc
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/components/Preview/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { JSX } from 'preact';
import { useRef } from 'preact/hooks';

import s from './styles.css';
Expand All @@ -8,6 +9,7 @@ import { JSON } from './JSON';
import { DownloadButton } from '../DownloadButton';
import { IconDuplicate } from '../Icons/IconDuplicate';
import { createConfig } from '../../util/items';
import { preventDefault } from '../../util/component';

const createData = (config: string): string => `// Jobs Config Generator
// https://wix.to/NDAQn6c
Expand All @@ -34,6 +36,11 @@ export const Preview: FC = () => {
}
};

const copy: JSX.ClipboardEventHandler<HTMLPreElement> = (event) => {
event.clipboardData?.setData('text/plain', data);
preventDefault(event);
};

return (
<div className={s.box}>
<ToolbarWrapper>
Expand All @@ -52,6 +59,7 @@ export const Preview: FC = () => {
</ToolbarWrapper>
<pre
ref={output}
onCopy={copy}
className={s.out}
>
<JSON input={config} />
Expand Down

0 comments on commit 97126dc

Please sign in to comment.