|
1 | 1 | import toast from 'react-hot-toast';
|
| 2 | +import { highlight, Grammar } from 'prismjs'; |
| 3 | +import Editor from 'react-simple-code-editor'; |
2 | 4 | import { DuplicateIcon } from '@heroicons/react/outline';
|
3 | 5 |
|
4 | 6 | type OutputProps = {
|
5 | 7 | output: string;
|
6 | 8 | isLoading: boolean;
|
| 9 | + languageGrammar: Grammar; |
7 | 10 | }
|
8 | 11 |
|
9 | 12 | function Output(props: OutputProps) {
|
10 |
| - const { output, isLoading } = props; |
| 13 | + const { output, isLoading, languageGrammar } = props; |
11 | 14 |
|
12 | 15 | const copyToClipboard = () => {
|
13 | 16 | navigator.clipboard.writeText(output);
|
14 | 17 | toast.success('Copied to clipboard');
|
15 | 18 | };
|
16 | 19 |
|
17 | 20 | return (
|
18 |
| - <div className="relative bg-gray-100 border-2 border-gray-200 rounded-lg text-gray-700 p-4 pb-10" style={{ minHeight: '12rem' }}> |
19 |
| - <p className="whitespace-pre-line text-sm">{output}</p> |
20 |
| - { |
21 |
| - output && ( |
| 21 | + <div className="relative"> |
| 22 | + <Editor |
| 23 | + value={output} |
| 24 | + onValueChange={() => {}} |
| 25 | + highlight={(codeToBeHighlighted) => highlight( |
| 26 | + codeToBeHighlighted, languageGrammar, 'TypeScript', |
| 27 | + )} |
| 28 | + padding={12} |
| 29 | + disabled |
| 30 | + textareaId="codeArea" |
| 31 | + className="bg-gray-100 output border-2 border-gray-200 rounded-lg p-4 pb-10 text-sm" |
| 32 | + style={{ |
| 33 | + boxSizing: 'border-box', |
| 34 | + fontFamily: '"Dank Mono", "Fira Code", monospace', |
| 35 | + minHeight: '12rem', |
| 36 | + color: '#0D935B !important', |
| 37 | + }} |
| 38 | + /> |
| 39 | + {output && ( |
22 | 40 | <button className="absolute right-3 bottom-3" type="button" onClick={copyToClipboard}>
|
23 | 41 | <DuplicateIcon className="h-6 w-6 text-gray-600 hover:text-gray-400" />
|
24 | 42 | </button>
|
25 |
| - ) |
26 |
| - } |
| 43 | + )} |
27 | 44 | {isLoading && (
|
28 |
| - <div className="absolute inset-0 flex items-center justify-center"> |
29 |
| - <svg className="animate-spin -ml-1 mr-3 h-5 w-5 text-gray-800" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"> |
30 |
| - <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" /> |
31 |
| - <path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" /> |
32 |
| - </svg> |
33 |
| - </div> |
| 45 | + <div className="absolute inset-0 flex items-center justify-center"> |
| 46 | + <svg className="animate-spin -ml-1 mr-3 h-5 w-5 text-gray-800" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"> |
| 47 | + <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" /> |
| 48 | + <path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" /> |
| 49 | + </svg> |
| 50 | + </div> |
34 | 51 | )}
|
35 | 52 | </div>
|
36 | 53 | );
|
|
0 commit comments