// Copyright (C) The Arvados Authors. All rights reserved. // // SPDX-License-Identifier: AGPL-3.0 import React, { useEffect, useState } from 'react'; import { Tabs, Tab, List, ListItem, StyleRulesCallback, withStyles } from '@material-ui/core'; import { WithStyles } from '@material-ui/core'; import classNames from 'classnames'; import { ArvadosTheme } from 'common/custom-theme'; type TabbedListClasses = 'root' | 'tabs' | 'list'; const tabbedListStyles: StyleRulesCallback = (theme: ArvadosTheme) => ({ root: { overflowY: 'auto', }, tabs: { backgroundColor: theme.palette.background.paper, position: 'sticky', top: 0, zIndex: 1, borderBottom: '1px solid lightgrey', }, list: { overflowY: 'scroll', }, }); type SingleTabProps = { label: string; items: T[]; }; type TabPanelProps = { children: React.ReactNode; value: number; index: number; }; type TabbedListProps = { tabbedListContents: SingleTabProps[]; renderListItem?: (item: T) => React.ReactNode; injectedStyles?: string; keypress?: { key: string }; selectedIndex?: number; }; export const TabbedList = withStyles(tabbedListStyles)(({ tabbedListContents, renderListItem, selectedIndex, keypress, injectedStyles, classes }: TabbedListProps & WithStyles) => { const [tabNr, setTabNr] = useState(0); useEffect(() => { if (keypress) handleKeyPress(keypress.key); }, [keypress]); const handleKeyPress = (keypress: string) => { const numTabs = tabbedListContents.length; if (keypress === 'Tab') { setTabNr((tabNr + 1) % numTabs); } }; const handleTabChange = (event: React.SyntheticEvent, newValue: number) => { event.preventDefault(); setTabNr(newValue); }; return (
{tabbedListContents.map((tab) => ( ))}
{tabbedListContents[tabNr].items.map((item, i) => ( {renderListItem ? renderListItem(item) : JSON.stringify(item)} ))}
); }); const TabPanel = ({ children, value, index }: TabPanelProps) => { return ; };