Files
parcer/src/components/molecules/BrowserTabs.tsx

145 lines
4.4 KiB
TypeScript
Raw Normal View History

2024-06-14 23:16:28 +05:30
import * as React from 'react';
import { Box, IconButton, Tab, Tabs } from "@mui/material";
import { useBrowserDimensionsStore } from "../../context/browserDimensions";
import { Close } from "@mui/icons-material";
2024-11-24 00:49:39 +05:30
import { useThemeMode } from '../../context/theme-provider';
2024-06-14 23:16:28 +05:30
interface BrowserTabsProp {
tabs: string[],
handleTabChange: (index: number) => void,
handleAddNewTab: () => void,
handleCloseTab: (index: number) => void,
handleChangeIndex: (index: number) => void;
tabIndex: number
}
export const BrowserTabs = (
{
tabs, handleTabChange, handleAddNewTab,
handleCloseTab, handleChangeIndex, tabIndex
}: BrowserTabsProp) => {
let tabWasClosed = false;
const { width } = useBrowserDimensionsStore();
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
if (!tabWasClosed) {
handleChangeIndex(newValue);
}
};
2024-11-24 00:49:39 +05:30
const isDarkMode = useThemeMode().darkMode;
2024-06-14 23:16:28 +05:30
return (
<Box sx={{
display: 'flex',
overflow: 'auto',
alignItems: 'center',
2024-11-24 00:49:39 +05:30
backgroundColor: `${isDarkMode? '#1e2124' : 'white'}`, // Dark background synced with BrowserNavbar
padding: '8px',
borderRadius: '8px 8px 0px 0px',
boxShadow: '0px 4px 10px rgba(0, 0, 0, 0.3)', // Synced shadow style
width: '900px', // Fixed width
2024-06-14 23:16:28 +05:30
}}>
2024-11-24 00:49:39 +05:30
<Box sx={{ borderColor: '#333' }}> {/* Synced border color */}
2024-06-14 23:16:28 +05:30
<Tabs
value={tabIndex}
onChange={handleChange}
2024-11-24 00:49:39 +05:30
variant="scrollable"
scrollButtons="auto"
sx={{
backgroundColor: `${isDarkMode? '#1e2124' : 'white'}`, // Dark background synced with BrowserNavbar
minHeight: '48px',
'& .MuiTabs-indicator': {
backgroundColor: '#ff00c3', // Synced subtle indicator color
height: '3px',
borderRadius: '3px 3px 0 0',
},
}}
2024-06-14 23:16:28 +05:30
>
{tabs.map((tab, index) => {
return (
<Tab
key={`tab-${index}`}
id={`tab-${index}`}
2024-10-19 04:23:22 +05:30
sx={{
2024-11-24 00:49:39 +05:30
backgroundColor: '#f5f5f5', // Synced dark background for tabs
borderRadius: '8px 8px 0px 0px',
marginRight: '8px',
minHeight: '48px',
textTransform: 'none',
fontWeight: '500',
fontSize: '14px',
color: 'black', // Synced light gray text color
'&.Mui-selected': {
backgroundColor:` ${isDarkMode?"#2a2a2a":"#f5f5f5"}`, // Synced selected tab color
color: '#ff00c3', // Slightly lighter text when selected
},
2024-10-19 04:23:08 +05:30
}}
2024-06-14 23:16:28 +05:30
icon={<CloseButton closeTab={() => {
tabWasClosed = true;
handleCloseTab(index);
}} disabled={tabs.length === 1}
/>}
iconPosition="end"
onClick={() => {
if (!tabWasClosed) {
handleTabChange(index)
}
2024-11-24 00:49:39 +05:30
}}
2024-06-14 23:16:28 +05:30
label={tab}
/>
);
})}
</Tabs>
</Box>
2024-11-24 00:49:39 +05:30
{/* <IconButton
aria-label="add tab"
onClick={handleAddNewTab}
sx={{
backgroundColor: '#2A2A2A', // Synced dark button background
color: '#CFCFCF', // Synced light text color
marginLeft: '8px',
'&:hover': { backgroundColor: '#3A3A3A' }, // Synced hover color
}}
>
+
</IconButton> */}
2024-06-14 23:16:28 +05:30
</Box>
);
}
interface CloseButtonProps {
closeTab: () => void;
disabled: boolean;
}
const CloseButton = ({ closeTab, disabled }: CloseButtonProps) => {
return (
<IconButton
aria-label="close"
size={"small"}
onClick={closeTab}
disabled={disabled}
2024-06-14 23:16:50 +05:30
sx={{
2024-11-24 00:49:39 +05:30
height: '28px',
width: '28px',
padding: '4px',
backgroundColor: '#3A3A3A', // Synced dark gray background
borderRadius: '50%',
'&:hover': {
backgroundColor: '#505050', // Synced hover color for close button
color: '#FFFFFF',
},
'&.Mui-disabled': {
opacity: 0.4, // Lower opacity for disabled state
},
transition: 'background-color 0.3s ease, color 0.3s ease',
2024-06-14 23:16:50 +05:30
}}
2024-06-14 23:16:28 +05:30
>
2024-11-24 00:49:39 +05:30
<Close fontSize="small" />
2024-06-14 23:16:28 +05:30
</IconButton>
);
}