1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { Tabs, Tab, List, ListItem, StyleRulesCallback, withStyles } from '@material-ui/core';
7 import { WithStyles } from '@material-ui/core';
8 import classNames from 'classnames';
9 import { ArvadosTheme } from 'common/custom-theme';
11 type TabbedListClasses = 'root' | 'tabs' | 'list';
13 const tabbedListStyles: StyleRulesCallback<TabbedListClasses> = (theme: ArvadosTheme) => ({
18 backgroundColor: theme.palette.background.paper,
22 borderBotton: '1px solid lightgrey'
29 type SingleTabProps = {
34 type TabbedListProps = {
35 tabbedListContents: SingleTabProps[];
36 renderListItem?: (item: any) => React.ReactNode;
37 injectedStyles?: string;
40 type TabPanelProps = {
41 children: React.ReactNode;
46 const TabPanel = ({ children, value, index }: TabPanelProps) => {
47 return <div hidden={value !== index}>{value === index && children}</div>;
50 export const TabbedList = withStyles(tabbedListStyles)(({ tabbedListContents, renderListItem, injectedStyles, classes }: TabbedListProps & WithStyles<TabbedListClasses>) => {
51 const [tabNr, setTabNr] = React.useState(0);
53 const handleChange = (event: React.SyntheticEvent, newValue: number) => {
54 event.preventDefault();
59 <div className={classNames(classes.root, injectedStyles)}>
60 <div className={classes.tabs}>
63 onChange={handleChange}
66 {tabbedListContents.map((tab) => (
67 <Tab label={tab.label} />
75 <List className={classes.list}>{tabbedListContents[tabNr].items.map((item) => (renderListItem ? renderListItem(item) : <ListItem>{item}</ListItem>))}</List>