Skip to content

Commit e10fe1d

Browse files
committed
feat: support passing sx props to customize the style
1 parent c5e1753 commit e10fe1d

File tree

5 files changed

+8
-4
lines changed

5 files changed

+8
-4
lines changed

docs/components/JsonViewerPreview.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const JsonViewerPreview: FC<JsonViewerProps> = (props) => {
99
return (
1010
<JsonViewer
1111
theme={currentTheme}
12-
style={{
12+
sx={{
1313
fontSize: 12
1414
}}
1515
value={props.value}

docs/pages/full/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ const IndexPage: FC = () => {
277277
}, []
278278
)
279279
}
280-
style={{
281-
paddingLeft: 16
280+
sx={{
281+
paddingLeft: 2
282282
}}
283283
/>
284284
</div>

docs/pages/index.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ Check the [source code](https://github.com./TexteaInc/json-viewer/blob/main/docs/
8787
| `theme` | `"light"` <br />\| `"dark"` <br />\| `"auto"` <br />\| [Base16](https://github.com./chriskempson/base16) | `"light"` | Color theme. |
8888
| `className` | `string` | - | Custom class name. |
8989
| `style` | `CSSProperties` | - | Custom style. |
90+
| `sx` | `SxProps` | - | [The `sx` prop](https://mui.com/system/getting-started/the-sx-prop/) lets you style elements inline, using values from the theme. |
9091
| `indentWidth` | `number` | 3 | Indent width for nested objects |
9192
| `keyRenderer` | `{when: (props) => boolean}` | - | Customize a key, if `keyRenderer.when` returns `true`. |
9293
| `valueTypes` | `ValueTypes` | - | Customize value types. |

src/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ const JsonViewerInner: FC<JsonViewerProps> = (props) => {
102102
sx={{
103103
fontFamily: 'monospace',
104104
userSelect: 'none',
105-
contentVisibility: 'auto'
105+
contentVisibility: 'auto',
106+
...props.sx
106107
}}
107108
onMouseLeave={onMouseLeave}
108109
>

src/type.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { SxProps, Theme } from '@mui/material/styles'
12
import type { ComponentType, CSSProperties, Dispatch, FC, SetStateAction } from 'react'
23

34
import type { Colorspace } from './theme/base16'
@@ -154,6 +155,7 @@ export type JsonViewerProps<T = unknown> = {
154155

155156
className?: string
156157
style?: CSSProperties
158+
sx?: SxProps<Theme>
157159
/**
158160
*
159161
* @default 'light'

0 commit comments

Comments
 (0)