import ko from "knockout";
import React, { useEffect, useRef, useState } from "react";
import loadingIcon from "../../../images/circular_loader_black_16x16.gif";
import errorIcon from "../../../images/close-black.svg";
import { useObservable } from "../../hooks/useObservable";
import TabsBase from "./TabsBase";
type Tab = TabsBase | (TabsBase & { render: () => JSX.Element });
export const Tabs = ({ tabs, activeTab }: { tabs: readonly Tab[]; activeTab: Tab }): JSX.Element => (
);
function TabNav({ tab, active }: { tab: Tab; active: boolean }) {
const [hovering, setHovering] = useState(false);
return (
setHovering(true)}
onMouseLeave={() => setHovering(false)}
onClick={() => tab.onTabClick()}
onKeyPress={({ nativeEvent: e }) => tab.onKeyPressActivate(undefined, e)}
className={active ? "active tabList" : "tabList"}
title={useObservable(tab.tabPath)}
aria-selected={active}
aria-expanded={active}
aria-controls={tab.tabId}
tabIndex={0}
role="tab"
>
{useObservable(tab.isExecutionError) && }
{useObservable(tab.isExecuting) && (
)}
{useObservable(tab.tabTitle)}
);
}
const CloseButton = ({ tab, active, hovering }: { tab: Tab; active: boolean; hovering: boolean }) => (
tab.onCloseTabButtonClick()}
tabIndex={active ? 0 : undefined}
onKeyPress={({ nativeEvent: e }) => tab.onKeyPressClose(undefined, e)}
>
);
const ErrorIcon = ({ tab, active }: { tab: Tab; active: boolean }) => (
tab.onErrorDetailsClick(undefined, e)}
onKeyPress={({ nativeEvent: e }) => tab.onErrorDetailsKeyPress(undefined, e)}
>
);
function TabPane({ tab, active }: { tab: Tab; active: boolean }) {
const ref = useRef();
const attrs = {
style: { display: active ? undefined : "none" },
className: "tabs-container",
};
useEffect((): (() => void) | void => {
const { current: element } = ref;
if (element) {
ko.applyBindings(tab, element);
const ctx = ko.contextFor(element).createChildContext(tab);
ko.applyBindingsToDescendants(ctx, element);
tab.isTemplateReady(true);
return () => ko.cleanNode(element);
}
}, [ref, tab]);
if ("render" in tab) {
return {tab.render()}
;
}
return ;
}