mirror of
https://github.com/zadam/trilium.git
synced 2025-10-30 09:56:36 +01:00
feat(react/settings): port override theme fonts
This commit is contained in:
@@ -1,13 +1,14 @@
|
|||||||
import type { ComponentChildren } from "preact";
|
import type { ComponentChildren } from "preact";
|
||||||
|
|
||||||
interface ColumnProps {
|
interface ColumnProps {
|
||||||
md: number;
|
md?: number;
|
||||||
children: ComponentChildren;
|
children: ComponentChildren;
|
||||||
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Column({ md, children }: ColumnProps) {
|
export default function Column({ md, children, className }: ColumnProps) {
|
||||||
return (
|
return (
|
||||||
<div className={`col-md-${md}`}>
|
<div className={`col-md-${md ?? 6} ${className ?? ""}`}>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import SpacedUpdate from "../../services/spaced_update";
|
|||||||
import { OptionNames } from "@triliumnext/commons";
|
import { OptionNames } from "@triliumnext/commons";
|
||||||
import options from "../../services/options";
|
import options from "../../services/options";
|
||||||
import utils, { reloadFrontendApp } from "../../services/utils";
|
import utils, { reloadFrontendApp } from "../../services/utils";
|
||||||
|
import { __values } from "tslib";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows a React component to react to Trilium events (e.g. `entitiesReloaded`). When the desired event is triggered, the handler is invoked with the event parameters.
|
* Allows a React component to react to Trilium events (e.g. `entitiesReloaded`). When the desired event is triggered, the handler is invoked with the event parameters.
|
||||||
@@ -93,6 +94,14 @@ export function useTriliumOption(name: OptionNames, needsRefresh?: boolean): [st
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useTriliumOptionBool(name: OptionNames): [boolean, (newValue: boolean) => Promise<void>] {
|
||||||
|
const [ value, setValue ] = useTriliumOption(name);
|
||||||
|
return [
|
||||||
|
(value === "true"),
|
||||||
|
(newValue) => setValue(newValue ? "true" : "false")
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a unique name via a random alphanumeric string of a fixed length.
|
* Generates a unique name via a random alphanumeric string of a fixed length.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ import { isMobile, reloadFrontendApp } from "../../../services/utils";
|
|||||||
import Column from "../../react/Column";
|
import Column from "../../react/Column";
|
||||||
import FormRadioGroup from "../../react/FormRadioGroup";
|
import FormRadioGroup from "../../react/FormRadioGroup";
|
||||||
import FormSelect from "../../react/FormSelect";
|
import FormSelect from "../../react/FormSelect";
|
||||||
import { useTriliumOption } from "../../react/hooks";
|
import { useTriliumOption, useTriliumOptionBool } from "../../react/hooks";
|
||||||
import OptionsSection from "./components/OptionsSection";
|
import OptionsSection from "./components/OptionsSection";
|
||||||
import server from "../../../services/server";
|
import server from "../../../services/server";
|
||||||
|
import FormCheckbox from "../../react/FormCheckbox";
|
||||||
|
|
||||||
interface Theme {
|
interface Theme {
|
||||||
val: string;
|
val: string;
|
||||||
@@ -26,6 +27,7 @@ const BUILTIN_THEMES: Theme[] = [
|
|||||||
export default function AppearanceSettings() {
|
export default function AppearanceSettings() {
|
||||||
const [ layoutOrientation, setLayoutOrientation ] = useTriliumOption("layoutOrientation", true);
|
const [ layoutOrientation, setLayoutOrientation ] = useTriliumOption("layoutOrientation", true);
|
||||||
const [ theme, setTheme ] = useTriliumOption("theme", true);
|
const [ theme, setTheme ] = useTriliumOption("theme", true);
|
||||||
|
const [ overrideThemeFonts, setOverrideThemeFonts ] = useTriliumOptionBool("overrideThemeFonts");
|
||||||
|
|
||||||
const [ themes, setThemes ] = useState<Theme[]>([]);
|
const [ themes, setThemes ] = useState<Theme[]>([]);
|
||||||
|
|
||||||
@@ -58,10 +60,17 @@ export default function AppearanceSettings() {
|
|||||||
</OptionsSection>
|
</OptionsSection>
|
||||||
|
|
||||||
<OptionsSection title={t("theme.title")}>
|
<OptionsSection title={t("theme.title")}>
|
||||||
<Column md={6}>
|
<Column>
|
||||||
<label>{t("theme.theme_label")}</label>
|
<label>{t("theme.theme_label")}</label>
|
||||||
<FormSelect values={themes} currentValue={theme} onChange={setTheme} />
|
<FormSelect values={themes} currentValue={theme} onChange={setTheme} />
|
||||||
</Column>
|
</Column>
|
||||||
|
|
||||||
|
<Column className="side-checkbox">
|
||||||
|
<FormCheckbox
|
||||||
|
name="override-theme-fonts"
|
||||||
|
label={t("theme.override_theme_fonts_label")}
|
||||||
|
currentValue={overrideThemeFonts} onChange={setOverrideThemeFonts} />
|
||||||
|
</Column>
|
||||||
</OptionsSection>
|
</OptionsSection>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
import OptionsWidget from "../options_widget.js";
|
|
||||||
import server from "../../../../services/server.js";
|
|
||||||
import utils from "../../../../services/utils.js";
|
|
||||||
import { t } from "../../../../services/i18n.js";
|
|
||||||
import type { OptionMap } from "@triliumnext/commons";
|
|
||||||
|
|
||||||
const TPL = /*html*/`
|
|
||||||
<div class="options-section">
|
|
||||||
<div class="form-group row">
|
|
||||||
<div class="col-md-6 side-checkbox">
|
|
||||||
<label class="form-check tn-checkbox">
|
|
||||||
<input type="checkbox" class="override-theme-fonts form-check-input">
|
|
||||||
${t("theme.override_theme_fonts_label")}
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
|
|
||||||
export default class ThemeOptions extends OptionsWidget {
|
|
||||||
|
|
||||||
private $overrideThemeFonts!: JQuery<HTMLElement>;
|
|
||||||
|
|
||||||
doRender() {
|
|
||||||
this.$widget = $(TPL);
|
|
||||||
this.$themeSelect = this.$widget.find(".theme-select");
|
|
||||||
this.$overrideThemeFonts = this.$widget.find(".override-theme-fonts");
|
|
||||||
|
|
||||||
|
|
||||||
this.$overrideThemeFonts.on("change", () => this.updateCheckboxOption("overrideThemeFonts", this.$overrideThemeFonts));
|
|
||||||
}
|
|
||||||
|
|
||||||
async optionsLoaded(options: OptionMap) {
|
|
||||||
this.setCheckboxState(this.$overrideThemeFonts, options.overrideThemeFonts);
|
|
||||||
|
|
||||||
this.$widget.find(`input[name="layout-orientation"][value="${options.layoutOrientation}"]`).prop("checked", "true");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,9 @@ export default function OptionsSection({ title, children }: OptionsSectionProps)
|
|||||||
<div className="options-section">
|
<div className="options-section">
|
||||||
<h4>{title}</h4>
|
<h4>{title}</h4>
|
||||||
|
|
||||||
{children}
|
<div className="form-group row">
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user