>({});
+
+ // Scroll to active tab.
+ useEffect(() => {
+ if (!shown || !activeNoteContext?.ntxId) return;
+ const correspondingEl = tabRefs.current[activeNoteContext.ntxId];
+ requestAnimationFrame(() => {
+ correspondingEl?.scrollIntoView();
+ });
+ }, [ activeNoteContext, shown ]);
return (
@@ -64,13 +82,15 @@ function TabBarModelContent({ selectTab }: {
noteContext={noteContext}
activeNtxId={activeNoteContext.ntxId}
selectTab={selectTab}
+ containerRef={el => (tabRefs.current[noteContext.ntxId ?? ""] = el)}
/>
))}
);
}
-function Tab({ noteContext, selectTab, activeNtxId }: {
+function Tab({ noteContext, containerRef, selectTab, activeNtxId }: {
+ containerRef: (el: HTMLDivElement | null) => void;
noteContext: NoteContext;
selectTab: (noteContextToActivate: NoteContext) => void;
activeNtxId: string | null | undefined;
@@ -78,15 +98,21 @@ function Tab({ noteContext, selectTab, activeNtxId }: {
const { note } = noteContext;
const iconClass = useNoteIcon(note);
const colorClass = note?.getColorClass() || '';
+ const workspaceTabBackgroundColorHue = getWorkspaceTabBackgroundColorHue(noteContext);
return (
selectTab(noteContext)}
+ style={{
+ "--bg-hue": workspaceTabBackgroundColorHue
+ }}
>
-
+
{noteContext.note?.title ?? t("tab_row.new_tab")}
@@ -102,6 +128,23 @@ function Tab({ noteContext, selectTab, activeNtxId }: {
);
}
+function getWorkspaceTabBackgroundColorHue(noteContext: NoteContext) {
+ if (!noteContext.hoistedNoteId) return;
+ const hoistedNote = froca.getNoteFromCache(noteContext.hoistedNoteId);
+ if (!hoistedNote) return;
+
+ const workspaceTabBackgroundColor = hoistedNote.getWorkspaceTabBackgroundColor();
+ if (!workspaceTabBackgroundColor) return;
+
+ try {
+ const parsedColor = parseColor(workspaceTabBackgroundColor);
+ if (!parsedColor) return;
+ return getHue(parsedColor);
+ } catch (e) {
+ // Colors are non-critical, simply ignore.
+ }
+}
+
function useMainNoteContexts() {
const [ noteContexts, setNoteContexts ] = useState(appContext.tabManager.getMainNoteContexts());