Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit 91e241d

Browse files
author
Dom Harrington
committed
Make sure code blocks have the correct styling when in sidebar
1 parent 020db21 commit 91e241d

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

packages/api-explorer-ui/__tests__/block-types/Content.test.jsx

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,58 @@ const body = `
3636
`;
3737

3838
test('should output only left content if `isThreeColumn=left`', () => {
39-
const content = mount(<Content body={body} isThreeColumn='left' />);
39+
const content = mount(<Content body={body} isThreeColumn="left" />);
4040

4141
expect(content.find('.magic-block-textarea').length).toBe(1);
4242
});
4343

4444
test('should output only right content if `isThreeColumn=right`', () => {
45-
const content = mount(<Content body={body} isThreeColumn='right' />);
45+
const content = mount(<Content body={body} isThreeColumn="right" />);
4646

4747
expect(content.find('.magic-block-api-header').length).toBe(1);
4848
});
49+
50+
test('should make code not-dark if it is in the left column', () => {
51+
const content = mount(
52+
<Content
53+
body={`
54+
[block:code]
55+
{
56+
"codes": [
57+
{
58+
"code": "var a = 1;",
59+
"language": "javascript"
60+
}
61+
]
62+
}
63+
[/block]
64+
`}
65+
isThreeColumn="left"
66+
/>,
67+
);
68+
69+
expect(content.html()).toContain('cm-s-neo');
70+
});
71+
72+
test('should make code `dark` if it is in right column', () => {
73+
const content = mount(
74+
<Content
75+
body={`
76+
[block:code]
77+
{
78+
"codes": [
79+
{
80+
"code": "var a = 1;",
81+
"language": "javascript"
82+
}
83+
],
84+
"sidebar": true
85+
}
86+
[/block]
87+
`}
88+
isThreeColumn="right"
89+
/>,
90+
);
91+
92+
expect(content.html()).toContain('cm-s-tomorrow-night');
93+
});

packages/api-explorer-ui/src/block-types/Code.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class BlockCode extends React.Component {
1515
this.setState({ activeTab: i });
1616
}
1717
render() {
18-
const { block, opts = {} } = this.props;
18+
const { block, opts = {}, dark } = this.props;
1919
const codes = Array.isArray(block.data.codes) ? block.data.codes : [];
2020

2121
return (
@@ -64,7 +64,7 @@ class BlockCode extends React.Component {
6464
<code
6565
// eslint-disable-next-line
6666
dangerouslySetInnerHTML={{
67-
__html: syntaxHighlighter(code.code, code.language, opts.dark),
67+
__html: syntaxHighlighter(code.code, code.language, dark),
6868
}}
6969
/>
7070
}

packages/api-explorer-ui/src/block-types/Content.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ const Content = props => {
7878
);
7979
}
8080

81-
return <Loop content={isThreeColumn === 'left' ? left : right} flags={props.flags} />;
81+
return (
82+
<Loop
83+
content={isThreeColumn === 'left' ? left : right}
84+
flags={props.flags}
85+
column={isThreeColumn}
86+
/>
87+
);
8288
};
8389

8490
Loop.propTypes = {
@@ -97,7 +103,7 @@ Loop.defaultProps = {
97103
};
98104

99105
Content.propTypes = {
100-
isThreeColumn: PropTypes.oneOfType([ PropTypes.bool, PropTypes.string ]),
106+
isThreeColumn: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
101107
body: PropTypes.string,
102108
flags: PropTypes.shape({}),
103109
};

0 commit comments

Comments
 (0)