Skip to content

Commit bd632ae

Browse files
authored
Merge pull request #209 from lightingbeetle/fix/preview-html
Fix/preview html
2 parents 1f19f89 + d177dde commit bd632ae

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

packages/styleguide/src/components/MDX/MDX.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ export const MDXComponents = {
3636
a: props => <Link {...props} />,
3737
inlineCode: props => <Code {...props} />,
3838
code: props => (
39-
<CodeBlock language={props.className.replace(/language-/, '')} {...props} />
39+
<CodeBlock
40+
language={props.className && props.className.replace(/language-/, '')}
41+
{...props}
42+
/>
4043
),
4144
};
4245

packages/styleguide/src/components/Preview/CodeExample.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,15 @@ export default class CodeExample extends React.Component {
167167
}
168168

169169
render() {
170-
const { children, codeJSXOptions, codeTypes, theme, ...other } = this.props;
170+
const { children, codeJSXOptions, codeTypes, ...other } = this.props;
171171

172172
let codeToShow;
173173
switch (this.state.codePreviewType) {
174174
case 'html':
175175
codeToShow = pretty(
176176
typeof children === 'string'
177177
? unescape(children)
178-
: renderToStaticMarkup({
179-
...children,
180-
props: { ...children.props, theme },
181-
}),
178+
: renderToStaticMarkup(children),
182179
{
183180
ocd: true,
184181
}
@@ -214,6 +211,7 @@ export default class CodeExample extends React.Component {
214211
<Code
215212
inline={false}
216213
ref={this.codeBlockRef}
214+
data-testid={this.state.codePreviewType}
217215
language={
218216
this.state.codePreviewType === 'html'
219217
? 'markup'
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { render } from '@testing-library/react';
2+
import { render, fireEvent } from '@testing-library/react';
33

44
import Preview from '.';
55

@@ -8,4 +8,19 @@ describe('rendering', () => {
88
const { getByText } = render(<Preview>Preview</Preview>);
99
expect(getByText('Preview')).toBeInTheDocument();
1010
});
11+
12+
it('HTML preview renders more than 1 child', () => {
13+
const { getByText, getByTestId } = render(
14+
<Preview>
15+
<p>Paragraph 1</p>
16+
<p>Paragraph 2</p>
17+
</Preview>
18+
);
19+
20+
fireEvent.click(getByText('SHOW CODE'));
21+
22+
fireEvent.click(getByText('HTML'));
23+
24+
expect(getByTestId('html')).toBeInTheDocument();
25+
});
1126
});

0 commit comments

Comments
 (0)