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): let a font size be typed as well as dragged to
Elian Doran7dfef99a0abc
diff --git a/apps/client/src/widgets/type_widgets/options/appearance_fonts.css b/apps/client/src/widgets/type_widgets/options/appearance_fonts.cssindex 6372e8b6a7..f22e0eb063 100644--- a/apps/client/src/widgets/type_widgets/options/appearance_fonts.css+++ b/apps/client/src/widgets/type_widgets/options/appearance_fonts.css@@ -147,9 +147,14 @@ body.desktop .modal.font-picker-modal {flex: 1;}+ /* The pair sizes itself (see `theme-next/forms.css`), so the slider takes what is left. */+ .tn-number-unit-pair {+ flex: 0 0 auto;+ }++ /* Dragging the slider runs the number through every value between: proportional digits would+ shuffle its width the whole way. */.font-size-value {- min-width: 50px;- text-align: right;font-variant-numeric: tabular-nums;}}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 5a3e956b8c..1658940ce3 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,23 @@ describe("the font settings", () => {expect(catalogue.fonts.document_preview_body).toContain("<em>");});+ it("offers the size as a number to type as well as a slider to drag", async () => {+ mocks.stored = { overrideThemeFonts: true, mainFontSize: "120" };+ open();+ await act(async () => {});+ await act(async () => (fontRows()[0] as HTMLElement).click());++ const slider = document.querySelector<HTMLInputElement>(".font-picker-modal .slider");+ const box = document.querySelector<HTMLInputElement>(".font-picker-modal .font-size-value");+ expect(slider?.value).toBe("120");+ expect(box?.value).toBe("120");++ // The same bounds on both, so a size that can be typed is one the slider can reach back to.+ expect(box?.min).toBe(slider?.min);+ expect(box?.max).toBe(slider?.max);+ expect(box?.step).toBe(slider?.step);+ });+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();diff --git a/apps/client/src/widgets/type_widgets/options/appearance_fonts.tsx b/apps/client/src/widgets/type_widgets/options/appearance_fonts.tsxindex 79f7c9b779..f93e776338 100644--- a/apps/client/src/widgets/type_widgets/options/appearance_fonts.tsx+++ b/apps/client/src/widgets/type_widgets/options/appearance_fonts.tsx@@ -16,6 +16,7 @@ import Button from "../../react/Button";import { Card, OptionCardSection } from "../../react/Card";import { filterTokens, matchesFilter } from "../../react/filter";import FormList, { FormListHeader, FormListItem } from "../../react/FormList";+import { FormTextBoxWithUnit } from "../../react/FormTextBox";import FormToggle from "../../react/FormToggle";import { useChildNotes, useNoteTitle, useTriliumOption, useTriliumOptionBool } from "../../react/hooks";import Icon from "../../react/Icon";@@ -528,6 +529,11 @@ function CodePreview() {const PREVIEW_TEXT = "The quick brown fox jumps over the lazy dog. 0123456789";+/** Percentages, of the interface size for the tree and the document and of nothing for itself. */+const FONT_SIZE_MIN = 50;+const FONT_SIZE_MAX = 200;+const FONT_SIZE_STEP = 5;+interface FontPickerModalProps {show: boolean;onHidden: () => void;@@ -608,11 +614,20 @@ function FontPickerModal({ show, onHidden, target, onTargetChange, option: { fam<Slidervalue={size}onChange={setSize}- min={50}- max={200}- step={5}+ min={FONT_SIZE_MIN}+ max={FONT_SIZE_MAX}+ step={FONT_SIZE_STEP}+ />+ {/* The same control the zoom factor is set by, so a size can be typed and+ read back rather than only dragged to. */}+ <FormTextBoxWithUnit+ className="font-size-value"+ type="number"+ min={FONT_SIZE_MIN} max={FONT_SIZE_MAX} step={FONT_SIZE_STEP}+ currentValue={String(size)}+ onChange={(value) => setSize(parseInt(value, 10))}+ unit={t("units.percentage")}/>- <span className="font-size-value">{size}%</span></div>{target.sizeDescription && <small className="font-size-description">{target.sizeDescription}</small>}</div>