Skip to content

Commit d11316a

Browse files
committed
fix: border color and expand icon
1 parent 0a538a4 commit d11316a

File tree

6 files changed

+29
-9
lines changed

6 files changed

+29
-9
lines changed

examples/basic/pages/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const KeyRenderer: JsonViewerKeyRenderer = ({ path }) => {
7979
KeyRenderer.when = (props) => props.value === 114.514
8080

8181
const IndexPage: React.FC = () => {
82-
const [indent, setIndent] = useState(2)
82+
const [indent, setIndent] = useState(3)
8383
const [groupArraysAfterLength, setGroupArraysAfterLength] = useState(100)
8484
const [theme, setTheme] = useState<JsonViewerTheme>('light')
8585
const [src, setSrc] = useState(() => example)
@@ -121,7 +121,7 @@ const IndexPage: React.FC = () => {
121121
}
122122
}
123123
/>
124-
<FormControl fullWidth>
124+
<FormControl>
125125
<InputLabel>Theme</InputLabel>
126126
<Select
127127
value={theme}

src/components/DataKeyPair.tsx

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import {
22
Check as CheckIcon,
3+
ChevronRight as ChevronRightIcon,
34
Close as CloseIcon,
45
ContentCopy as ContentCopyIcon,
5-
Edit as EditIcon
6+
Edit as EditIcon,
7+
ExpandMore as ExpandMoreIcon
68
} from '@mui/icons-material'
79
import { Box, styled } from '@mui/material'
810
import type React from 'react'
@@ -145,7 +147,7 @@ export const DataKeyPair: React.FC<DataKeyPairProps> = (props) => {
145147
},
146148
[Editor, copied, copy, editable, editing, onChange, path, tempValue, value])
147149

148-
const expandable = PreComponent && PostComponent
150+
const expandable = !!(PreComponent && PostComponent)
149151
const KeyRenderer = useJsonViewerStore(store => store.keyRenderer)
150152
return (
151153
<Box className='data-key-pair'
@@ -172,6 +174,18 @@ export const DataKeyPair: React.FC<DataKeyPairProps> = (props) => {
172174
}, [setInspect])
173175
}
174176
>
177+
{
178+
expandable
179+
? (inspect
180+
? <ExpandMoreIcon sx={{
181+
fontSize: '.8rem'
182+
}}/>
183+
: <ChevronRightIcon sx={{
184+
fontSize: '.8rem'
185+
}}/>
186+
)
187+
: null
188+
}
175189
{
176190
(isRoot && rootName !== false)
177191
? <>&quot;{rootName}&quot;</>

src/components/DataTypes/Object.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ function getIterator (value: any): value is Iterable<unknown> {
104104

105105
export const ObjectType: React.FC<DataItemProps<object>> = (props) => {
106106
const keyColor = useTextColor()
107+
const borderColor = useJsonViewerStore(store => store.colorNamespace.base02)
107108
const groupArraysAfterLength = useJsonViewerStore(
108109
store => store.groupArraysAfterLength)
109110
const isTrap = useIsCycleReference(props.path, props.value)
@@ -223,14 +224,18 @@ export const ObjectType: React.FC<DataItemProps<object>> = (props) => {
223224
groupArraysAfterLength,
224225
displayLength,
225226
keyColor])
226-
const indentWidth = useJsonViewerStore(store => store.indentWidth)
227+
const marginLeft = props.inspect ? 0.6 : 0
228+
const width = useJsonViewerStore(store => store.indentWidth)
229+
const indentWidth = props.inspect ? width - marginLeft : width
227230
return (
228231
<Box
229232
className='data-object'
230233
sx={{
231234
display: props.inspect ? 'block' : 'inline-block',
232-
pl: props.inspect ? indentWidth : 0,
233-
color: keyColor
235+
pl: props.inspect ? indentWidth - 0.6 : 0,
236+
marginLeft,
237+
color: keyColor,
238+
borderLeft: props.inspect ? `1px solid ${borderColor}` : 'none'
234239
}}
235240
>
236241
{

src/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const JsonViewerInner: React.FC<JsonViewerProps> = (props) => {
6363
const setHover = useJsonViewerStore(store => store.setHover)
6464
return (
6565
<Paper
66+
elevation={0}
6667
className={props.className}
6768
style={props.style}
6869
sx={{

src/stores/JsonViewerStore.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const createJsonViewerStore = <T = unknown>(props: JsonViewerProps<T>) =>
4040
{
4141
inspectCache: {},
4242
hoverPath: null,
43-
indentWidth: props.indentWidth ?? 2,
43+
indentWidth: props.indentWidth ?? 3,
4444
groupArraysAfterLength: props.groupArraysAfterLength ?? 100,
4545
collapseStringsAfterLength: props.collapseStringsAfterLength ?? 50,
4646
maxDisplayLength: props.maxDisplayLength ?? 30,

src/type.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export type JsonViewerProps<T = unknown> = {
4242
value: T
4343
/**
4444
* Indent width for nested objects
45-
* @default 2
45+
* @default 3
4646
*/
4747
indentWidth?: number
4848
/**

0 commit comments

Comments
 (0)