Skip to content

Commit

Permalink
fix: add any custom classes to menus and sub-menus
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgurney committed Jan 7, 2025
1 parent 5e927e4 commit 70563ae
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,10 @@ export default class NoteToolbarPlugin extends Plugin {
// add class so we can style the menu
menu.dom.addClass('note-toolbar-menu');

// apply custom classes to the sub-menu by getting the note's toolbar
const activeToolbar = this.getCurrentToolbar();
if (activeToolbar && activeToolbar.customClasses) menu.dom.addClasses([...activeToolbar.customClasses.split(' ')]);

return menu;

}
Expand Down Expand Up @@ -728,8 +732,10 @@ export default class NoteToolbarPlugin extends Plugin {
let subMenu = item.setSubmenu() as Menu;
// add class so we can style the menu
subMenu.dom.addClass('note-toolbar-menu');
// FIXME: this is not the parent toolbar
// toolbar.customClasses && subMenu.dom.addClasses([...toolbar.customClasses.split(' ')]);
// apply custom classes to the sub-menu by getting the note's toolbar
const activeToolbar = this.getCurrentToolbar();
if (activeToolbar && activeToolbar.customClasses) subMenu.dom.addClasses([...activeToolbar.customClasses.split(' ')]);
// render the sub-menu items
let menuToolbar = this.settingsManager.getToolbarById(toolbarItem.link);
menuToolbar ? this.renderMenuItems(subMenu, menuToolbar, file, recursions + 1) : undefined;
});
Expand Down Expand Up @@ -1611,7 +1617,6 @@ export default class NoteToolbarPlugin extends Plugin {

/**
* Get the toolbar element, in the current view.
* @param positionsToCheck
* @returns HTMLElement or null, if it doesn't exist.
*/
getToolbarEl(): HTMLElement | null {
Expand Down Expand Up @@ -1762,6 +1767,16 @@ export default class NoteToolbarPlugin extends Plugin {
return adapter;
}

/**
* Gets the settings for the toolbar in the current view.
* @returns ToolbarSettings for the current toolbar, or undefined if it doesn't exist.
*/
getCurrentToolbar(): ToolbarSettings | undefined {
const noteToolbarEl = this.getToolbarEl();
const noteToolbarSettings = noteToolbarEl ? this.settingsManager.getToolbarById(noteToolbarEl?.id) : undefined;
return noteToolbarSettings;
}

/**
* Check if a string has vars {{ }} or expressions (Dataview or Templater)
* @param s The string to check.
Expand Down

0 comments on commit 70563ae

Please sign in to comment.