From c5823bffd314c8b74bea947e2617c353e507c799 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Fri, 14 Jun 2024 23:16:28 +0530 Subject: [PATCH] feat: browser tabs --- src/components/molecules/BrowserTabs.tsx | 91 ++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/components/molecules/BrowserTabs.tsx diff --git a/src/components/molecules/BrowserTabs.tsx b/src/components/molecules/BrowserTabs.tsx new file mode 100644 index 00000000..8e2a6a9f --- /dev/null +++ b/src/components/molecules/BrowserTabs.tsx @@ -0,0 +1,91 @@ +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 ( + + + + {tabs.map((tab, index) => { + return ( + { + tabWasClosed = true; + handleCloseTab(index); + }} disabled={tabs.length === 1} + />} + iconPosition="end" + onClick={() => { + if (!tabWasClosed) { + handleTabChange(index) + } + } + } + label={tab} + /> + ); + })} + + + + + ); +} + +interface CloseButtonProps { + closeTab: () => void; + disabled: boolean; +} + +const CloseButton = ({ closeTab, disabled }: CloseButtonProps) => { + return ( + + + + ); +}