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