Skip to content

Commit 777d17e

Browse files
authored
feat(parseJson): added the ability to include json parse in the editor (#120)
1 parent f710ecb commit 777d17e

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/stories/components/Editor/Editor.scss

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,23 @@
2424
overflow-y: auto;
2525
}
2626

27+
&__parse-json {
28+
margin-bottom: 20px;
29+
display: flex;
30+
align-items: center;
31+
}
32+
33+
&__switch {
34+
margin-left: 20px;
35+
}
36+
2737
&__toggler {
2838
margin-bottom: 20px;
2939
}
3040

3141
&__monaco {
3242
width: 640px;
33-
height: 100%;
43+
height: calc(100% - 40px);
3444

3545
.df-monaco-input {
3646
width: 100%;

src/stories/components/Editor/Editor.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
import {RadioButton} from '@gravity-ui/uikit';
3+
import {RadioButton, Switch, Text} from '@gravity-ui/uikit';
44
import _ from 'lodash';
55
import {Form} from 'react-final-form';
66
import MonacoEditor from 'react-monaco-editor';
@@ -31,6 +31,7 @@ export const Editor: React.FC<EditorProps> = ({spec: externalSpec, value, viewMo
3131
const [spec, setSpec] = React.useState(externalSpec);
3232
const [ready, setReady] = React.useState(true);
3333
const [toggler, setToggler] = React.useState<'form' | 'view' | 'json'>('form');
34+
const [parseJson, setParseJson] = React.useState(false);
3435

3536
const togglerItems = React.useMemo(
3637
() => [
@@ -113,6 +114,10 @@ export const Editor: React.FC<EditorProps> = ({spec: externalSpec, value, viewMo
113114
return (
114115
<div className={b({docs: viewMode === 'docs'})}>
115116
<div className={b('options')}>
117+
<div className={b('parse-json')}>
118+
<Text variant="body-2">Parse default values like json</Text>
119+
<Switch onChange={() => setParseJson((v) => !v)} className={b('switch')} />
120+
</div>
116121
<div className={b('monaco')}>
117122
<MonacoInput {...specEditorProps} />
118123
</div>
@@ -137,7 +142,7 @@ export const Editor: React.FC<EditorProps> = ({spec: externalSpec, value, viewMo
137142
<DynamicField
138143
name="input"
139144
spec={spec}
140-
parseJsonDefaultValue={false}
145+
parseJsonDefaultValue={parseJson}
141146
/>
142147
</div>
143148
) : null}

0 commit comments

Comments
 (0)