Skip to content

Commit 94a030c

Browse files
authored
SW-6812: Add Deliverables tab to Project Profile in Console (#661)
SW-6812: Add Deliverables tab to Project Profile in Console (#661)
1 parent b1b78a6 commit 94a030c

File tree

1 file changed

+45
-40
lines changed

1 file changed

+45
-40
lines changed

src/components/Tabs/index.tsx

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,62 @@
1-
import React, { useEffect, useState } from 'react';
21
import { TabContext, TabList, TabPanel } from '@mui/lab';
3-
import { Box, Tab as MuiTab, useTheme } from '@mui/material';
2+
import { Box, Tab as MuiTab, SxProps, Theme, useTheme } from '@mui/material';
3+
import React, { useEffect, useState } from 'react';
4+
45
import { useDeviceInfo } from '../../utils';
56
import Icon from '../Icon/Icon';
67
import { IconName } from '../Icon/icons';
78

89
export type Tab = {
10+
children: React.ReactNode;
11+
disabled?: boolean;
912
icon?: IconName;
1013
id: string;
1114
label: string;
12-
children: React.ReactNode;
13-
disabled?: boolean;
1415
};
1516

1617
export type TabsProps = {
17-
tabs: Tab[];
18-
onTabChange?: (tab: string) => void;
1918
activeTab?: string;
19+
onTabChange?: (tab: string) => void;
20+
tabs: Tab[];
21+
tabStyle?: SxProps<Theme>;
2022
};
2123

22-
const Tabs = ({ tabs, onTabChange, activeTab }: TabsProps): JSX.Element => {
24+
const Tabs = ({ activeTab, onTabChange, tabs, tabStyle }: TabsProps): JSX.Element => {
2325
const [selectedTab, setSelectedTab] = useState<string>(activeTab ?? tabs[0]?.id ?? '');
2426
const theme = useTheme();
2527
const { isMobile } = useDeviceInfo();
2628

27-
const tabStyles = {
28-
color: theme.palette.TwClrTxtSecondary as string,
29-
fontSize: '16px',
30-
fontWeight: 600,
31-
lineHeight: '24px',
32-
padding: theme.spacing(1, 2),
33-
minHeight: theme.spacing(4.5),
34-
textTransform: 'capitalize',
35-
'&:hover': {
36-
backgroundColor: theme.palette.TwClrBgHover as string,
37-
},
38-
'&.Mui-selected': {
39-
color: theme.palette.TwClrTxtBrand as string,
40-
},
41-
'&.MuiTab-labelIcon': {
42-
display: 'flex',
43-
flexDirection: 'row',
44-
alignItems: 'center',
29+
const tabStyles = [
30+
{
31+
color: theme.palette.TwClrTxtSecondary as string,
32+
fontSize: '16px',
33+
fontWeight: 600,
34+
lineHeight: '24px',
35+
minHeight: theme.spacing(4.5),
36+
padding: theme.spacing(1, 2),
37+
textTransform: 'capitalize',
38+
'&:hover': {
39+
backgroundColor: theme.palette.TwClrBgHover as string,
40+
},
41+
'&.Mui-selected': {
42+
color: theme.palette.TwClrTxtBrand as string,
43+
},
44+
'&.MuiTab-labelIcon': {
45+
alignItems: 'center',
46+
display: 'flex',
47+
flexDirection: 'row',
48+
},
49+
'& .MuiTab-iconWrapper': {
50+
fill: theme.palette.TwClrIcnSecondary as string,
51+
marginBottom: 0,
52+
marginRight: theme.spacing(1),
53+
},
54+
'&.Mui-selected .MuiTab-iconWrapper': {
55+
fill: theme.palette.TwClrIcnBrand as string,
56+
},
4557
},
46-
'& .MuiTab-iconWrapper': {
47-
fill: theme.palette.TwClrIcnSecondary as string,
48-
marginBottom: 0,
49-
marginRight: theme.spacing(1),
50-
},
51-
'&.Mui-selected .MuiTab-iconWrapper': {
52-
fill: theme.palette.TwClrIcnBrand as string,
53-
},
54-
};
58+
...(Array.isArray(tabStyle) ? tabStyle : [tabStyle]),
59+
];
5560

5661
const tabHeaderProps = {
5762
borderBottom: 1,
@@ -82,30 +87,30 @@ const Tabs = ({ tabs, onTabChange, activeTab }: TabsProps): JSX.Element => {
8287
<TabContext value={selectedTab}>
8388
<Box sx={tabHeaderProps}>
8489
<TabList
85-
variant='scrollable'
86-
sx={{ minHeight: theme.spacing(4.5) }}
8790
onChange={(unused, value: string) => setTab(value)}
91+
sx={{ minHeight: theme.spacing(4.5) }}
8892
TabIndicatorProps={{
8993
style: {
9094
background: theme.palette.TwClrBgBrand,
9195
height: '4px',
9296
},
9397
}}
98+
variant='scrollable'
9499
>
95100
{tabs.map((tab, index) => (
96101
<MuiTab
102+
disabled={tab.disabled}
97103
icon={tab.icon ? <Icon name={tab.icon} /> : undefined}
104+
key={index}
98105
label={tab.label}
99-
value={tab.id}
100106
sx={tabStyles}
101-
key={index}
102-
disabled={tab.disabled}
107+
value={tab.id}
103108
/>
104109
))}
105110
</TabList>
106111
</Box>
107112
{tabs.map((tab, index) => (
108-
<TabPanel value={tab.id} key={index} sx={tabPanelStyles}>
113+
<TabPanel key={index} sx={tabPanelStyles} value={tab.id}>
109114
{tab.children}
110115
</TabPanel>
111116
))}

0 commit comments

Comments
 (0)