|
1 | 1 | import React, { useEffect, useRef } from 'react' |
2 | | -// import { JsonEditor, ThemeName, Theme, themes } from './json-edit-react/src' |
3 | | -import { JsonEditor, ThemeName, Theme, themes } from 'json-edit-react' |
| 2 | +// import { JsonEditor, themes, ThemeName, Theme, ThemeInput } from './json-edit-react/src' |
| 3 | +import { JsonEditor, themes, ThemeName, Theme, ThemeInput } from 'json-edit-react' |
4 | 4 | import { FaNpm, FaExternalLinkAlt, FaGithub } from 'react-icons/fa' |
5 | 5 | import { BiReset } from 'react-icons/bi' |
6 | 6 | import { AiOutlineCloudUpload } from 'react-icons/ai' |
@@ -42,7 +42,7 @@ function App() { |
42 | 42 | const [rootName, setRootName] = useState('data') |
43 | 43 | const [indent, setIndent] = useState(4) |
44 | 44 | const [collapseLevel, setCollapseLevel] = useState(2) |
45 | | - const [theme, setTheme] = useState<ThemeName>('default') |
| 45 | + const [theme, setTheme] = useState<ThemeInput>('default') |
46 | 46 | const [allowEdit, setAllowEdit] = useState(true) |
47 | 47 | const [allowDelete, setAllowDelete] = useState(true) |
48 | 48 | const [allowAdd, setAllowAdd] = useState(true) |
@@ -76,6 +76,10 @@ function App() { |
76 | 76 | } |
77 | 77 | }, [selectedData, reset]) |
78 | 78 |
|
| 79 | + useEffect(() => { |
| 80 | + if (selectedData === 'editTheme') setTheme(data) |
| 81 | + }, [data]) |
| 82 | + |
79 | 83 | const restrictEdit: FilterFunction | boolean = (() => { |
80 | 84 | const customRestrictor = demoData[selectedData]?.restrictEdit |
81 | 85 | if (customRestrictor) return (input) => !allowEdit || customRestrictor(input) |
@@ -115,6 +119,7 @@ function App() { |
115 | 119 | switch (selectedData) { |
116 | 120 | case 'editTheme': |
117 | 121 | reset(themes[previousThemeName.current]) |
| 122 | + setTheme(themes[previousThemeName.current]) |
118 | 123 | return |
119 | 124 | case 'liveData': |
120 | 125 | setIsSaving(true) |
@@ -185,7 +190,7 @@ function App() { |
185 | 190 | indent={indent} |
186 | 191 | onUpdate={({ newData }) => { |
187 | 192 | setData(newData) |
188 | | - if (selectedData === 'editTheme') setTheme(newData as any) |
| 193 | + if (selectedData === 'editTheme') setTheme(newData) |
189 | 194 | }} |
190 | 195 | collapse={collapseLevel} |
191 | 196 | enableClipboard={ |
|
0 commit comments