Skip to content

Build your personal knowledge base with Trilium Notes

feat(mobile): tint the workspace cards' icons, not their tiles

Elian Doranc283f1b6153b
diff --git a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.css b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.css
index 1ee791196d..e9abbf815c 100644
--- a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.css
+++ b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.css
@@ -56,12 +56,7 @@
place-items: center;
width: 52px;
height: 52px;
- border-radius: 14px;
font-size: 2.2em;
-
- .has-color & {
- background: var(--color);
- }
}
.mobile-navigator-workspace-title {
@@ -351,6 +346,7 @@
/* Colored notes: `--custom-color` is set by the theme on `.use-note-color`
(see css_class_manager.createClassForColor). Apply it to the title/icon. */
.mobile-navigator-unhoist.use-note-color,
+.mobile-navigator-workspace-icon.use-note-color,
.mobile-navigator-row.use-note-color .mobile-navigator-row-title,
.mobile-navigator-row.use-note-color .mobile-navigator-row-icon,
.mobile-navigator-current-tile.use-note-color .mobile-navigator-current-title,
diff --git a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.spec.tsx b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.spec.tsx
index 438dda6e0d..c9fea6044e 100644
--- a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.spec.tsx
+++ b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.spec.tsx
@@ -140,8 +140,11 @@ describe("TitleWithIndicators", () => {
describe("WorkspaceCards", () => {
it("lists the workspaces and enters the one tapped", async () => {
- const workspace = buildNote({ title: "Work", "#workspace": "", "#workspaceIconClass": "bx bx-briefcase" });
- const searchForNotes = vi.spyOn(search, "searchForNotes").mockResolvedValue([ workspace ]);
+ const workspace = buildNote({
+ title: "Work", "#workspace": "", "#workspaceIconClass": "bx bx-briefcase", "#workspaceTabBackgroundColor": "#1e3a8a"
+ });
+ const plain = buildNote({ title: "Plain", "#workspace": "" });
+ const searchForNotes = vi.spyOn(search, "searchForNotes").mockResolvedValue([ workspace, plain ]);
const onEnter = vi.fn();
const parent = {
componentId: "cid", registerHandler: () => {}, removeHandler: () => {}
@@ -161,9 +164,14 @@ describe("WorkspaceCards", () => {
expect(searchForNotes).toHaveBeenCalledWith("#workspace #!template");
expect(container.querySelector(".mobile-navigator-workspaces-label")?.textContent).toBe("mobile_note_navigator.workspaces");
const cards = [ ...container.querySelectorAll(".mobile-navigator-workspaces .mobile-navigator-workspace") ];
- expect(cards.map((card) => card.textContent)).toEqual([ "Work" ]);
+ expect(cards.map((card) => card.textContent)).toEqual([ "Work", "Plain" ]);
expect(cards[0]?.tagName).toBe("BUTTON");
- expect(cards[0]?.querySelector(".mobile-navigator-workspace-icon.bx-briefcase")).not.toBeNull();
+ // The workspace color tints the icon, with its lightness limited per theme, and fills nothing.
+ const icon = cards[0]?.querySelector(".mobile-navigator-workspace-icon.bx-briefcase");
+ expect(icon?.classList.contains("use-note-color")).toBe(true);
+ expect(icon?.classList.contains("color-1E3A8A")).toBe(true);
+ expect(icon?.getAttribute("style")).toBeNull();
+ expect(cards[1]?.querySelector(".mobile-navigator-workspace-icon")?.classList.contains("use-note-color")).toBe(false);
(cards[0] as HTMLElement | undefined)?.click();
expect(onEnter).toHaveBeenCalledWith(workspace.noteId);
diff --git a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.tsx b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.tsx
index 5b47f69e92..385a4637f3 100644
--- a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.tsx
+++ b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.tsx
@@ -8,7 +8,7 @@ import type Component from "../../components/component";
import type FNote from "../../entities/fnote";
import contextMenu from "../../menus/context_menu";
import { buildTreeContextMenuItems, handleTreeContextMenuSelect } from "../../menus/tree_context_menu";
-import cssClassManager, { getReadableTextColor } from "../../services/css_class_manager";
+import cssClassManager from "../../services/css_class_manager";
import froca from "../../services/froca";
import hoisted_note from "../../services/hoisted_note";
import { t } from "../../services/i18n";
@@ -614,27 +614,19 @@ function WorkspaceCard({ note, onClick }: { note: FNote, onClick: () => void })
const title = useNoteTitle(note.noteId, undefined);
return (
- <button
- type="button"
- className={clsx("mobile-navigator-workspace", { "has-color": !!workspaceColor })}
- onClick={onClick}
- >
+ <button type="button" className="mobile-navigator-workspace" onClick={onClick}>
<Icon
icon={workspaceIconClass || icon}
- className="mobile-navigator-workspace-icon"
- style={workspaceColorStyle(workspaceColor)}
+ className={clsx(
+ "mobile-navigator-workspace-icon",
+ cssClassManager.createClassForColor(workspaceColor ?? null)
+ )}
/>
<span className="mobile-navigator-workspace-title">{title ?? note.title}</span>
</button>
);
}
-/** Paints an element in the workspace's `#workspaceTabBackgroundColor`, with a text color readable on it. */
-function workspaceColorStyle(workspaceColor: string | null | undefined) {
- if (!workspaceColor) return undefined;
- return { "--color": workspaceColor, "color": getReadableTextColor(workspaceColor) } as Record<string, string>;
-}
-
interface NavigatorRowProps {
note: FNote;
parentNoteId: string | undefined;