Skip to content

Commit 8a8a739

Browse files
committed
added explicit style support for rjv container
1 parent e0665cf commit 8a8a739

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Name|Type|Default|Description
4444
`src`|`JSON Object`|None|This property contains your input JSON
4545
`name`|`string`|"root"|Contains the name of your root node
4646
`theme`|`string`|"rjv-default"|RJV supports base-16 themes. Check out the [list of supported themes here](https://github.com/gaearon/base16-js/tree/master/src). A custom "rjv-default" theme applies by default.
47+
`style`|`object`|`{}`|style attributes for react-json-view container. Explicit style attributes will override attributes provided by a theme.
4748
`indentWidth`|`integer`|4|Set the indent-width for nested objects
4849
`collapsed`|`boolean` or `integer`|`false`|When set to `true`, all nodes will be collapsed by default. Use an integer value to collapse at a particular depth.
4950
`collapseStringsAfterLength`|`integer`|`false`|When an integer value is assigned, strings will be cut off at that length. Collapsed strings are followed by an ellipsis. String content can be expanded and collapsed by clicking on the string value.

example/example.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ReactDom.render(
1212
<div>
1313
{/* just pass in your JSON to the src attribute */}
1414
<JsonViewer
15+
style={{padding:'30px', backgroundColor: 'white'}}
1516
src={getExampleJson1()}
1617
collapseStringsAfterLength={12}
1718
onEdit={(e)=>{console.log(e)}}

src/js/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export default class extends React.Component {
4343
displayDataTypes: true,
4444
onEdit: false,
4545
onDelete: false,
46-
onAdd: false
46+
onAdd: false,
47+
style: {}
4748
}
4849

4950
getListeners = () => {
@@ -114,11 +115,11 @@ export default class extends React.Component {
114115
}
115116

116117
render() {
117-
const {addKeyRequest, ...props} = this.state;
118+
const {addKeyRequest, style, ...props} = this.state;
118119
//reset key request to false once it's observed
119120
this.state.addKeyRequest = false;
120121
return (<div class="react-json-view"
121-
{...Theme(props.theme, 'app-container')} >
122+
style={{...Theme(props.theme, 'app-container').style, ...style}} >
122123
<JsonViewer {...props} type={toType(props.src)} rjvId={this.rjvId} />
123124
<AddKeyRequest active={addKeyRequest} theme={props.theme} rjvId={this.rjvId} />
124125
</div>);

0 commit comments

Comments
 (0)