2016-07-18 01:06:43 +02:00
|
|
|
import React, { PropTypes } from 'react';
|
2016-07-21 06:33:41 +02:00
|
|
|
import InlineSVG from 'react-inlinesvg';
|
|
|
|
const upArrowUrl = require('../../../images/up-arrow.svg');
|
|
|
|
const downArrowUrl = require('../../../images/down-arrow.svg');
|
|
|
|
import classNames from 'classnames';
|
2016-07-18 01:06:43 +02:00
|
|
|
|
|
|
|
class Console extends React.Component {
|
2016-07-21 06:05:47 +02:00
|
|
|
componentDidUpdate() {
|
|
|
|
this.refs.console_messages.scrollTop = this.refs.console_messages.scrollHeight;
|
|
|
|
}
|
|
|
|
|
2016-07-18 02:49:57 +02:00
|
|
|
render() {
|
2016-07-21 06:33:41 +02:00
|
|
|
const consoleClass = classNames({
|
|
|
|
'preview-console': true,
|
|
|
|
'preview-console--collapsed': !this.props.isExpanded
|
|
|
|
});
|
2016-07-18 01:06:43 +02:00
|
|
|
|
|
|
|
return (
|
2016-08-10 23:24:52 +02:00
|
|
|
<div ref="console" className={consoleClass} role="main" tabIndex="0" title="console">
|
2016-07-21 06:33:41 +02:00
|
|
|
<div className="preview-console__header">
|
2017-01-11 20:13:49 +01:00
|
|
|
<h2 className="preview-console__header-title">Console</h2>
|
2017-01-10 00:09:23 +01:00
|
|
|
<div className="preview-console__header-buttons">
|
2017-01-11 20:13:49 +01:00
|
|
|
<a className="preview-console__clear" onClick={this.props.clearConsole} aria-label="clear console">
|
2017-01-10 00:09:23 +01:00
|
|
|
Clear
|
2017-01-11 20:13:49 +01:00
|
|
|
</a>
|
2017-01-10 00:09:23 +01:00
|
|
|
<button className="preview-console__collapse" onClick={this.props.collapseConsole} aria-label="collapse console">
|
|
|
|
<InlineSVG src={downArrowUrl} />
|
|
|
|
</button>
|
|
|
|
<button className="preview-console__expand" onClick={this.props.expandConsole} aria-label="expand console">
|
|
|
|
<InlineSVG src={upArrowUrl} />
|
|
|
|
</button>
|
|
|
|
</div>
|
2016-07-21 06:33:41 +02:00
|
|
|
</div>
|
2016-07-21 06:05:47 +02:00
|
|
|
<div ref="console_messages" className="preview-console__messages">
|
2017-01-11 20:13:49 +01:00
|
|
|
{this.props.consoleEvents.map((consoleEvent, index) => {
|
|
|
|
const args = consoleEvent.arguments;
|
|
|
|
const method = consoleEvent.method;
|
|
|
|
if (Object.keys(args).length === 0) {
|
|
|
|
return (
|
|
|
|
<div key={index} className="preview-console__undefined">
|
|
|
|
<span key={`${index}-0`}>{'undefined'}</span>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<div key={index} className={`preview-console__${method}`}>
|
|
|
|
{Object.keys(args).map((key) => <span key={`${index}-${key}`}>{args[key]}</span>)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
2016-07-21 06:05:47 +02:00
|
|
|
</div>
|
2016-07-18 01:06:43 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Console.propTypes = {
|
2017-01-11 20:13:49 +01:00
|
|
|
consoleEvents: PropTypes.array,
|
2016-07-21 06:33:41 +02:00
|
|
|
isPlaying: PropTypes.bool.isRequired,
|
|
|
|
isExpanded: PropTypes.bool.isRequired,
|
|
|
|
collapseConsole: PropTypes.func.isRequired,
|
2016-10-06 19:01:48 +02:00
|
|
|
expandConsole: PropTypes.func.isRequired,
|
2017-01-11 20:13:49 +01:00
|
|
|
clearConsole: PropTypes.func.isRequired
|
2016-07-18 01:06:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Console;
|