Skip to content

Build your personal knowledge base with Trilium Notes

feat(board): tint the "Move to" icons with the column's colour

Elian Doran817a5dac3516
diff --git a/apps/client/src/menus/context_menu.spec.ts b/apps/client/src/menus/context_menu.spec.ts
index b733c1c8e3..6020fbc580 100644
--- a/apps/client/src/menus/context_menu.spec.ts
+++ b/apps/client/src/menus/context_menu.spec.ts
@@ -60,6 +60,26 @@ describe("contextMenu", () => {
expect(menu?.parentElement).toBe(document.body);
});
+ it("tints an item's icon with the colour class it carries, and only the icon", async () => {
+ const menu = buildPage();
+ const contextMenu = await buildContextMenu();
+
+ await contextMenu.show({
+ x: 10,
+ y: 10,
+ selectMenuItemHandler: () => {},
+ items: [
+ { title: "To Do", uiIcon: "bx bx-list-ul", iconColorClass: "use-note-color color-e64d4d" },
+ { title: "Done", uiIcon: "bx bx-check" }
+ ]
+ });
+
+ const icons = [ ...menu?.querySelectorAll(".dropdown-item .tn-icon") ?? [] ];
+ expect(icons.map(icon => icon.classList.contains("use-note-color"))).toEqual([ true, false ]);
+ // The label sits beside the icon rather than inside it, so it keeps the menu's own colour.
+ expect(menu?.querySelectorAll(".dropdown-item .use-note-color")).toHaveLength(1);
+ });
+
it("says whether it is up, for a host whose own press would otherwise not know", async () => {
buildPage();
const contextMenu = await buildContextMenu();
diff --git a/apps/client/src/menus/context_menu.ts b/apps/client/src/menus/context_menu.ts
index b69ca4749f..88ce6c311d 100644
--- a/apps/client/src/menus/context_menu.ts
+++ b/apps/client/src/menus/context_menu.ts
@@ -47,6 +47,12 @@ export interface MenuCommandItem<T> {
* If not set, no icon is displayed and the item will appear shifted slightly to the left if there are other items with icons. To avoid this, use `bx bx-empty`.
*/
uiIcon?: string;
+ /**
+ * Classes tinting {@link uiIcon} with the colour of whatever the item stands for, as
+ * `cssClassManager.createClassForColor()` and `FNote#getColorClass()` return them. Only the
+ * icon is tinted, the label staying readable against the highlight.
+ */
+ iconColorClass?: string;
badges?: MenuItemBadge[];
templateNoteId?: string;
enabled?: boolean;
@@ -292,6 +298,9 @@ class ContextMenu {
const icon = (item.checked ? "bx bx-check" : item.uiIcon);
if (icon) {
$icon.addClass([icon, "tn-icon"]);
+ if (item.iconColorClass) {
+ $icon.addClass(item.iconColorClass);
+ }
} else {
$icon.append("&nbsp;");
}
diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.css
index e76784c967..9c1dd20559 100644
--- a/apps/client/src/stylesheets/style.css
+++ b/apps/client/src/stylesheets/style.css
@@ -593,6 +593,11 @@ body.mobile .dropdown .dropdown-submenu {
color: var(--dropdown-item-icon-destructive-color);
}
+.dropdown-item .tn-icon.use-note-color {
+ --menu-item-icon-color: var(--custom-color);
+ color: var(--custom-color, inherit);
+}
+
.dropdown-item > span:not([class]) {
width: 100%;
}
diff --git a/apps/client/src/widgets/collections/board/api.spec.ts b/apps/client/src/widgets/collections/board/api.spec.ts
index 9a3e794209..5e78805968 100644
--- a/apps/client/src/widgets/collections/board/api.spec.ts
+++ b/apps/client/src/widgets/collections/board/api.spec.ts
@@ -189,6 +189,15 @@ describe("BoardApi column mutations", () => {
expect(api.getColumnIcon(column.noteId)).toContain("bx bx-check");
});
+ it("reads back the colour a column carries as the classes that tint with it", async () => {
+ const { api } = createApi(
+ { columns: [ { value: "To Do", color: "#e64d4d" }, { value: "Done" } ] },
+ [ "To Do", "Done" ]);
+
+ expect(api.getColumnColorClass("To Do")).toContain("use-note-color");
+ expect(api.getColumnColorClass("Done")).toBe("");
+ });
+
it("stores a colour beside the icon, without either clearing the other", async () => {
const { api, saved } = createApi({ columns: [ { value: "To Do" } ] }, [ "To Do" ]);
diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.ts
index 5e9b53729f..bed9bb1857 100644
--- a/apps/client/src/widgets/collections/board/api.ts
+++ b/apps/client/src/widgets/collections/board/api.ts
@@ -5,6 +5,7 @@ import FNote from "../../../entities/fnote";
import attributes from "../../../services/attributes";
import branches from "../../../services/branches";
import { executeBulkActions } from "../../../services/bulk_action";
+import cssClassManager from "../../../services/css_class_manager";
import dialog from "../../../services/dialog";
import froca from "../../../services/froca";
import { t } from "../../../services/i18n";
@@ -238,6 +239,15 @@ export default class BoardApi {
?? DEFAULT_COLUMN_ICON;
}
+ /**
+ * The classes tinting anything that stands in for a column with the colour picked for it, empty
+ * while it carries none. The colour is stored per column in both modes, unlike the icon.
+ */
+ getColumnColorClass(column: string) {
+ const color = this.viewConfig?.columns?.find(col => col.value === column)?.color;
+ return cssClassManager.createClassForColor(color ?? null);
+ }
+
/** Whether a column is archived, which the board shows only while archived notes are shown. */
isColumnArchived(column: string) {
return !!this.viewConfig?.columns?.find(col => col.value === column)?.archived;
diff --git a/apps/client/src/widgets/collections/board/context_menu.spec.ts b/apps/client/src/widgets/collections/board/context_menu.spec.ts
index 21dff4cefb..ef617ef4e9 100644
--- a/apps/client/src/widgets/collections/board/context_menu.spec.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.spec.ts
@@ -230,6 +230,7 @@ describe("Board item context menu", () => {
columns: [ "To Do", "Done" ],
isColumnArchived: () => false,
getColumnIcon: () => DEFAULT_COLUMN_ICON,
+ getColumnColorClass: () => "",
changeColumn: vi.fn(async () => {})
} as unknown as BoardApi;
@@ -284,7 +285,8 @@ describe("Board item context menu", () => {
const api = {
columns: [ "To Do", "Done" ],
isColumnArchived: (column: string) => column === "Done",
- getColumnIcon: () => DEFAULT_COLUMN_ICON
+ getColumnIcon: () => DEFAULT_COLUMN_ICON,
+ getColumnColorClass: () => "",
} as unknown as BoardApi;
const moveTo = openItemMenu(api).find(item =>
@@ -298,12 +300,13 @@ describe("Board item context menu", () => {
.toEqual([ false, true ]);
});
- it("shows each column it offers to move a card to with the icon that column carries", () => {
+ it("shows each column it offers to move a card to with the icon and colour it carries", () => {
const api = {
columns: [ "To Do", "Done" ],
isColumnArchived: () => false,
getColumnIcon: (column: string) =>
- column === "Done" ? "bx bx-check-circle" : DEFAULT_COLUMN_ICON
+ column === "Done" ? "bx bx-check-circle" : DEFAULT_COLUMN_ICON,
+ getColumnColorClass: (column: string) => column === "Done" ? "use-note-color" : ""
} as unknown as BoardApi;
const moveTo = openItemMenu(api).find(item =>
@@ -312,5 +315,8 @@ describe("Board item context menu", () => {
expect((moveTo.items ?? []).map(item => item && "uiIcon" in item ? item.uiIcon : undefined))
.toEqual([ DEFAULT_COLUMN_ICON, "bx bx-check-circle" ]);
+ expect((moveTo.items ?? [])
+ .map(item => item && "iconColorClass" in item ? item.iconColorClass : undefined))
+ .toEqual([ "", "use-note-color" ]);
});
});
diff --git a/apps/client/src/widgets/collections/board/context_menu.ts b/apps/client/src/widgets/collections/board/context_menu.ts
index 1bdfa667f5..66a2b2e491 100644
--- a/apps/client/src/widgets/collections/board/context_menu.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.ts
@@ -150,6 +150,7 @@ export function openNoteContextMenu(api: Api, event: ContextMenuEvent, note: FNo
items: api.columns.map(columnToMoveTo => ({
title: columnToMoveTo,
uiIcon: api.getColumnIcon(columnToMoveTo),
+ iconColorClass: api.getColumnColorClass(columnToMoveTo),
enabled: columnToMoveTo !== column,
badges: api.isColumnArchived(columnToMoveTo)
? [ { title: t("board_view.archived-badge") } ]