embark-area-51/lib/modules/webserver/backend/contracts/components/source-area.js

39 lines
921 B
JavaScript
Raw Normal View History

2018-08-02 19:17:40 +00:00
/*global hljs*/
import React from 'react';
import PropTypes from 'prop-types';
2018-04-18 19:06:41 +00:00
class SourceArea extends React.Component {
2018-08-02 19:17:40 +00:00
constructor(props) {
super(props);
this.state = {
sourceCode: ""
};
}
componentDidMount() {
let colorCodedText = hljs.highlight('javascript', this.props.source, true).value;
this.setState({sourceCode: colorCodedText});
}
2018-04-18 19:06:41 +00:00
2018-08-02 19:17:40 +00:00
render() {
return <div className="card">
<div className="card-header">
<h3 className="card-title">{this.props.definition.className}</h3>
<div className="card-options">
<small>{this.props.definition.filename}</small>
</div>
</div>
<div className="card-body">
<pre dangerouslySetInnerHTML={{__html: this.state.sourceCode}}></pre>
</div>
</div>;
}
2018-04-18 19:06:41 +00:00
}
2018-08-02 19:17:40 +00:00
SourceArea.propTypes = {
definition: PropTypes.object,
source: PropTypes.string
};
export default SourceArea;