From 2addc2cdf2e36f47877f3405329d956d7cb54433 Mon Sep 17 00:00:00 2001 From: Nikita Zolotykh Date: Fri, 21 Jun 2024 16:18:22 +0200 Subject: [PATCH] refactor: add theme condition for monaco --- src/stories/components/Editor/Editor.tsx | 21 ++++++--- .../components/InputPreview/InputPreview.tsx | 43 ++++++++++++------- 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/src/stories/components/Editor/Editor.tsx b/src/stories/components/Editor/Editor.tsx index 8279917c..d8800321 100644 --- a/src/stories/components/Editor/Editor.tsx +++ b/src/stories/components/Editor/Editor.tsx @@ -1,6 +1,6 @@ import React from 'react'; -import {RadioButton, Switch, Text} from '@gravity-ui/uikit'; +import {RadioButton, Switch, Text, useTheme} from '@gravity-ui/uikit'; import noop from 'lodash/noop'; import {Form} from 'react-final-form'; import MonacoEditor from 'react-monaco-editor'; @@ -32,6 +32,7 @@ export const Editor: React.FC = ({spec: externalSpec, value, viewMo const [ready, setReady] = React.useState(true); const [toggler, setToggler] = React.useState<'form' | 'view' | 'json'>('form'); const [parseJson, setParseJson] = React.useState(false); + const theme = useTheme(); const togglerItems = React.useMemo( () => [ @@ -70,11 +71,16 @@ export const Editor: React.FC = ({spec: externalSpec, value, viewMo }, spec: {viewSpec: {monacoParams: {language: 'json', fontSize: 11}}}, MonacoComponent: (props: MonacoEditorProps) => ( - + ), withoutDialog: true, }) as MonacoInputBaseProps, - [], + [theme], ); const getValuesEditorProps = React.useCallback( @@ -86,11 +92,16 @@ export const Editor: React.FC = ({spec: externalSpec, value, viewMo }, spec: {viewSpec: {monacoParams: {language: 'json', fontSize: 11}, disabled: true}}, MonacoComponent: (props: MonacoEditorProps) => ( - + ), withoutDialog: true, }) as MonacoInputBaseProps, - [], + [theme], ); const getViewProps = React.useCallback( diff --git a/src/stories/components/InputPreview/InputPreview.tsx b/src/stories/components/InputPreview/InputPreview.tsx index 26aaacd5..5f6e7282 100644 --- a/src/stories/components/InputPreview/InputPreview.tsx +++ b/src/stories/components/InputPreview/InputPreview.tsx @@ -1,6 +1,6 @@ import React from 'react'; -import {RadioButton, TextInput} from '@gravity-ui/uikit'; +import {RadioButton, TextInput, useTheme} from '@gravity-ui/uikit'; import noop from 'lodash/noop'; import {Form} from 'react-final-form'; import MonacoEditor from 'react-monaco-editor'; @@ -33,6 +33,7 @@ export const InputPreview: React.FC = ({ const [searchInput, setSearchInput] = React.useState(''); const [toggler, setToggler] = React.useState<'form' | 'json'>('form'); const [togglerInput, setTogglerInput] = React.useState<'form' | 'view' | 'json'>('form'); + const theme = useTheme(); const togglerItems = React.useMemo( () => [ @@ -61,21 +62,33 @@ export const InputPreview: React.FC = ({ [setTogglerInput], ); - const renderMonaco = React.useCallback((value: FormValue) => { - const monacoProps = { - input: { - value: JSON.stringify(value, (_, value) => (value === undefined ? null : value), 2), - onChange: noop, - }, - spec: {viewSpec: {monacoParams: {language: 'json', fontSize: 11}, disabled: true}}, - MonacoComponent: (props: MonacoEditorProps) => ( - - ), - withoutDialog: true, - } as MonacoInputBaseProps; + const renderMonaco = React.useCallback( + (value: FormValue) => { + const monacoProps = { + input: { + value: JSON.stringify( + value, + (_, value) => (value === undefined ? null : value), + 2, + ), + onChange: noop, + }, + spec: {viewSpec: {monacoParams: {language: 'json', fontSize: 11}, disabled: true}}, + MonacoComponent: (props: MonacoEditorProps) => ( + + ), + withoutDialog: true, + } as MonacoInputBaseProps; - return ; - }, []); + return ; + }, + [theme], + ); const initialValues = React.useMemo( () => ({