1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React, { ReactElement, useEffect, useState } from "react";
6 import { Tabs, Tab } from "@material-ui/core";
7 import { TabsProps } from "@material-ui/core/Tabs";
9 interface ComponentWithHidden {
13 export type TabData = {
16 content: ReactElement<ComponentWithHidden>;
19 type ConditionalTabsProps = {
23 export const ConditionalTabs = (props: Omit<TabsProps, 'value' | 'onChange'> & ConditionalTabsProps) => {
24 const [tabState, setTabState] = useState(0);
25 const visibleTabs = props.tabs.filter(tab => tab.show);
26 const visibleTabNames = visibleTabs.map(tab => tab.label).join();
28 const handleTabChange = (event: React.MouseEvent<HTMLElement>, value: number) => {
32 // Reset tab to 0 when tab visibility changes
33 // (or if tab set change causes visible set to change)
36 }, [visibleTabNames]);
42 onChange={handleTabChange} >
43 {visibleTabs.map(tab => <Tab key={tab.label} label={tab.label} />)}
46 {visibleTabs.map((tab, i) => (
47 React.cloneElement(tab.content, {key: i, hidden: i !== tabState})