import { IconButton, Tab, Tabs } from '@material-ui/core'; import CheckBoxOutlineBlankIcon from '@material-ui/icons/CheckBoxOutlineBlank'; import CloseIcon from "@material-ui/icons/Close"; import { default as React, FunctionComponent, useCallback, useEffect, useMemo } from 'react'; type Props = { tabs: { label: string }[] currentTabIndex: number | undefined onCurrentTabIndexChanged: (i: number) => void onTabClosed: (i: number) => void } const TabWidgetTabBar: FunctionComponent = ({ tabs, currentTabIndex, onCurrentTabIndexChanged, onTabClosed }) => { useEffect(() => { if (currentTabIndex === undefined) { if (tabs.length > 0) { onCurrentTabIndexChanged(0) } } }, [currentTabIndex, onCurrentTabIndexChanged, tabs.length]) const handleClickTab = useCallback((index: number) => { onCurrentTabIndexChanged(index) }, [onCurrentTabIndexChanged]) const classes = ['ViewContainerTabBar'] const opts = useMemo(() => ( tabs.map((tab, i) => ( {selected: (i === currentTabIndex)} )) ), [tabs, currentTabIndex]) return ( {tabs.map((tab, i) => ( ))} ) } type TabProps = { tab: {label: string} tabIndex: number onClose: (i: number) => void opts: {selected?: boolean} onClick: (i: number) => void } const TabWidgetTab: FunctionComponent = ({tab, onClose, opts, onClick, tabIndex}) => { // thanks: https://stackoverflow.com/questions/63265780/react-material-ui-tabs-close/63277341#63277341 // thanks also: https://www.freecodecamp.org/news/reactjs-implement-drag-and-drop-feature-without-using-external-libraries-ad8994429f1a/ const icon = useMemo(() => (), []) const handleClick = useCallback(() => { onClick(tabIndex) }, [onClick, tabIndex]) const label = (
{e.dataTransfer.setData('viewId', view.viewId);}} onClick={handleClick} > {} {tab.label}   onClose(tabIndex)} className="CloseButton" style={{padding: 0}} >
) const style: React.CSSProperties = useMemo(() => (opts.selected ? {color: 'black', fontWeight: 'bold'} : {color: 'gray'}), [opts.selected]) return ( ) } export default TabWidgetTabBar