2016-08-15 23:06:12 +02:00
|
|
|
import React, { PropTypes } from 'react';
|
2017-07-11 17:37:43 +02:00
|
|
|
import InlineSVG from 'react-inlinesvg';
|
|
|
|
import { browserHistory } from 'react-router';
|
2016-08-15 23:06:12 +02:00
|
|
|
|
2017-07-11 17:37:43 +02:00
|
|
|
const exitUrl = require('../../../images/exit.svg');
|
|
|
|
|
|
|
|
class Overlay extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.close = this.close.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.overlay.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
close() {
|
|
|
|
if (!this.props.closeOverlay) {
|
|
|
|
browserHistory.push(this.props.previousPath);
|
|
|
|
} else {
|
|
|
|
this.props.closeOverlay();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
ariaLabel,
|
|
|
|
title,
|
|
|
|
children
|
|
|
|
} = this.props;
|
|
|
|
return (
|
|
|
|
<div className="overlay">
|
|
|
|
<div className="overlay__content">
|
|
|
|
<section
|
|
|
|
tabIndex="0"
|
|
|
|
role="main"
|
|
|
|
aria-label={ariaLabel}
|
|
|
|
ref={(element) => { this.overlay = element; }}
|
|
|
|
className="overlay__body"
|
|
|
|
>
|
|
|
|
<header className="overlay__header">
|
|
|
|
<h2 className="overlay__title">{title}</h2>
|
|
|
|
<button className="overlay__close-button" onClick={this.close}>
|
|
|
|
<InlineSVG src={exitUrl} alt="close overlay" />
|
|
|
|
</button>
|
|
|
|
</header>
|
|
|
|
{children}
|
|
|
|
</section>
|
|
|
|
</div>
|
2016-08-15 23:06:12 +02:00
|
|
|
</div>
|
2017-07-11 17:37:43 +02:00
|
|
|
);
|
|
|
|
}
|
2016-08-15 23:06:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Overlay.propTypes = {
|
2017-07-11 17:37:43 +02:00
|
|
|
children: PropTypes.element,
|
|
|
|
closeOverlay: PropTypes.func,
|
|
|
|
title: PropTypes.string,
|
|
|
|
ariaLabel: PropTypes.string,
|
2017-09-14 20:51:36 +02:00
|
|
|
previousPath: PropTypes.string
|
2017-02-22 20:29:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Overlay.defaultProps = {
|
2017-07-11 17:37:43 +02:00
|
|
|
children: null,
|
|
|
|
title: 'Modal',
|
|
|
|
closeOverlay: null,
|
2017-09-14 20:51:36 +02:00
|
|
|
ariaLabel: 'modal',
|
|
|
|
previousPath: '/'
|
2016-08-15 23:06:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Overlay;
|