ocrcc-chatbox/src/components/widget.js

76 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-05-29 02:49:38 +00:00
import React, { Component } from 'react';
2018-05-26 18:53:54 +00:00
import PropTypes from 'prop-types';
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 = () => {
if (this.state.showDock) {
return (
<a className="dock" onClick={this.handleToggleOpen}>
^ OPEN ^
</a>
2018-05-26 18:53:54 +00:00
);
}
2018-05-29 02:49:38 +00:00
return '';
2018-05-28 01:09:44 +00:00
}
render() {
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">
<Transition in={this.state.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>
<a className="widget-header-icon" onClick={this.handleToggleOpen}>
X
</a>
</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>
);
}
}
Widget.propTypes = {};
export default Widget;