Skip to content
This repository was archived by the owner on Sep 21, 2021. It is now read-only.

Commit d921c23

Browse files
committed
Add a prop to have ObjectInspector inline.
1 parent ddb0c05 commit d921c23

File tree

4 files changed

+124
-1
lines changed

4 files changed

+124
-1
lines changed

packages/devtools-reps/src/object-inspector/index.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
.tree {
66
overflow: auto;
7+
}
8+
9+
.tree.inline {
710
display: inline-block;
811
}
912

packages/devtools-reps/src/object-inspector/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type Props = {
6060
autoExpandDepth: number,
6161
disabledFocus: boolean,
6262
itemHeight: number,
63+
inline: boolean,
6364
mode: Mode,
6465
roots: Array<Node>,
6566
disableWrap: boolean,
@@ -373,6 +374,7 @@ class ObjectInspector extends Component {
373374
autoExpandDepth = 1,
374375
autoExpandAll = true,
375376
disabledFocus,
377+
inline,
376378
itemHeight = 20,
377379
disableWrap = false,
378380
} = this.props;
@@ -392,7 +394,10 @@ class ObjectInspector extends Component {
392394
}
393395

394396
return Tree({
395-
className: disableWrap ? "nowrap" : "",
397+
className: classnames({
398+
inline,
399+
nowrap: disableWrap,
400+
}),
396401
autoExpandAll,
397402
autoExpandDepth,
398403
disabledFocus,
@@ -422,6 +427,7 @@ ObjectInspector.propTypes = {
422427
autoExpandDepth: PropTypes.number,
423428
disabledFocus: PropTypes.bool,
424429
disableWrap: PropTypes.bool,
430+
inline: PropTypes.bool,
425431
roots: PropTypes.array,
426432
getObjectProperties: PropTypes.func.isRequired,
427433
loadObjectProperties: PropTypes.func.isRequired,
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`ObjectInspector - classnames has the expected class 1`] = `
4+
<ObjectInspector
5+
autoExpandDepth={0}
6+
getObjectProperties={[Function]}
7+
loadObjectProperties={[Function]}
8+
roots={
9+
Array [
10+
Object {
11+
"contents": Object {
12+
"value": 42,
13+
},
14+
"name": "root",
15+
"path": "root",
16+
},
17+
]
18+
}
19+
/>
20+
`;
21+
22+
exports[`ObjectInspector - classnames has the inline class when inline prop is true 1`] = `
23+
<ObjectInspector
24+
autoExpandDepth={0}
25+
getObjectProperties={[Function]}
26+
inline={true}
27+
loadObjectProperties={[Function]}
28+
roots={
29+
Array [
30+
Object {
31+
"contents": Object {
32+
"value": 42,
33+
},
34+
"name": "root",
35+
"path": "root",
36+
},
37+
]
38+
}
39+
/>
40+
`;
41+
42+
exports[`ObjectInspector - classnames has the nowrap class when disableWrap prop is true 1`] = `
43+
<ObjectInspector
44+
autoExpandDepth={0}
45+
disableWrap={true}
46+
getObjectProperties={[Function]}
47+
loadObjectProperties={[Function]}
48+
roots={
49+
Array [
50+
Object {
51+
"contents": Object {
52+
"value": 42,
53+
},
54+
"name": "root",
55+
"path": "root",
56+
},
57+
]
58+
}
59+
/>
60+
`;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
const { mount } = require("enzyme");
6+
const React = require("react");
7+
const { createFactory } = React;
8+
const ObjectInspector = createFactory(require("../../index"));
9+
10+
function generateDefaults(overrides) {
11+
return Object.assign({
12+
autoExpandDepth: 0,
13+
roots: [{
14+
path: "root",
15+
name: "root",
16+
contents: {value: 42}
17+
}],
18+
getObjectProperties: () => {},
19+
loadObjectProperties: () => {},
20+
}, overrides);
21+
}
22+
23+
describe("ObjectInspector - classnames", () => {
24+
it("has the expected class", () => {
25+
const props = generateDefaults();
26+
const oi = ObjectInspector(props);
27+
const wrapper = mount(oi);
28+
29+
expect(wrapper.hasClass("tree")).toBeTruthy();
30+
expect(wrapper.hasClass("inline")).toBeFalsy();
31+
expect(wrapper.hasClass("nowrap")).toBeFalsy();
32+
expect(oi).toMatchSnapshot();
33+
});
34+
35+
it("has the nowrap class when disableWrap prop is true", () => {
36+
const props = generateDefaults({
37+
disableWrap: true,
38+
});
39+
const oi = ObjectInspector(props);
40+
const wrapper = mount(oi);
41+
expect(wrapper.hasClass("nowrap")).toBeTruthy();
42+
expect(oi).toMatchSnapshot();
43+
});
44+
45+
it("has the inline class when inline prop is true", () => {
46+
const props = generateDefaults({
47+
inline: true,
48+
});
49+
const oi = ObjectInspector(props);
50+
const wrapper = mount(oi);
51+
expect(wrapper.hasClass("inline")).toBeTruthy();
52+
expect(oi).toMatchSnapshot();
53+
});
54+
});

0 commit comments

Comments
 (0)