feat(client/fonts): add groups for fonts

This commit is contained in:
Elian Doran 2025-01-03 18:55:45 +02:00
parent 639d118f41
commit 710a80aa26
No known key found for this signature in database

View File

@ -3,11 +3,14 @@ import utils from "../../../../services/utils.js";
import { t } from "../../../../services/i18n.js"; import { t } from "../../../../services/i18n.js";
import { OptionMap, OptionNames } from "../../../../../../services/options_interface.js"; import { OptionMap, OptionNames } from "../../../../../../services/options_interface.js";
const FONT_FAMILIES = [ const FONT_FAMILIES = {
"Generic fonts": [
{ value: "theme", label: t("fonts.theme_defined") }, { value: "theme", label: t("fonts.theme_defined") },
{ value: "serif", label: "Serif" }, { value: "serif", label: "Serif" },
{ value: "sans-serif", label: "Sans Serif" }, { value: "sans-serif", label: "Sans Serif" },
{ value: "monospace", label: "Monospace" }, { value: "monospace", label: "Monospace" },
],
"System fonts": [
{ value: "Arial", label: "Arial" }, { value: "Arial", label: "Arial" },
{ value: "Verdana", label: "Verdana" }, { value: "Verdana", label: "Verdana" },
{ value: "Helvetica", label: "Helvetica" }, { value: "Helvetica", label: "Helvetica" },
@ -27,7 +30,8 @@ const FONT_FAMILIES = [
{ value: "Luminari", label: "Luminari" }, { value: "Luminari", label: "Luminari" },
{ value: "Comic Sans MS", label: "Comic Sans MS" }, { value: "Comic Sans MS", label: "Comic Sans MS" },
{ value: "Microsoft YaHei", label: "Microsoft YaHei" }, { value: "Microsoft YaHei", label: "Microsoft YaHei" },
]; ]
};
const TPL = ` const TPL = `
<div class="options-section"> <div class="options-section">
@ -186,11 +190,17 @@ export default class FontsOptions extends OptionsWidget {
fillFontFamilyOptions($select: JQuery<HTMLElement>, currentValue: string) { fillFontFamilyOptions($select: JQuery<HTMLElement>, currentValue: string) {
$select.empty(); $select.empty();
for (const {value, label} of FONT_FAMILIES) { for (const [group, fonts] of Object.entries(FONT_FAMILIES)) {
$select.append($("<optgroup>")
.attr("label", group));
for (const {value, label} of fonts) {
$select.append($("<option>") $select.append($("<option>")
.attr("value", value) .attr("value", value)
.prop("selected", value === currentValue) .prop("selected", value === currentValue)
.text(label)); .text(label));
} }
} }
}
} }