Skip to content

Build your personal knowledge base with Trilium Notes

feat(web-clipper): give the popup's buttons Boxicons v3 icons

Elian Doranbc5a0d32f497
diff --git a/apps/web-clipper/assets/theme.css b/apps/web-clipper/assets/theme.css
index 081b665bf2..1dd725b357 100644
--- a/apps/web-clipper/assets/theme.css
+++ b/apps/web-clipper/assets/theme.css
@@ -1,4 +1,6 @@
-/* The Next theme's buttons, text boxes and check boxes, as the app draws them. */
+/* The Next theme's buttons, icon buttons, text boxes and check boxes, as the app draws them, in the
+ order the app loads them. */
+@import "@triliumnext/client/src/stylesheets/buttons.css";
@import "@triliumnext/client/src/stylesheets/theme-next/forms.css";
/* The app's own font file, matching the face in the client's `theme-next/base.css`. */
@@ -46,6 +48,16 @@
--radio-checkbox-hover-background: #0000004f;
--radio-checkbox-indicator-color: black;
+ --hover-item-background-color: #0000001a;
+ --hover-item-text-color: black;
+
+ --button-text-color: currentColor;
+ --icon-button-size: 32px;
+ --icon-button-icon-ratio: 0.65;
+ --icon-button-color: currentColor;
+ --icon-button-hover-background: var(--hover-item-background-color);
+ --icon-button-hover-color: var(--hover-item-text-color);
+
/* The log status colors, for the connection status. */
--status-ok-color: #32b323;
--status-warning-color: #b7bd10;
@@ -88,6 +100,9 @@
--radio-checkbox-hover-background: #ffffff61;
--radio-checkbox-indicator-color: white;
+ --hover-item-background-color: #ffffff16;
+ --hover-item-text-color: #efefef;
+
--status-ok-color: #74d369;
--status-warning-color: #d3c769;
--status-error-color: #d36969;
@@ -113,11 +128,41 @@ textarea {
font: inherit;
}
-button.btn {
+button.btn,
+button.icon-action {
cursor: pointer;
line-height: 1.5;
}
+/* The Boxicons drawn as inline SVG, sized and spaced as the app sizes and spaces its icon font. */
+svg.icon {
+ flex-shrink: 0;
+ width: 1em;
+ height: 1em;
+}
+
+button.btn > svg.icon {
+ width: 1.2em;
+ height: 1.2em;
+ margin-inline-end: 0.35em;
+ color: var(--cmd-button-icon-color);
+}
+
+button.icon-action {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+
+ > svg.icon {
+ width: calc(var(--icon-button-size) * var(--icon-button-icon-ratio));
+ height: calc(var(--icon-button-size) * var(--icon-button-icon-ratio));
+ }
+
+ &:active > svg.icon {
+ transform: scale(0.85);
+ }
+}
+
input[type="text"],
input[type="password"],
textarea {
diff --git a/apps/web-clipper/entrypoints/popup/main.tsx b/apps/web-clipper/entrypoints/popup/main.tsx
index e7a6de47e7..3c38a0f45d 100644
--- a/apps/web-clipper/entrypoints/popup/main.tsx
+++ b/apps/web-clipper/entrypoints/popup/main.tsx
@@ -1,6 +1,15 @@
import "@/assets/theme.css";
import "./popup.css";
+import type { IconData, IconDefinition } from "@boxicons/js";
+import Article from "@boxicons/js/icons/Article";
+import Cog from "@boxicons/js/icons/Cog";
+import Crop from "@boxicons/js/icons/Crop";
+import HelpCircle from "@boxicons/js/icons/HelpCircle";
+import Link from "@boxicons/js/icons/Link";
+import RefreshCw from "@boxicons/js/icons/RefreshCw";
+import Screenshot from "@boxicons/js/icons/Screenshot";
+import Tabs from "@boxicons/js/icons/Tabs";
import { render } from "preact";
import { useEffect, useRef, useState } from "preact/hooks";
@@ -64,8 +73,12 @@ export function Popup() {
<h3>Trilium Web Clipper</h3>
<div className="popup-header-buttons">
- <button className="btn btn-sm" onClick={() => browser.runtime.openOptionsPage()}>Options</button>
- <button className="btn btn-sm" onClick={() => window.open(HELP_URL, "_blank")}>Help</button>
+ <button className="icon-action" title="Options" aria-label="Options" onClick={() => browser.runtime.openOptionsPage()}>
+ <Icon icon={Cog} />
+ </button>
+ <button className="icon-action" title="Help" aria-label="Help" onClick={() => window.open(HELP_URL, "_blank")}>
+ <Icon icon={HelpCircle} />
+ </button>
</div>
</div>
@@ -86,18 +99,23 @@ export function Popup() {
<div className="capture-buttons">
<button className="btn btn-secondary" {...needsConnection} onClick={() => sendAndClose("save-cropped-screenshot")}>
+ <Icon icon={Crop} />
Crop screenshot
</button>
<button className="btn btn-secondary" {...needsConnection} onClick={() => sendAndClose("save-whole-screenshot")}>
+ <Icon icon={Screenshot} />
Save whole screenshot
</button>
<button className="btn btn-secondary" {...needsConnection} onClick={() => sendMessage({ name: "save-whole-page" })}>
+ <Icon icon={Article} />
Save whole page
</button>
<button className="btn btn-secondary" {...needsConnection} onClick={() => setIsWritingNote(true)}>
+ <Icon icon={Link} />
Save link with a note
</button>
<button className="btn btn-secondary" {...needsConnection} onClick={() => sendMessage({ name: "save-tabs" })}>
+ <Icon icon={Tabs} />
Save window's tabs as a list
</button>
</div>
@@ -107,8 +125,13 @@ export function Popup() {
<div className="connection">
<div>Status: <ConnectionStatus status={searchStatus} /></div>
- <button className="btn btn-sm" onClick={() => sendMessage({ name: "trigger-trilium-search" })}>
- check
+ <button
+ className="icon-action"
+ title="Check the connection again"
+ aria-label="Check the connection again"
+ onClick={() => sendMessage({ name: "trigger-trilium-search" })}
+ >
+ <Icon icon={RefreshCw} />
</button>
</div>
</div>
@@ -196,6 +219,29 @@ function ConnectionStatus({ status }: { status: TriliumSearchStatus | undefined
}
}
+/** A Boxicons v3 icon, drawn inline in the current text color. */
+function Icon({ icon }: { icon: IconDefinition }) {
+ const { viewBox, content } = basicIcon(icon);
+ return (
+ <svg
+ className="icon"
+ viewBox={viewBox}
+ fill="currentColor"
+ aria-hidden="true"
+ dangerouslySetInnerHTML={{ __html: content }}
+ />
+ );
+}
+
+/** The outlined variant of an icon, the one matching the app's Boxicons. */
+export function basicIcon(icon: IconDefinition): IconData {
+ const data = icon.packs.basic;
+ if (!data) {
+ throw new Error(`Boxicons has no basic variant of '${icon.name}'.`);
+ }
+ return data;
+}
+
/** A version mismatch counts as connected, so the buttons stay enabled and report it on use. */
function isConnected(status: TriliumSearchStatus) {
return status.status === "found-desktop" || status.status === "found-server" || status.status === "version-mismatch";
diff --git a/apps/web-clipper/entrypoints/popup/popup.css b/apps/web-clipper/entrypoints/popup/popup.css
index 4650332c57..e641b95fca 100644
--- a/apps/web-clipper/entrypoints/popup/popup.css
+++ b/apps/web-clipper/entrypoints/popup/popup.css
@@ -25,11 +25,6 @@ body {
gap: 4px;
}
- button.btn.btn-sm {
- min-width: unset;
- padding: 2px 10px;
- }
-
.already-visited:empty {
display: none;
}
@@ -40,6 +35,7 @@ body {
gap: 6px;
button.btn {
+ justify-content: flex-start;
width: 100%;
}
}
@@ -73,6 +69,7 @@ body {
padding-top: 10px;
border-top: 1px solid var(--main-border-color);
color: var(--muted-text-color);
+ --icon-button-size: 26px;
}
.status-ok {
diff --git a/apps/web-clipper/entrypoints/popup/popup.spec.tsx b/apps/web-clipper/entrypoints/popup/popup.spec.tsx
index 9830afea3d..ad3b93907a 100644
--- a/apps/web-clipper/entrypoints/popup/popup.spec.tsx
+++ b/apps/web-clipper/entrypoints/popup/popup.spec.tsx
@@ -3,7 +3,9 @@ import { act } from "preact/test-utils";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { fakeBrowser } from "wxt/testing/fake-browser";
-import { parseLinkNote, Popup, textToHtml } from "./main";
+import Crop from "@boxicons/js/icons/Crop";
+
+import { basicIcon, parseLinkNote, Popup, textToHtml } from "./main";
const sendMessage = vi.fn(async (_message: object): Promise<unknown> => undefined);
const openOptionsPage = vi.fn(async () => {});
@@ -100,7 +102,7 @@ describe("popup", () => {
expect(sendMessage).toHaveBeenCalledWith({ name: "save-whole-page" });
await click("Save window's tabs as a list");
expect(sendMessage).toHaveBeenCalledWith({ name: "save-tabs" });
- await click("check");
+ await click("Check the connection again");
expect(sendMessage).toHaveBeenCalledWith({ name: "trigger-trilium-search" });
await click("Options");
expect(openOptionsPage).toHaveBeenCalledOnce();
@@ -193,6 +195,33 @@ describe("popup", () => {
});
});
+describe("icons", () => {
+ it("draws each button's Boxicon inline, hidden from assistive technology", async () => {
+ vi.spyOn(console, "log").mockImplementation(() => {});
+ const container = document.createElement("div");
+ await act(() => render(<Popup />, container));
+
+ const icons = container.querySelectorAll("button > svg.icon");
+ expect(icons).toHaveLength(8);
+ for (const icon of icons) {
+ expect(icon.getAttribute("aria-hidden")).toBe("true");
+ expect(icon.getAttribute("viewBox")).toBe("0 0 24 24");
+ expect(icon.querySelector("path")).not.toBeNull();
+ }
+ for (const button of container.querySelectorAll("button.icon-action")) {
+ expect(button.getAttribute("aria-label")).toBe(button.getAttribute("title"));
+ }
+
+ await act(() => render(null, container));
+ });
+
+ it("uses the outlined variant, and refuses an icon that has none", () => {
+ expect(basicIcon(Crop)).toBe(Crop.packs.basic);
+ expect(() => basicIcon({ name: "brand", defaultPack: "brands", packs: {} }))
+ .toThrow("Boxicons has no basic variant of 'brand'.");
+ });
+});
+
describe("parseLinkNote", () => {
it("takes the first sentence or line as the title, unless the page title is kept", () => {
expect(parseLinkNote(" ", false)).toEqual({ title: "", content: "" });
@@ -216,8 +245,10 @@ async function receive(message: object) {
});
}
+/** Clicks the button with the given label, or with that `aria-label` when it shows only an icon. */
async function click(text: string) {
- const button = [ ...container.querySelectorAll("button") ].find((b) => b.textContent?.trim() === text);
+ const button = [ ...container.querySelectorAll("button") ]
+ .find((b) => b.textContent?.trim() === text || b.getAttribute("aria-label") === text);
expect(button, text).toBeDefined();
await act(() => button?.click());
}
diff --git a/apps/web-clipper/package.json b/apps/web-clipper/package.json
index 1c69d40dcf..a7d60332af 100644
--- a/apps/web-clipper/package.json
+++ b/apps/web-clipper/package.json
@@ -24,6 +24,7 @@
"wxt": "0.21.4"
},
"dependencies": {
+ "@boxicons/js": "1.0.1",
"preact": "11.0.0"
}
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index ab8aa031cf..dd08be64f8 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1024,6 +1024,9 @@ importers:
apps/web-clipper:
dependencies:
+ '@boxicons/js':
+ specifier: 1.0.1
+ version: 1.0.1
preact:
specifier: 11.0.0
version: 11.0.0([email protected])
@@ -1788,6 +1791,9 @@ packages:
'@borewit/[email protected]':
resolution: {integrity: sha512-DDaRehssg1aNrH4+2hnj1B7vnUGEjU6OIlyRdkMd0aUdIUvKXrJfXsy8LVtXAy7DRvYVluWbMspsRhz2lcW0mQ==}
+ '@boxicons/[email protected]':
+ resolution: {integrity: sha512-DY4Z4uggmU+iKVcgQBvTK05AtbRweMa3mWLLoPnWhjH7DWPeCdI9It7rHNEi3RlI0YQqWu6WCfo5aC7oETIWng==}
+
'@braintree/[email protected]':
resolution: {integrity: sha512-Tbsj02wXCbqGmzdnXNk0SOF19ChhRU70BsroIi4Pm6Ehp56in6vch94mfbdQ17DozxkL3BAVjbZ4Qc1a0HFRAg==}
@@ -12144,6 +12150,8 @@ snapshots:
'@borewit/[email protected]': {}
+ '@boxicons/[email protected]': {}
+
'@braintree/[email protected]': {}
'@braintree/[email protected]': {}