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

97 lines
2.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 { AddButton } from "../atoms/buttons/AddButton";
import { useBrowserDimensionsStore } from "../../context/browserDimensions";
import { Close } from "@mui/icons-material";
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);
}
};
return (
<Box sx={{
2024-10-11 10:20:24 +05:30
width: 800,
2024-06-14 23:16:28 +05:30
display: 'flex',
overflow: 'auto',
alignItems: 'center',
}}>
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
<Tabs
value={tabIndex}
onChange={handleChange}
>
{tabs.map((tab, index) => {
return (
<Tab
key={`tab-${index}`}
id={`tab-${index}`}
2024-10-19 04:23:22 +05:30
sx={{
background: 'white',
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)
}
}
}
label={tab}
/>
);
})}
</Tabs>
</Box>
2024-10-19 04:23:22 +05:30
<AddButton handleClick={handleAddNewTab} style={{ background: 'white' }} />
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={{
height: '34px',
'&:hover': { color: 'white', backgroundColor: '#1976d2' }
}}
2024-06-14 23:16:28 +05:30
component="span"
>
2024-06-14 23:16:50 +05:30
<Close />
2024-06-14 23:16:28 +05:30
</IconButton>
);
}