Skip to content

Commit df6931b

Browse files
committed
Small tweaks
1 parent 2464a88 commit df6931b

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Features include:
3131
- [Undo functionality](#undo-functionality)
3232
- [Issues, bugs, suggestions?](#issues-bugs-suggestions)
3333
- [Roadmap](#roadmap)
34+
- [Inspiration](#inspiration)
3435
- [Changelog](#changelog)
3536

3637

@@ -328,7 +329,12 @@ The main features I'd like to introduce are:
328329
2. **Visibility filter function***hide* properties from the UI completely based on a Filter function. This should arguably be done outside the component though (filter the data upstream), so would be less of a priority (though it would be fairly simple to implement, so 🤷‍♂️)
329330
3. **Search** — allow the user to narrow the list of visible keys with a simple search input. This would be useful for very large data objects, but is possibly getting a bit too much in terms of opinionated UI, so would need to ensure it can be styled easily. Perhaps it would be better if the "Search" input was handled outside this package, and we just accepted a "search" string prop?
330331

332+
## Inspiration
333+
334+
This component is heavily inspired by [react-json-view](https://github.com/mac-s-g/react-json-view), a great package that I've used in my own projects. However, it seems to have been abandoned now, and requires a few critical fixes, so I decided to create my own from scratch and extend the functionality while I was at it.
331335

332336
## Changelog
333337

334-
- **0.9.0**: Initial release
338+
- **0.9.0**: Initial release
339+
- **0.9.1**: Export more Types from the package
340+

demo/src/App.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useEffect, useRef } from 'react'
22
// import { JsonEditor, ThemeName, Theme, themes } from './json-edit-react/src'
3+
import { ThemeInput } from './json-edit-react/src'
34
import { JsonEditor, ThemeName, Theme, themes } from 'json-edit-react'
45
import { FaNpm, FaExternalLinkAlt, FaGithub } from 'react-icons/fa'
56
import { BiReset } from 'react-icons/bi'
@@ -42,7 +43,7 @@ function App() {
4243
const [rootName, setRootName] = useState('data')
4344
const [indent, setIndent] = useState(4)
4445
const [collapseLevel, setCollapseLevel] = useState(2)
45-
const [theme, setTheme] = useState<ThemeName>('default')
46+
const [theme, setTheme] = useState<ThemeInput>('default')
4647
const [allowEdit, setAllowEdit] = useState(true)
4748
const [allowDelete, setAllowDelete] = useState(true)
4849
const [allowAdd, setAllowAdd] = useState(true)
@@ -76,6 +77,10 @@ function App() {
7677
}
7778
}, [selectedData, reset])
7879

80+
useEffect(() => {
81+
if (selectedData === 'editTheme') setTheme(data)
82+
}, [data])
83+
7984
const restrictEdit: FilterFunction | boolean = (() => {
8085
const customRestrictor = demoData[selectedData]?.restrictEdit
8186
if (customRestrictor) return (input) => !allowEdit || customRestrictor(input)
@@ -115,6 +120,7 @@ function App() {
115120
switch (selectedData) {
116121
case 'editTheme':
117122
reset(themes[previousThemeName.current])
123+
setTheme(themes[previousThemeName.current])
118124
return
119125
case 'liveData':
120126
setIsSaving(true)
@@ -185,7 +191,7 @@ function App() {
185191
indent={indent}
186192
onUpdate={({ newData }) => {
187193
setData(newData)
188-
if (selectedData === 'editTheme') setTheme(newData as any)
194+
if (selectedData === 'editTheme') setTheme(newData)
189195
}}
190196
collapse={collapseLevel}
191197
enableClipboard={

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import JsonEditor from './JsonEditor'
2-
import { themes, ThemeName, Theme } from './theme'
2+
import { themes, ThemeName, Theme, ThemeInput } from './theme'
33

4-
export { JsonEditor, themes, type ThemeName, type Theme }
4+
export { JsonEditor, themes, type ThemeName, type Theme, type ThemeInput }

0 commit comments

Comments
 (0)