mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 10:55:55 +01:00
chore(react/ribbon): toggleable tabs
This commit is contained in:
@@ -63,41 +63,6 @@ export default class RibbonContainer extends NoteContextAwareWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleRibbonTab($ribbonTitle: JQuery<HTMLElement>, refreshActiveTab = true) {
|
|
||||||
const activate = !$ribbonTitle.hasClass("active");
|
|
||||||
|
|
||||||
this.$tabContainer.find(".ribbon-tab-title").removeClass("active");
|
|
||||||
this.$bodyContainer.find(".ribbon-body").removeClass("active");
|
|
||||||
|
|
||||||
if (activate) {
|
|
||||||
const ribbonComponendId = $ribbonTitle.attr("data-ribbon-component-id");
|
|
||||||
|
|
||||||
const wasAlreadyActive = this.lastActiveComponentId === ribbonComponendId;
|
|
||||||
|
|
||||||
this.lastActiveComponentId = ribbonComponendId;
|
|
||||||
|
|
||||||
this.$tabContainer.find(`.ribbon-tab-title[data-ribbon-component-id="${ribbonComponendId}"]`).addClass("active");
|
|
||||||
this.$bodyContainer.find(`.ribbon-body[data-ribbon-component-id="${ribbonComponendId}"]`).addClass("active");
|
|
||||||
|
|
||||||
const activeChild = this.getActiveRibbonWidget();
|
|
||||||
|
|
||||||
if (activeChild && (refreshActiveTab || !wasAlreadyActive) && this.noteContext && this.notePath) {
|
|
||||||
const handleEventPromise = activeChild.handleEvent("noteSwitched", { noteContext: this.noteContext, notePath: this.notePath });
|
|
||||||
|
|
||||||
if (refreshActiveTab) {
|
|
||||||
if (handleEventPromise) {
|
|
||||||
handleEventPromise.then(() => (activeChild as any).focus?.()); // TODO: Base class
|
|
||||||
} else {
|
|
||||||
// TODO: Base class
|
|
||||||
(activeChild as any).focus?.();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.lastActiveComponentId = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async noteSwitched() {
|
async noteSwitched() {
|
||||||
this.lastActiveComponentId = null;
|
this.lastActiveComponentId = null;
|
||||||
|
|
||||||
|
|||||||
@@ -256,15 +256,12 @@ export function useNoteContext() {
|
|||||||
setNotePath(noteContext.notePath);
|
setNotePath(noteContext.notePath);
|
||||||
});
|
});
|
||||||
useTriliumEventBeta("setNoteContext", ({ noteContext }) => {
|
useTriliumEventBeta("setNoteContext", ({ noteContext }) => {
|
||||||
console.log("Set note context", noteContext, noteContext.noteId);
|
|
||||||
setNoteContext(noteContext);
|
setNoteContext(noteContext);
|
||||||
});
|
});
|
||||||
useTriliumEventBeta("noteSwitchedAndActivated", ({ noteContext }) => {
|
useTriliumEventBeta("noteSwitchedAndActivated", ({ noteContext }) => {
|
||||||
console.log("Note switched and activated")
|
|
||||||
setNoteContext(noteContext);
|
setNoteContext(noteContext);
|
||||||
});
|
});
|
||||||
useTriliumEventBeta("noteSwitched", ({ noteContext, notePath }) => {
|
useTriliumEventBeta("noteSwitched", ({ noteContext, notePath }) => {
|
||||||
console.warn("Note switched", notePath);
|
|
||||||
setNotePath(notePath);
|
setNotePath(notePath);
|
||||||
});
|
});
|
||||||
useTriliumEventBeta("frocaReloaded", () => {
|
useTriliumEventBeta("frocaReloaded", () => {
|
||||||
|
|||||||
@@ -108,7 +108,14 @@ export default function Ribbon() {
|
|||||||
icon={icon}
|
icon={icon}
|
||||||
title={typeof title === "string" ? title : title(context)}
|
title={typeof title === "string" ? title : title(context)}
|
||||||
active={i === activeTab}
|
active={i === activeTab}
|
||||||
onClick={() => setActiveTab(i)}
|
onClick={() => {
|
||||||
|
if (activeTab !== i) {
|
||||||
|
setActiveTab(i);
|
||||||
|
} else {
|
||||||
|
// Collapse
|
||||||
|
setActiveTab(undefined);
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@@ -123,11 +130,13 @@ export default function Ribbon() {
|
|||||||
function RibbonTab({ icon, title, active, onClick }: { icon: string; title: string; active: boolean, onClick: () => void }) {
|
function RibbonTab({ icon, title, active, onClick }: { icon: string; title: string; active: boolean, onClick: () => void }) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={`ribbon-tab-title ${active ? "active" : ""}`}>
|
<div
|
||||||
|
className={`ribbon-tab-title ${active ? "active" : ""}`}
|
||||||
|
onClick={onClick}
|
||||||
|
>
|
||||||
<span
|
<span
|
||||||
className={`ribbon-tab-title-icon ${icon}`}
|
className={`ribbon-tab-title-icon ${icon}`}
|
||||||
title={title}
|
title={title}
|
||||||
onClick={onClick}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{ active && <span class="ribbon-tab-title-label">{title}</span> }
|
{ active && <span class="ribbon-tab-title-label">{title}</span> }
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
flex-basis: 24px;
|
flex-basis: 24px;
|
||||||
max-width: max-content;
|
max-width: max-content;
|
||||||
flex-grow: 10;
|
flex-grow: 10;
|
||||||
|
user-select: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ribbon-tab-title .bx {
|
.ribbon-tab-title .bx {
|
||||||
|
|||||||
Reference in New Issue
Block a user