Skip to content

Commit

Permalink
feat: hide colon when key is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
pionxzh committed Aug 13, 2024
1 parent f03ab10 commit c1ce6ed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/pages/apis.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
| `style` | `CSSProperties` | - | Custom style. |
| `sx` | `SxProps` | - | [The `sx` prop](https://mui.com/system/getting-started/the-sx-prop/) lets you style elements inline, using values from the theme. |
| `indentWidth` | `number` | 3 | Indent width for nested objects |
| `keyRenderer` | `{when: (props) => boolean}` | - | Customize a key, if `keyRenderer.when` returns `true`. |
| `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. |
| `valueTypes` | `ValueTypes` | - | Customize the definition of data types. See [Defining Data Types](/how-to/data-types) |
| `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. |
| `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. |
Expand Down
14 changes: 12 additions & 2 deletions src/components/DataKeyPair.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,11 @@ export const DataKeyPair: FC<DataKeyPairProps> = (props) => {
)
: null
}
<Box ref={highlightContainer} component='span'>
<Box
ref={highlightContainer}
className='data-key-key'
component='span'
>
{
(isRoot && depth === 0
? rootName !== false
Expand All @@ -380,7 +384,13 @@ export const DataKeyPair: FC<DataKeyPairProps> = (props) => {
isRoot
? (rootName !== false && <DataBox sx={{ mr: 0.5 }}>:</DataBox>)
: nestedIndex === undefined && (
<DataBox sx={{ mr: 0.5 }}>:</DataBox>
<DataBox
className='data-key-colon'
sx={{
mr: 0.5,
'.data-key-key:empty + &': { display: 'none' }
}}
>:</DataBox>
)
)
}
Expand Down

0 comments on commit c1ce6ed

Please sign in to comment.