client/context menus: add support to display badges for menu items

This commit is contained in:
Adorian Doran 2025-07-03 23:27:02 +03:00
parent 38114bddb9
commit 0a06c60cb7

View File

@ -17,11 +17,17 @@ interface MenuSeparatorItem {
title: "----"; title: "----";
} }
interface MenuItemBadge {
title: string;
className?: string;
}
export interface MenuCommandItem<T> { export interface MenuCommandItem<T> {
title: string; title: string;
command?: T; command?: T;
type?: string; type?: string;
uiIcon?: string; uiIcon?: string;
badges?: MenuItemBadge[];
templateNoteId?: string; templateNoteId?: string;
enabled?: boolean; enabled?: boolean;
handler?: MenuHandler<T>; handler?: MenuHandler<T>;
@ -157,6 +163,18 @@ class ContextMenu {
.append(" &nbsp; ") // some space between icon and text .append(" &nbsp; ") // some space between icon and text
.append(item.title); .append(item.title);
if ("badges" in item && item.badges) {
for (let badge of item.badges) {
const badgeElement = $(`<span class="badge">`).text(badge.title);
if (badge.className) {
badgeElement.addClass(badge.className);
}
$link.append(badgeElement);
}
}
if ("shortcut" in item && item.shortcut) { if ("shortcut" in item && item.shortcut) {
$link.append($("<kbd>").text(item.shortcut)); $link.append($("<kbd>").text(item.shortcut));
} }