MonacoEditor.tsx 1.88 KB
Newer Older
v-liguo's avatar
v-liguo committed
1
import * as React from 'react';
2
import { Spinner } from '@fluentui/react';
v-liguo's avatar
v-liguo committed
3
4
5
6
7
import MonacoEditor from 'react-monaco-editor';

interface MonacoEditorProps {
    content: string;
    loading: boolean;
Lijiao's avatar
Lijiao committed
8
    height: number;
v-liguo's avatar
v-liguo committed
9
10
11
12
13
14
15
}

class MonacoHTML extends React.Component<MonacoEditorProps, {}> {
    constructor(props: MonacoEditorProps) {
        super(props);
    }

16
    render(): React.ReactNode {
Lijiao's avatar
Lijiao committed
17
        const { content, loading, height } = this.props;
v-liguo's avatar
v-liguo committed
18
        return (
19
            <React.Fragment>
20
21
22
23
24
25
26
                {loading ? (
                    <Spinner
                        label='Wait, wait...'
                        ariaLive='assertive'
                        labelPosition='right'
                        styles={{ root: { width: '100%', height: height } }}
                    >
27
                        <MonacoEditor
28
                            width='100%'
29
                            height={height}
30
                            language='json'
31
                            value={content}
32
33
34
35
36
37
                            options={{
                                minimap: { enabled: false },
                                readOnly: true,
                                automaticLayout: true,
                                wordWrap: 'on'
                            }}
38
                        />
39
40
                    </Spinner>
                ) : (
41
42
43
44
45
46
47
48
49
50
51
52
                    <MonacoEditor
                        width='100%'
                        height={height}
                        language='json'
                        value={content}
                        options={{
                            minimap: { enabled: false },
                            readOnly: true,
                            automaticLayout: true,
                            wordWrap: 'on'
                        }}
                    />
53
                )}
54
            </React.Fragment>
v-liguo's avatar
v-liguo committed
55
56
57
58
59
        );
    }
}

export default MonacoHTML;