forked from zoltantothcom/Design-Patterns-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode.jsx
More file actions
40 lines (34 loc) · 1.11 KB
/
Code.jsx
File metadata and controls
40 lines (34 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { Light as SyntaxHighlighter } from 'react-syntax-highlighter';
import js from 'react-syntax-highlighter/dist/languages/hljs/javascript';
import { getJS, getCurrent } from '../selectors';
import CodePreTag from './CodePreTag';
SyntaxHighlighter.registerLanguage('javascript', js);
const Code = props => {
const { js, current, style } = props;
return (
<Fragment>
{js === 'es5' && (
<SyntaxHighlighter language="javascript" style={style} className="fixed" PreTag={CodePreTag}>
{current.codeES5}
</SyntaxHighlighter>
)}
{js === 'es6' && (
<SyntaxHighlighter language="javascript" style={style} className="fixed" PreTag={CodePreTag}>
{current.codeES6}
</SyntaxHighlighter>
)}
</Fragment>
);
};
Code.propTypes = {
js: PropTypes.string.isRequired,
current: PropTypes.object.isRequired,
style: PropTypes.object.isRequired
};
export default connect(state => ({
js: getJS(state),
current: getCurrent(state)
}))(Code);