import {AbstractModal} from "tc-shared/ui/react-elements/modal/Definitions"; import React from "react"; import {joinClassList} from "tc-shared/ui/react-elements/Helper"; import TeaCupImage from "./TeaCup.png"; import {ErrorBoundary} from "tc-shared/ui/react-elements/ErrorBoundary"; import {ClientIcon} from "svg-sprites/client-icons"; import {ClientIconRenderer} from "tc-shared/ui/react-elements/Icons"; const cssStyle = require("./Renderer.scss"); export class ModalFrameTopRenderer extends React.PureComponent<{ modalInstance: AbstractModal, className?: string, onClose?: () => void, onPopout?: () => void, onMinimize?: () => void, replacePageTitle: boolean, }> { private readonly refTitle = React.createRef(); private titleElement: HTMLTitleElement; private observer: MutationObserver; componentDidMount() { if(this.props.replacePageTitle) { const titleElements = document.getElementsByTagName("title"); if(titleElements.length === 0) { this.titleElement = document.createElement("title"); document.head.appendChild(this.titleElement); } else { this.titleElement = titleElements[0]; } this.observer = new MutationObserver(() => this.updatePageTitle()); this.observer.observe(this.refTitle.current, { attributes: true, subtree: true, childList: true, characterData: true }); this.updatePageTitle(); } } componentWillUnmount() { this.observer?.disconnect(); this.observer = undefined; this.titleElement = undefined; } render() { const buttons = []; if(this.props.onMinimize) { buttons.push(
); } if(this.props.onPopout) { buttons.push(
); } if(this.props.onClose) { buttons.push(
); } return (
{""}
{this.props.modalInstance.renderTitle()}
{buttons}
); } private updatePageTitle() { if(!this.refTitle.current) { return; } this.titleElement.innerText = this.refTitle.current.textContent; } } export class ModalBodyRenderer extends React.PureComponent<{ modalInstance: AbstractModal, className?: string }> { constructor(props) { super(props); } render() { return (
{this.props.modalInstance.renderBody()}
) } } export class ModalFrameRenderer extends React.PureComponent<{ windowed: boolean, children: [React.ReactElement, React.ReactElement] }> { render() { return (
{this.props.children[0]} {this.props.children[1]}
); } } export class PageModalRenderer extends React.PureComponent<{ modalInstance: AbstractModal, onBackdropClicked: () => void, children: React.ReactElement }, { shown: boolean }> { constructor(props) { super(props); this.state = { shown: false }; } render() { return (
{ if(event.target !== event.currentTarget) { return; } this.props.onBackdropClicked(); }} >
{this.props.children}
); } } export const WindowModalRenderer = (props: { children: [React.ReactElement, React.ReactElement] }) => { return (
{props.children[0]} {props.children[1]}
); }