Skip to content

Commit 3ea2805

Browse files
committed
feat: expose class json-viewer-theme-* for style customization
1 parent e10fe1d commit 3ea2805

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"@emotion/react": "^11.10.6",
6565
"@emotion/styled": "^11.10.6",
6666
"@mui/material": "^5.11.13",
67+
"clsx": "^1.2.1",
6768
"copy-to-clipboard": "^3.3.3",
6869
"zustand": "^4.3.6"
6970
},

src/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
createTheme, Paper,
33
ThemeProvider
44
} from '@mui/material'
5+
import clsx from 'clsx'
56
import type { FC, ReactElement } from 'react'
67
import { useCallback, useContext, useEffect, useMemo, useRef } from 'react'
78

@@ -74,6 +75,10 @@ const JsonViewerInner: FC<JsonViewerProps> = (props) => {
7475
})
7576
}
7677
}, [setState, props.theme])
78+
const themeCls = useMemo(() => {
79+
if (typeof props.theme === 'object') return 'json-viewer-theme-custom'
80+
return props.theme === 'dark' ? 'json-viewer-theme-dark' : 'json-viewer-theme-light'
81+
}, [props.theme])
7782
const onceRef = useRef(true)
7883
const predefinedTypes = useMemo(() => predefined(), [])
7984
const registerTypes = useTypeRegistryStore(store => store.registerTypes)
@@ -97,7 +102,7 @@ const JsonViewerInner: FC<JsonViewerProps> = (props) => {
97102
return (
98103
<Paper
99104
elevation={0}
100-
className={props.className}
105+
className={clsx(themeCls, props.className)}
101106
style={props.style}
102107
sx={{
103108
fontFamily: 'monospace',

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,6 +1715,7 @@ __metadata:
17151715
"@vitejs/plugin-react": ^3.1.0
17161716
"@vitest/coverage-c8": ^0.29.3
17171717
"@vitest/ui": ^0.29.3
1718+
clsx: ^1.2.1
17181719
copy-to-clipboard: ^3.3.3
17191720
eslint: ^8.36.0
17201721
eslint-config-standard: ^17.0.0

0 commit comments

Comments
 (0)