1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/dashboard/client/components/dock/terminal-window.tsx
Jari Kolehmainen 1d0815abd2
Lens app source code (#119)
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
2020-03-15 09:52:02 +02:00

46 lines
1.1 KiB
TypeScript

import "./terminal-window.scss";
import React from "react";
import { reaction } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react";
import { cssNames } from "../../utils";
import { IDockTab } from "./dock.store";
import { Terminal } from "./terminal";
import { terminalStore } from "./terminal.store";
import { themeStore } from "../../theme.store";
interface Props {
className?: string;
tab: IDockTab;
}
@observer
export class TerminalWindow extends React.Component<Props> {
public elem: HTMLElement;
public terminal: Terminal;
componentDidMount() {
disposeOnUnmount(this, [
reaction(() => this.props.tab.id, tabId => this.activate(tabId), {
fireImmediately: true
})
])
}
activate(tabId = this.props.tab.id) {
if (this.terminal) this.terminal.detach(); // detach previous
this.terminal = terminalStore.getTerminal(tabId);
this.terminal.attachTo(this.elem);
}
render() {
const { className } = this.props;
return (
<div
className={cssNames("TerminalWindow", className, themeStore.activeTheme.type)}
ref={e => this.elem = e}
/>
)
}
}