Skip to content

Commit c1ce6ed

Browse files
committed
feat: hide colon when key is empty
1 parent f03ab10 commit c1ce6ed

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

docs/pages/apis.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
| `style` | `CSSProperties` | - | Custom style. |
1010
| `sx` | `SxProps` | - | [The `sx` prop](https://mui.com/system/getting-started/the-sx-prop/) lets you style elements inline, using values from the theme. |
1111
| `indentWidth` | `number` | 3 | Indent width for nested objects |
12-
| `keyRenderer` | `{when: (props) => boolean}` | - | Customize a key, if `keyRenderer.when` returns `true`. |
12+
| `keyRenderer` | `{when: (props) => boolean}` | - | Customize the rendering of key when `keyRenderer.when` returns `true`. Render `null` in `keyRenderer` will cause the colons to be hidden. |
1313
| `valueTypes` | `ValueTypes` | - | Customize the definition of data types. See [Defining Data Types](/how-to/data-types) |
1414
| `enableAdd` | `boolean` \|<br />`(path, currentValue) => boolean` | `false` | Whether enable add feature. Provide a function to customize this behavior by returning a boolean based on the value and path. |
1515
| `enableDelete` | `boolean` \|<br />`(path, currentValue) => boolean` | `false` | Whether enable delete feature. Provide a function to customize this behavior by returning a boolean based on the value and path. |

src/components/DataKeyPair.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,11 @@ export const DataKeyPair: FC<DataKeyPairProps> = (props) => {
359359
)
360360
: null
361361
}
362-
<Box ref={highlightContainer} component='span'>
362+
<Box
363+
ref={highlightContainer}
364+
className='data-key-key'
365+
component='span'
366+
>
363367
{
364368
(isRoot && depth === 0
365369
? rootName !== false
@@ -380,7 +384,13 @@ export const DataKeyPair: FC<DataKeyPairProps> = (props) => {
380384
isRoot
381385
? (rootName !== false && <DataBox sx={{ mr: 0.5 }}>:</DataBox>)
382386
: nestedIndex === undefined && (
383-
<DataBox sx={{ mr: 0.5 }}>:</DataBox>
387+
<DataBox
388+
className='data-key-colon'
389+
sx={{
390+
mr: 0.5,
391+
'.data-key-key:empty + &': { display: 'none' }
392+
}}
393+
>:</DataBox>
384394
)
385395
)
386396
}

0 commit comments

Comments
 (0)