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';
|
2020-02-01 05:30:58 +00:00
|
|
|
import Chatbox from './chatbox';
|
2018-05-28 01:09:44 +00:00
|
|
|
import './widget.scss';
|
2018-05-26 18:53:54 +00:00
|
|
|
|
2018-05-29 02:49:38 +00:00
|
|
|
class Widget extends Component {
|
2020-02-01 05:30:58 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
opened: false,
|
|
|
|
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,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
render() {
|
2020-02-01 05:30:58 +00:00
|
|
|
const { opened, showDock } = this.state;
|
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}>
|
2020-02-01 05:30:58 +00:00
|
|
|
{(status) => (
|
2018-05-28 01:09:44 +00:00
|
|
|
<div className={`widget widget-${status}`}>
|
2020-02-01 05:30:58 +00:00
|
|
|
<Chatbox handleToggleOpen={this.handleToggleOpen} opened={opened} status={status} />
|
2018-05-28 01:09:44 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Transition>
|
2020-02-01 05:30:58 +00:00
|
|
|
{showDock && (
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="dock"
|
|
|
|
onClick={this.handleToggleOpen}
|
|
|
|
onKeyPress={this.handleToggleOpen}
|
|
|
|
>
|
|
|
|
<span>Open support chat</span>
|
|
|
|
<span className={`arrow ${opened ? 'opened' : 'closed'}`}>⌃</span>
|
|
|
|
</button>
|
|
|
|
)}
|
2018-05-26 18:53:54 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-20 17:26:02 +00:00
|
|
|
Widget.propTypes = {
|
|
|
|
};
|
|
|
|
|
|
|
|
Widget.defaultProps = {
|
|
|
|
};
|
|
|
|
|
2018-05-26 18:53:54 +00:00
|
|
|
export default Widget;
|