Skip to content

Build your personal knowledge base with Trilium Notes

chore(print_preview): reuse existing widgets

Elian Doranf9a5935b855d
diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md
index fad12709d3..ba1dbc9b50 100644
--- a/.github/copilot-instructions.md
+++ b/.github/copilot-instructions.md
@@ -118,14 +118,17 @@ class MyNoteWidget extends NoteContextAwareWidget {
**Important**: Widgets use jQuery (`this.$widget`) for DOM manipulation. Don't mix React patterns here.
### Reusable Preact Components
-Common UI components are available in `apps/client/src/widgets/react/` — prefer reusing these over creating custom implementations:
+Common UI components are available in `apps/client/src/widgets/react/` — **always** reuse these instead of writing raw HTML elements or custom implementations:
- `NoItems` - Empty state placeholder with icon and message (use for "no results", "too many items", error states)
- `ActionButton` - Consistent button styling with icon support
-- `FormTextBox` - Text input with validation and controlled input handling
+- `FormTextBox` - Text input with validation and controlled input handling; `FormTextBoxWithUnit` for inputs with a unit suffix (e.g. "mm", "px")
+- `FormSelect` - Dropdown/combobox taking an object array as data
- `Slider` - Range slider with label
- `Checkbox`, `RadioButton` - Form controls
- `CollapsibleSection` - Expandable content sections
+**Do not use Bootstrap utility classes** (e.g. `form-control-sm`, `form-select-sm`, `input-group`) on these components — they manage their own styling internally. If you need to adjust sizing or layout, use props provided by the component or CSS custom properties, not Bootstrap overrides.
+
## Development Workflow
### Running & Testing
diff --git a/CLAUDE.md b/CLAUDE.md
index a395f985bf..c796821960 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -69,14 +69,17 @@ Frontend uses a widget system (`apps/client/src/widgets/`):
- Type-specific widgets in `type_widgets/` directory
#### Reusable Preact Components
-Common UI components are available in `apps/client/src/widgets/react/` — prefer reusing these over creating custom implementations:
+Common UI components are available in `apps/client/src/widgets/react/` — **always** reuse these instead of writing raw HTML elements or custom implementations:
- `NoItems` - Empty state placeholder with icon and message (use for "no results", "too many items", error states)
- `ActionButton` - Consistent button styling with icon support
-- `FormTextBox` - Text input with validation and controlled input handling
+- `FormTextBox` - Text input with validation and controlled input handling; `FormTextBoxWithUnit` for inputs with a unit suffix (e.g. "mm", "px")
+- `FormSelect` - Dropdown/combobox taking an object array as data
- `Slider` - Range slider with label
- `Checkbox`, `RadioButton` - Form controls
- `CollapsibleSection` - Expandable content sections
+**Do not use Bootstrap utility classes** (e.g. `form-control-sm`, `form-select-sm`, `input-group`) on these components — they manage their own styling internally. If you need to adjust sizing or layout, use props provided by the component or CSS custom properties, not Bootstrap overrides.
+
#### API Architecture
- **Internal API**: REST endpoints in `apps/server/src/routes/api/`
- **ETAPI**: External API for third-party integrations (`apps/server/src/etapi/`)
diff --git a/apps/client/src/widgets/dialogs/print_preview.tsx b/apps/client/src/widgets/dialogs/print_preview.tsx
index d60ff23012..1af4b814dd 100644
--- a/apps/client/src/widgets/dialogs/print_preview.tsx
+++ b/apps/client/src/widgets/dialogs/print_preview.tsx
@@ -7,6 +7,8 @@ import { dynamicRequire, isElectron } from "../../services/utils";
import Button, { ButtonGroup } from "../react/Button";
import Dropdown from "../react/Dropdown";
import { FormListHeader, FormListItem } from "../react/FormList";
+import FormSelect from "../react/FormSelect";
+import FormTextBox, { FormTextBoxWithUnit } from "../react/FormTextBox";
import { useNoteLabelBoolean, useNoteLabelWithDefault, useTriliumEvent } from "../react/hooks";
import Modal from "../react/Modal";
import Slider from "../react/Slider";
@@ -356,16 +358,14 @@ export default function PrintPreviewDialog() {
</OptionsRow>
<OptionsRow name="pageSize" label={t("print_preview.page_size")}>
- <select
- class="form-select form-select-sm"
- value={pageSize}
- onChange={(e) => setPageSize((e.target as HTMLSelectElement).value)}
+ <FormSelect
+ values={PAGE_SIZES.map((size) => ({ key: size, title: size }))}
+ keyProperty="key"
+ titleProperty="title"
+ currentValue={pageSize}
+ onChange={setPageSize}
disabled={loading}
- >
- {PAGE_SIZES.map((size) => (
- <option key={size} value={size}>{size}</option>
- ))}
- </select>
+ />
</OptionsRow>
<OptionsRow name="scale" label={t("print_preview.scale")} description={`${Math.round(scale * 100)}%`}>
@@ -379,17 +379,19 @@ export default function PrintPreviewDialog() {
</OptionsRow>
<OptionsRow name="margins" label={t("print_preview.margins")}>
- <select
- class="form-select form-select-sm"
- value={marginPreset}
- onChange={(e) => setMarginsStr(serializeMargins((e.target as HTMLSelectElement).value as MarginPreset | "custom", customMargins))}
+ <FormSelect
+ values={[
+ { key: "default", title: t("print_preview.margins_default") },
+ { key: "none", title: t("print_preview.margins_none") },
+ { key: "minimum", title: t("print_preview.margins_minimum") },
+ { key: "custom", title: t("print_preview.margins_custom") },
+ ]}
+ keyProperty="key"
+ titleProperty="title"
+ currentValue={marginPreset}
+ onChange={(value) => setMarginsStr(serializeMargins(value as MarginPreset | "custom", customMargins))}
disabled={loading}
- >
- <option value="default">{t("print_preview.margins_default")}</option>
- <option value="none">{t("print_preview.margins_none")}</option>
- <option value="minimum">{t("print_preview.margins_minimum")}</option>
- <option value="custom">{t("print_preview.margins_custom")}</option>
- </select>
+ />
</OptionsRow>
{marginPreset === "custom" && (
@@ -401,12 +403,11 @@ export default function PrintPreviewDialog() {
label={t("print_preview.page_ranges")}
description={!pageRangesValid ? t("print_preview.page_ranges_invalid") : t("print_preview.page_ranges_hint")}
>
- <input
- type="text"
- class={`form-control form-control-sm ${!pageRangesValid ? "is-invalid" : ""}`}
- value={pageRanges}
+ <FormTextBox
+ className={!pageRangesValid ? "is-invalid" : ""}
+ currentValue={pageRanges}
placeholder={t("print_preview.page_ranges_placeholder")}
- onInput={(e) => setPageRanges((e.target as HTMLInputElement).value)}
+ onChange={(value) => setPageRanges(value)}
disabled={loading}
style={{ width: "140px" }}
/>
@@ -461,20 +462,18 @@ function MarginSpinner({ label, value, onChange, disabled, style }: {
style?: Record<string, string>;
}) {
return (
- <div class="input-group input-group-sm" style={style}>
- <input
- type="number"
- class="form-control form-control-sm"
- title={label}
- aria-label={label}
- value={value}
- min={0}
- max={100}
- step={1}
- onChange={(e) => onChange(Math.min(100, (e.target as HTMLInputElement).valueAsNumber || 0))}
- disabled={disabled}
- />
- <span class="input-group-text">mm</span>
- </div>
+ <FormTextBoxWithUnit
+ type="number"
+ style={style}
+ title={label}
+ aria-label={label}
+ currentValue={String(value)}
+ min={0}
+ max={100}
+ step={1}
+ onChange={(val) => onChange(Math.min(100, parseInt(val, 10) || 0))}
+ disabled={disabled}
+ unit="mm"
+ />
);
}