import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { Transition } from 'react-transition-group'; import './widget.scss'; class Widget extends Component { state = { opened: false, showDock: true, } handleToggleOpen = () => { this.setState((prev) => { let { showDock } = prev; if (!prev.opened) { showDock = false; } return { showDock, opened: !prev.opened, }; }); } handleWidgetExit = () => { this.setState({ showDock: true, }); } renderBody = () => { const { showDock } = this.state; if (!showDock) return ''; return ( ); } render() { const { opened } = this.state; const body = this.renderBody(); const { bodyText, headerText, footerText } = this.props; return (
{status => (
{headerText}
{bodyText}
{footerText}
)}
{body}
); } } Widget.propTypes = { headerText: PropTypes.string, bodyText: PropTypes.string, footerText: PropTypes.string, }; Widget.defaultProps = { headerText: 'Header', bodyText: 'Body', footerText: 'Footer', }; export default Widget;