Skip to content

Commit

Permalink
feat: support passing sx props to customize the style
Browse files Browse the repository at this point in the history
  • Loading branch information
pionxzh committed Mar 21, 2023
1 parent c5e1753 commit e10fe1d
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/components/JsonViewerPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const JsonViewerPreview: FC<JsonViewerProps> = (props) => {
return (
<JsonViewer
theme={currentTheme}
style={{
sx={{
fontSize: 12
}}
value={props.value}
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/full/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ const IndexPage: FC = () => {
}, []
)
}
style={{
paddingLeft: 16
sx={{
paddingLeft: 2
}}
/>
</div>
Expand Down
1 change: 1 addition & 0 deletions docs/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Check the [source code](https://github.com/TexteaInc/json-viewer/blob/main/docs/
| `theme` | `"light"` <br />\| `"dark"` <br />\| `"auto"` <br />\| [Base16](https://github.com/chriskempson/base16) | `"light"` | Color theme. |
| `className` | `string` | - | Custom class name. |
| `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`. |
| `valueTypes` | `ValueTypes` | - | Customize value types. |
Expand Down
3 changes: 2 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ const JsonViewerInner: FC<JsonViewerProps> = (props) => {
sx={{
fontFamily: 'monospace',
userSelect: 'none',
contentVisibility: 'auto'
contentVisibility: 'auto',
...props.sx
}}
onMouseLeave={onMouseLeave}
>
Expand Down
2 changes: 2 additions & 0 deletions src/type.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { SxProps, Theme } from '@mui/material/styles'
import type { ComponentType, CSSProperties, Dispatch, FC, SetStateAction } from 'react'

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

className?: string
style?: CSSProperties
sx?: SxProps<Theme>
/**
*
* @default 'light'
Expand Down

0 comments on commit e10fe1d

Please sign in to comment.