Skip to content

Build your personal knowledge base with Trilium Notes

client/options/language & region: switch to the new card component

Adorian Doran59a4933d5f85
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index e78c496fb4..4abb797842 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2063,6 +2063,7 @@
"i18n": {
"title": "Localization",
"language": "Language",
+ "dates-title": "Dates & calendar",
"first-day-of-the-week": "First day of the week",
"monday": "Monday",
"tuesday": "Tuesday",
diff --git a/apps/client/src/widgets/type_widgets/options/i18n.css b/apps/client/src/widgets/type_widgets/options/i18n.css
new file mode 100644
index 0000000000..b70b2888ad
--- /dev/null
+++ b/apps/client/src/widgets/type_widgets/options/i18n.css
@@ -0,0 +1,22 @@
+/* Bootstrap gives a select the whole width of what holds it; in a card row it stands beside the
+ label instead, so it takes the width of what it offers — capped, one of the choices being a
+ sentence. The bounds are the ones these rows carried before they were card sections. */
+.i18n-dates select {
+ width: auto;
+ min-width: 150px;
+ max-width: 100%;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+/* Many lines rather than a control on one, so it is given room from the section's own edges.
+ `!important` because CheckboxList zeroes its bottom margin inline, which no selector outweighs. */
+.i18n-content-languages ul {
+ margin-block: 1em !important;
+}
+
+/* No card of its own, so it keeps the width of the ones above and ends where their controls do. */
+.i18n-restart {
+ text-align: end;
+}
diff --git a/apps/client/src/widgets/type_widgets/options/i18n.tsx b/apps/client/src/widgets/type_widgets/options/i18n.tsx
index b2a01f0fa9..cd758d9e3f 100644
--- a/apps/client/src/widgets/type_widgets/options/i18n.tsx
+++ b/apps/client/src/widgets/type_widgets/options/i18n.tsx
@@ -1,24 +1,27 @@
+import "./i18n.css";
+
+import type { Locale } from "@triliumnext/commons";
import { useMemo } from "preact/hooks";
+
import { getAvailableLocales, t } from "../../../services/i18n";
-import FormSelect from "../../react/FormSelect";
-import OptionsPageHeader from "./components/OptionsPageHeader";
-import OptionsRow from "./components/OptionsRow";
-import OptionsSection from "./components/OptionsSection";
-import { useTriliumOption, useTriliumOptionJson } from "../../react/hooks";
-import type { Locale } from "@triliumnext/commons";
import { isElectron, restartDesktopApp } from "../../../services/utils";
-import FormText from "../../react/FormText";
import Button from "../../react/Button";
+import { Card, CardOption, CardSection } from "../../react/Card";
+import FormSelect from "../../react/FormSelect";
+import { useTriliumOption, useTriliumOptionJson } from "../../react/hooks";
import CheckboxList from "./components/CheckboxList";
-import RelatedSettings from "./components/RelatedSettings";
import { LocaleSelector } from "./components/LocaleSelector";
+import OptionsPageHeader from "./components/OptionsPageHeader";
+import RelatedSettings from "./components/RelatedSettings";
export default function InternationalizationOptions() {
return (
<>
<OptionsPageHeader />
<LocalizationOptions />
+ <DateSettings />
<ContentLanguages />
+ <RestartAction />
{isElectron() && (
<RelatedSettings items={[
{
@@ -32,6 +35,7 @@ export default function InternationalizationOptions() {
);
}
+/** The languages the app is read in, written in, and formats its figures and dates by. */
function LocalizationOptions() {
const { uiLocales, formattingLocales: contentLocales, writingLocales } = useMemo<{ uiLocales: Locale[], formattingLocales: Locale[], writingLocales: Locale[] }>(() => {
const allLocales = getAvailableLocales();
@@ -59,102 +63,116 @@ function LocalizationOptions() {
const [ defaultContentLanguage, setDefaultContentLanguage ] = useTriliumOption("defaultContentLanguage");
return (
- <OptionsSection title={t("i18n.title")}>
- <OptionsRow name="language" label={t("i18n.language")}>
- <LocaleSelector locales={uiLocales} currentValue={locale} onChange={setLocale} />
- </OptionsRow>
-
- {<OptionsRow name="formatting-locale" label={t("i18n.formatting-locale")}>
- <LocaleSelector locales={contentLocales} currentValue={formattingLocale} onChange={setFormattingLocale} defaultLocale={{ id: "", name: t("i18n.formatting-locale-auto") }} />
- </OptionsRow>}
-
- <OptionsRow
- name="default-content-language"
- label={t("i18n.default-content-language")}
- description={t("i18n.default-content-language-description")}
- >
- <LocaleSelector
- locales={writingLocales}
- currentValue={defaultContentLanguage}
- onChange={setDefaultContentLanguage}
- defaultLocale={{ id: "", name: t("i18n.default-content-language-auto") }}
- />
- </OptionsRow>
-
- <DateSettings />
- </OptionsSection>
+ <div className="options-section">
+ <Card heading={t("i18n.title")}>
+ <CardOption name="language" label={t("i18n.language")}>
+ <LocaleSelector locales={uiLocales} currentValue={locale} onChange={setLocale} />
+ </CardOption>
+
+ <CardOption name="formatting-locale" label={t("i18n.formatting-locale")}>
+ <LocaleSelector
+ locales={contentLocales}
+ currentValue={formattingLocale}
+ onChange={setFormattingLocale}
+ defaultLocale={{ id: "", name: t("i18n.formatting-locale-auto") }}
+ />
+ </CardOption>
+
+ <CardOption
+ name="default-content-language"
+ label={t("i18n.default-content-language")}
+ description={t("i18n.default-content-language-description")}
+ >
+ <LocaleSelector
+ locales={writingLocales}
+ currentValue={defaultContentLanguage}
+ onChange={setDefaultContentLanguage}
+ defaultLocale={{ id: "", name: t("i18n.default-content-language-auto") }}
+ />
+ </CardOption>
+ </Card>
+ </div>
)
}
+/**
+ * Where a week starts and which one counts as the first of the year — conventions the calendar and
+ * week notes are numbered by, rather than languages, which is why they stand apart from the card
+ * above.
+ */
function DateSettings() {
const [ firstDayOfWeek, setFirstDayOfWeek ] = useTriliumOption("firstDayOfWeek");
const [ firstWeekOfYear, setFirstWeekOfYear ] = useTriliumOption("firstWeekOfYear");
const [ minDaysInFirstWeek, setMinDaysInFirstWeek ] = useTriliumOption("minDaysInFirstWeek");
return (
- <>
- <OptionsRow name="first-day-of-week" label={t("i18n.first-day-of-the-week")}>
- <FormSelect
- name="first-day-of-week"
- currentValue={firstDayOfWeek}
- onChange={setFirstDayOfWeek}
- keyProperty="value"
- titleProperty="label"
- values={[
- { value: "1", label: t("i18n.monday") },
- { value: "2", label: t("i18n.tuesday") },
- { value: "3", label: t("i18n.wednesday") },
- { value: "4", label: t("i18n.thursday") },
- { value: "5", label: t("i18n.friday") },
- { value: "6", label: t("i18n.saturday") },
- { value: "7", label: t("i18n.sunday") },
- ]}
- />
- </OptionsRow>
-
- <OptionsRow name="first-week-of-year" label={t("i18n.first-week-of-the-year")} description={t("i18n.first-week-warning")}>
- <FormSelect
+ <div className="options-section i18n-dates">
+ <Card heading={t("i18n.dates-title")}>
+ <CardOption name="first-day-of-week" label={t("i18n.first-day-of-the-week")}>
+ <FormSelect
+ name="first-day-of-week"
+ currentValue={firstDayOfWeek}
+ onChange={setFirstDayOfWeek}
+ keyProperty="value"
+ titleProperty="label"
+ values={[
+ { value: "1", label: t("i18n.monday") },
+ { value: "2", label: t("i18n.tuesday") },
+ { value: "3", label: t("i18n.wednesday") },
+ { value: "4", label: t("i18n.thursday") },
+ { value: "5", label: t("i18n.friday") },
+ { value: "6", label: t("i18n.saturday") },
+ { value: "7", label: t("i18n.sunday") },
+ ]}
+ />
+ </CardOption>
+
+ <CardOption
name="first-week-of-year"
- currentValue={firstWeekOfYear}
- onChange={setFirstWeekOfYear}
- keyProperty="value"
- titleProperty="label"
- values={[
- { value: "0", label: t("i18n.first-week-contains-first-day") },
- { value: "1", label: t("i18n.first-week-contains-first-thursday") },
- { value: "2", label: t("i18n.first-week-has-minimum-days") }
- ]}
- />
- </OptionsRow>
-
- {firstWeekOfYear === "2" && <OptionsRow name="min-days-in-first-week" label={t("i18n.min-days-in-first-week")}>
- <FormSelect
- keyProperty="days"
- currentValue={minDaysInFirstWeek} onChange={setMinDaysInFirstWeek}
- values={Array.from(
- { length: 7 },
- (_, i) => ({ days: String(i + 1) }))} />
- </OptionsRow>}
-
- <OptionsRow name="restart" centered>
- <Button
- name="restart-app-button"
- text={t("electron_integration.restart-app-button")}
- size="micro"
- onClick={restartDesktopApp}
- />
- </OptionsRow>
- </>
+ label={t("i18n.first-week-of-the-year")}
+ description={t("i18n.first-week-warning")}
+ >
+ <FormSelect
+ name="first-week-of-year"
+ currentValue={firstWeekOfYear}
+ onChange={setFirstWeekOfYear}
+ keyProperty="value"
+ titleProperty="label"
+ values={[
+ { value: "0", label: t("i18n.first-week-contains-first-day") },
+ { value: "1", label: t("i18n.first-week-contains-first-thursday") },
+ { value: "2", label: t("i18n.first-week-has-minimum-days") }
+ ]}
+ />
+ </CardOption>
+
+ {firstWeekOfYear === "2" && (
+ <CardOption name="min-days-in-first-week" label={t("i18n.min-days-in-first-week")}>
+ <FormSelect
+ keyProperty="days"
+ currentValue={minDaysInFirstWeek} onChange={setMinDaysInFirstWeek}
+ values={Array.from(
+ { length: 7 },
+ (_, i) => ({ days: String(i + 1) }))} />
+ </CardOption>
+ )}
+ </Card>
+ </div>
)
}
function ContentLanguages() {
return (
- <OptionsSection title={t("content_language.title")}>
- <FormText>{t("content_language.description")}</FormText>
-
- <ContentLanguagesList />
- </OptionsSection>
+ <div className="options-section">
+ <Card
+ heading={t("content_language.title")}
+ description={t("content_language.description")}
+ >
+ <CardSection className="i18n-content-languages">
+ <ContentLanguagesList />
+ </CardSection>
+ </Card>
+ </div>
);
}
@@ -171,3 +189,21 @@ export function ContentLanguagesList() {
/>
);
}
+
+/**
+ * Both cards above only take effect once the app has started again. The way to do that carries no
+ * card of its own — it is an action the page offers rather than anything it holds — but keeps the
+ * cards' width, so it ends where they do.
+ */
+function RestartAction() {
+ return (
+ <div className="options-section i18n-restart">
+ <Button
+ name="restart-app-button"
+ text={t("electron_integration.restart-app-button")}
+ size="micro"
+ onClick={restartDesktopApp}
+ />
+ </div>
+ );
+}