Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(fonts): preview the interface font on the interface
Elian Doranb4d1666c8cd8
diff --git a/apps/client/src/widgets/type_widgets/options/appearance_fonts.css b/apps/client/src/widgets/type_widgets/options/appearance_fonts.cssindex 948ffecbc3..6372e8b6a7 100644--- a/apps/client/src/widgets/type_widgets/options/appearance_fonts.css+++ b/apps/client/src/widgets/type_widgets/options/appearance_fonts.css@@ -183,6 +183,24 @@ pre.font-preview-code {padding: 0;}+.font-preview-interface {+ display: flex;+ flex-direction: column;+ align-items: flex-start;+ gap: 16px;++ /* The menu is a specimen, so it takes the room its entries need rather than the width it would+ have as a dropdown. */+ .dropdownWrapper {+ max-width: 100%;+ }++ .font-preview-interface-buttons {+ display: flex;+ gap: 8px;+ }+}+/* Sized in em, so the heading keeps its proportion to the text under it as the slider moves. */.font-preview-document {h3 {diff --git a/apps/client/src/widgets/type_widgets/options/appearance_fonts.spec.tsx b/apps/client/src/widgets/type_widgets/options/appearance_fonts.spec.tsxindex 515eb6c0b7..5a3e956b8c 100644--- a/apps/client/src/widgets/type_widgets/options/appearance_fonts.spec.tsx+++ b/apps/client/src/widgets/type_widgets/options/appearance_fonts.spec.tsx@@ -334,6 +334,22 @@ describe("the font settings", () => {expect(catalogue.fonts.document_preview_body).toContain("<em>");});+ it("shows the interface on the components the interface is made of", async () => {+ // The picker opens on the interface font, so this is what it lands on.+ await openPicker();++ // Real menu entries, a real shortcut and a real button rather than markup standing in for+ // them: what is previewed cannot then drift from what it previews.+ const preview = document.querySelector(".font-preview-interface");+ expect(preview?.querySelectorAll(".dropdown-item")).toHaveLength(3);+ expect(preview?.querySelector("kbd")).not.toBeNull();+ expect(preview?.querySelectorAll(".font-preview-interface-buttons button")).toHaveLength(2);++ // A specimen rather than a menu: one that answered to being pressed would have to be+ // worked out as not being one.+ expect(preview?.hasAttribute("inert")).toBe(true);+ });+it("shows the code sample on a surface the ligature setting reaches", async () => {await openPicker();await act(async () => pickerTargets()[3].click());diff --git a/apps/client/src/widgets/type_widgets/options/appearance_fonts.tsx b/apps/client/src/widgets/type_widgets/options/appearance_fonts.tsxindex 53442aa3d4..79f7c9b779 100644--- a/apps/client/src/widgets/type_widgets/options/appearance_fonts.tsx+++ b/apps/client/src/widgets/type_widgets/options/appearance_fonts.tsx@@ -12,6 +12,7 @@ import { getCustomFonts, registerFontNote } from "../../../services/custom_fontsimport { filterAvailableFamilies, listSystemFonts, quoteFamily, type SystemFont } from "../../../services/font";import { t } from "../../../services/i18n";import { isElectron } from "../../../services/utils";+import Button from "../../react/Button";import { Card, OptionCardSection } from "../../react/Card";import { filterTokens, matchesFilter } from "../../react/filter";import FormList, { FormListHeader, FormListItem } from "../../react/FormList";@@ -21,6 +22,7 @@ import Icon from "../../react/Icon";import Modal from "../../react/Modal";import NoItems from "../../react/NoItems";import SegmentedChoice from "../../react/SegmentedChoice";+import { renderShortcutKbds } from "../../react/shortcut_kbd";import Slider from "../../react/Slider";import SettingsSearch from "./components/SettingsSearch";@@ -100,7 +102,8 @@ const FONT_TARGETS: FontTarget[] = [key: "main",label: t("fonts.main_font"),shortLabel: t("fonts.main_font_short"),- themeVariable: "var(--main-font-family)"+ themeVariable: "var(--main-font-family)",+ Preview: InterfacePreview},{key: "tree",@@ -477,6 +480,37 @@ function DocumentPreview() {);}+/**+ * A menu and the buttons under it, built from the components the interface is built from rather+ * than mocked up, so what is previewed cannot drift from what it previews. The font is set for the+ * small text beside an icon, the shortcut in its `kbd`, and the label on a button — none of which a+ * line of specimen text stands in for.+ *+ * The labels are entries that already exist elsewhere in the interface, which is both what makes+ * them realistic and what keeps them from costing the catalogue anything.+ */+function InterfacePreview() {+ return (+ // Inert: a specimen of the interface rather than any part of it, and a menu that answered+ // to being pressed would be a menu the user has to work out is not one.+ <div className="font-preview-interface" inert>+ <FormList>+ <FormListItem icon="bx bx-link-external">+ {t("tree-context-menu.open-in-a-new-tab")}+ <span className="keyboard-shortcut">{renderShortcutKbds("CommandOrControl+Enter")}</span>+ </FormListItem>+ <FormListItem icon="bx bx-dock-right">{t("tree-context-menu.open-in-a-new-split")}</FormListItem>+ <FormListItem icon="bx bx-trash" disabled>{t("tree-context-menu.delete")}</FormListItem>+ </FormList>++ <div className="font-preview-interface-buttons">+ <Button text={t("confirm.cancel")} />+ <Button text={t("confirm.ok")} kind="primary" />+ </div>+ </div>+ );+}+/** The plot names set `0` against `O` and `1` against `l`; the operators are ligature pairs. */const CODE_PREVIEW = `const PLOTS = ["01", "10", "11"];