import * as React from 'react';
import { Panel } from './Panel';
/**
 * Used to set the panel title from another component's render method.
 *
 * For example:
 *
 * class MyComponent extends React.Component {
 *     public render(): React.ReactNode {
 *         return (
 *             <div>
 *                 <PanelTitlePortal>
 *                     <MyIcon /> My panel title
 *                 </PanelTitlePortal>
 *                 <h1>My component!</h1>
 *             </div>
 *         )
 *     }
 * }
 *
 * The icon and "My panel title" elements will be rendered as the panel's title.
 */
export class PanelTitlePortal extends React.PureComponent {
    componentDidMount() {
        this.subscription = Panel.setTitle(this.props.children);
    }
    componentDidUpdate(prevProps) {
        if (this.props.children !== prevProps.children) {
            if (this.subscription) {
                this.subscription.unsubscribe();
            }
            this.subscription = Panel.setTitle(this.props.children);
        }
    }
    componentWillUnmount() {
        if (this.subscription) {
            this.subscription.unsubscribe();
            this.subscription = undefined;
        }
    }
    forceUpdate(callBack) {
        super.forceUpdate(callBack);
        Panel.forceUpdate();
    }
    render() {
        return null; // the element is rendered in Panel, not here
    }
}
//# sourceMappingURL=PanelTitlePortal.js.map