refactor showing/hiding of separator for hover and active states

This commit is contained in:
Red Adaya 2024-12-09 14:36:48 +08:00
parent 88b110a424
commit 76ec792fe5
3 changed files with 26 additions and 15 deletions

View File

@ -49,11 +49,6 @@
.name { .name {
color: var(--main-text-color); color: var(--main-text-color);
} }
& + .tab .separator,
.separator {
opacity: 0;
}
} }
.name { .name {
@ -102,11 +97,6 @@
// Only apply hover effects when not in nohover mode. This prevents the previously-hovered tab from remaining hovered while a tab view is not mounted. // Only apply hover effects when not in nohover mode. This prevents the previously-hovered tab from remaining hovered while a tab view is not mounted.
body:not(.nohover) .tab:hover { body:not(.nohover) .tab:hover {
& + .tab::after,
&::after {
content: none;
}
.tab-inner { .tab-inner {
border-color: transparent; border-color: transparent;
background: rgb(from var(--main-text-color) r g b / 0.07); background: rgb(from var(--main-text-color) r g b / 0.07);

View File

@ -24,6 +24,7 @@ interface TabProps {
isNew: boolean; isNew: boolean;
isPinned: boolean; isPinned: boolean;
tabIds: string[]; tabIds: string[];
tabRefs: React.MutableRefObject<React.RefObject<HTMLDivElement>[]>;
onClick: () => void; onClick: () => void;
onClose: (event: React.MouseEvent<HTMLButtonElement, MouseEvent> | null) => void; onClose: (event: React.MouseEvent<HTMLButtonElement, MouseEvent> | null) => void;
onMouseDown: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void; onMouseDown: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
@ -46,6 +47,7 @@ const Tab = memo(
tabWidth, tabWidth,
isNew, isNew,
tabIds, tabIds,
tabRefs,
onLoaded, onLoaded,
onClick, onClick,
onClose, onClose,
@ -202,15 +204,33 @@ const Tab = memo(
const showSeparator = useCallback( const showSeparator = useCallback(
(id) => { (id) => {
// if (isFirst) return false;
const idx = tabIds.indexOf(id); const idx = tabIds.indexOf(id);
const found = tabIndicesMoved.find((i, ii) => ii !== 0 && i === idx) === undefined; const found = tabIndicesMoved.find((i, ii) => ii !== 0 && i === idx);
return found; console.log("id**********", id);
if (found) {
console.log("found=====", tabIds[found]);
console.log("tabIndicesMoved", tabIndicesMoved);
return false;
}
return true;
}, },
[isFirst, tabIndicesMoved] [isFirst, tabIndicesMoved]
); );
useEffect(() => {
if (!isActive) return;
const idx = tabIds.indexOf(id);
const targetIds = [tabIds[idx], tabIds[idx + 1]];
tabRefs.current.forEach((ref) => {
const separator = ref.current.querySelector(".separator") as HTMLElement;
if (!separator) return;
separator.style.opacity = targetIds.includes(ref.current.dataset.tabId) ? "0" : "1";
});
}, [id, isActive, tabIds, tabIndicesMoved]);
return ( return (
<div <div
ref={tabRef} ref={tabRef}
@ -239,7 +259,7 @@ const Tab = memo(
suppressContentEditableWarning={true} suppressContentEditableWarning={true}
> >
{tabData?.name} {tabData?.name}
{/* {id.substring(id.length - 3)} */} {id.substring(id.length - 3)}
</div> </div>
{isPinned ? ( {isPinned ? (
<Button <Button

View File

@ -668,6 +668,7 @@ const TabBar = memo(({ workspace }: TabBarProps) => {
tabIds={tabIds} tabIds={tabIds}
onMouseEnter={() => handleMouseEnterTab(index)} onMouseEnter={() => handleMouseEnterTab(index)}
onMouseLeave={() => handleMouseLeaveTab(index)} onMouseLeave={() => handleMouseLeaveTab(index)}
tabRefs={tabRefs}
/> />
); );
})} })}