2018-05-29 02:49:38 +00:00
|
|
|
import React, { Component } from 'react';
|
2018-05-28 01:09:44 +00:00
|
|
|
import { Transition } from 'react-transition-group';
|
|
|
|
import './widget.scss';
|
2018-05-26 18:53:54 +00:00
|
|
|
|
2018-05-29 02:49:38 +00:00
|
|
|
class Widget extends Component {
|
2018-05-26 18:53:54 +00:00
|
|
|
state = {
|
|
|
|
opened: false,
|
2018-05-28 01:09:44 +00:00
|
|
|
showDock: true,
|
2018-05-26 18:53:54 +00:00
|
|
|
}
|
|
|
|
|
2018-05-28 01:09:44 +00:00
|
|
|
handleToggleOpen = () => {
|
|
|
|
this.setState((prev) => {
|
2018-05-29 02:49:38 +00:00
|
|
|
let { showDock } = prev;
|
2018-05-28 01:09:44 +00:00
|
|
|
if (!prev.opened) {
|
|
|
|
showDock = false;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
showDock,
|
|
|
|
opened: !prev.opened,
|
|
|
|
};
|
|
|
|
});
|
2018-05-26 18:53:54 +00:00
|
|
|
}
|
|
|
|
|
2018-05-28 01:09:44 +00:00
|
|
|
handleWidgetExit = () => {
|
|
|
|
this.setState({
|
|
|
|
showDock: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
renderBody = () => {
|
2019-06-20 16:16:59 +00:00
|
|
|
const { showDock } = this.state;
|
|
|
|
|
|
|
|
if (!showDock) return '';
|
|
|
|
|
|
|
|
return (
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="dock"
|
|
|
|
onClick={this.handleToggleOpen}
|
|
|
|
onKeyPress={this.handleToggleOpen}
|
|
|
|
>
|
|
|
|
^ OPEN ^
|
|
|
|
</button>
|
|
|
|
);
|
2018-05-28 01:09:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-06-20 16:16:59 +00:00
|
|
|
const { opened } = this.state;
|
2018-05-29 02:49:38 +00:00
|
|
|
const body = this.renderBody();
|
2018-05-28 01:09:44 +00:00
|
|
|
|
2018-05-26 18:53:54 +00:00
|
|
|
return (
|
2018-05-28 01:09:44 +00:00
|
|
|
<div className="docked-widget">
|
2019-06-20 16:16:59 +00:00
|
|
|
<Transition in={opened} timeout={250} onExited={this.handleWidgetExit}>
|
2018-05-29 02:49:38 +00:00
|
|
|
{status => (
|
2018-05-28 01:09:44 +00:00
|
|
|
<div className={`widget widget-${status}`}>
|
|
|
|
<div className="widget-header">
|
|
|
|
<div className="widget-header-title">
|
|
|
|
Header
|
|
|
|
</div>
|
2019-06-20 16:16:59 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="widget-header-icon"
|
|
|
|
onClick={this.handleToggleOpen}
|
|
|
|
onKeyPress={this.handleToggleOpen}
|
|
|
|
>
|
2018-05-28 01:09:44 +00:00
|
|
|
X
|
2019-06-20 16:16:59 +00:00
|
|
|
</button>
|
2018-05-28 01:09:44 +00:00
|
|
|
</div>
|
|
|
|
<div className="widget-body">
|
|
|
|
Body
|
|
|
|
</div>
|
|
|
|
<div className="widget-footer">
|
|
|
|
Footer
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Transition>
|
2018-05-26 18:53:54 +00:00
|
|
|
{body}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Widget;
|