-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathres-editor.tsx
48 lines (43 loc) · 1.18 KB
/
res-editor.tsx
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
44
45
46
47
48
import { Component, h, Element, State, Prop, Host } from '@stencil/core';
import { EditorState, basicSetup } from '@codemirror/basic-setup';
import { EditorView } from '@codemirror/view';
import { json } from '@codemirror/lang-json';
@Component({
tag: 'res-editor',
scoped: true,
})
export class ResEditor {
@Element() element: HTMLElement;
@State() view: EditorView;
@State() state: EditorState;
@Prop() doc: any;
@Prop() responseLabel: 'result' | 'error' = 'result';
labelTitle = {
result: {
tag: 'Success 200',
class: 'text-green-700 text-sm font-semibold pb-2',
},
error: {
tag: 'Error',
class: 'text-red-700 text-sm font-semibold pb-2',
},
};
componentDidLoad() {
this.state = EditorState.create({
doc: this.doc,
extensions: [basicSetup, EditorView.editable.of(false), json()],
});
this.view = new EditorView({
state: this.state,
parent: this.element.querySelector('#res-editor'),
});
}
render() {
return (
<Host>
<p class={this.labelTitle[this.responseLabel].class}>{this.labelTitle[this.responseLabel].tag}</p>
<div id="res-editor"></div>
</Host>
);
}
}