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
client/options/code notes: switch to the new card component
Adorian Doranafc1a3e1e93e
diff --git a/apps/client/src/widgets/type_widgets/options/code_mime_types_list.css b/apps/client/src/widgets/type_widgets/options/code_mime_types_list.cssindex 912cc1d64a..ca9cd9b34a 100644--- a/apps/client/src/widgets/type_widgets/options/code_mime_types_list.css+++ b/apps/client/src/widgets/type_widgets/options/code_mime_types_list.css@@ -8,6 +8,16 @@break-inside: avoid-column;}+ /* The initial the group is filed under, marked the way a card marks its heading: it names a+ column of entries rather than introducing a subject of its own. */+ h5 {+ margin-bottom: 0.25em;+ font-size: .75rem;+ font-weight: bold;+ letter-spacing: .4pt;+ text-transform: uppercase;+ }+ul {padding-inline-start: 0;}diff --git a/apps/client/src/widgets/type_widgets/options/code_notes.css b/apps/client/src/widgets/type_widgets/options/code_notes.cssindex cfb1e738e8..11aaa7127a 100644--- a/apps/client/src/widgets/type_widgets/options/code_notes.css+++ b/apps/client/src/widgets/type_widgets/options/code_notes.css@@ -1,16 +1,26 @@-.note-detail-content-widget-content.options {- /* #region Code Preview */- .options-section.code-block-appearance .options-section-card {- overflow: hidden;+/* Bootstrap gives a select the whole width of what holds it, which in a card row leaves the label+ beside it a word to the line. Sized to what it offers instead, and cut short rather than carried+ across the row. */+.code-notes-appearance select {+ width: auto;+ min-width: 150px;+ max-width: 260px;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+}- .option-row:nth-last-child(2) {- border-bottom: 0;- }+/* A figure and the unit it is read in, sized to the figure: Bootstrap gives an input group the whole+ width of what holds it, which in a card row is the row. */+.code-notes-number .tn-number-unit-pair {+ width: auto;- .note-detail-readonly-code-content {- border-top: solid 1px var(--main-border-color);- margin: 0 calc(var(--options-card-padding) * -1) calc(var(--options-card-padding) * -1) calc(var(--options-card-padding) * -1) !important;- }+ input[type="number"] {+ width: 7em;}- /* #endregion */+}++/* Clipped to the corners the last segment rounds, which the editor inside would otherwise paint over. */+.code-note-preview {+ overflow: hidden;}diff --git a/apps/client/src/widgets/type_widgets/options/code_notes.tsx b/apps/client/src/widgets/type_widgets/options/code_notes.tsxindex 3feffad338..5de85184e5 100644--- a/apps/client/src/widgets/type_widgets/options/code_notes.tsx+++ b/apps/client/src/widgets/type_widgets/options/code_notes.tsx@@ -4,14 +4,14 @@ import CodeMirror, { ColorThemes, getThemeById, type ThemeVariant } from "@triliimport { useEffect, useMemo, useRef } from "preact/hooks";import { t } from "../../../services/i18n";+import { Card, CardOption, CardSection } from "../../react/Card";import FormSelect from "../../react/FormSelect";import { FormTextBoxWithUnit } from "../../react/FormTextBox";+import FormToggle from "../../react/FormToggle";import { useColorScheme, useTriliumOption, useTriliumOptionBool } from "../../react/hooks";import { CODE_THEME_DEFAULT_PREFIX as DEFAULT_PREFIX } from "../constants";import { CodeMimeTypesList } from "./code_mime_types_list";import OptionsPageHeader from "./components/OptionsPageHeader";-import OptionsRow, { OptionsRowWithToggle } from "./components/OptionsRow";-import OptionsSection from "./components/OptionsSection";import ThemeModeSelector from "./components/ThemeModeSelector";import codeNoteSample from "./samples/code_note.txt?raw";@@ -42,42 +42,50 @@ function Editor({ wordWrapping, setWordWrapping }: EditorProps) {const [codeNoteTabWidth, setCodeNoteTabWidth] = useTriliumOption("codeNoteTabWidth");return (- <OptionsSection title={t("code-editor-options.title")}>- <OptionsRowWithToggle- name="word-wrap"- label={t("code_theme.word_wrapping")}- currentValue={wordWrapping}- onChange={setWordWrapping}- />-- {/* Avoid using "code" in the name of numeric inputs to prevent KeepassXC from triggering. */}- <OptionsRow name="editor-tab-width" label={t("code-editor-options.tab_width")}>- <FormTextBoxWithUnit- type="number" min={1} max={16} step={1}- unit={t("code-editor-options.tab_width_unit")}- currentValue={codeNoteTabWidth}- onChange={setCodeNoteTabWidth}- onBlur={setCodeNoteTabWidth}- />- </OptionsRow>-- <OptionsRow name="source-readonly-threshold" label={t("code_auto_read_only_size.label")} description={t("text_auto_read_only_size.description")}>- <FormTextBoxWithUnit- type="number" min={0}- unit={t("text_auto_read_only_size.unit")}- currentValue={autoReadonlySize}- onBlur={setAutoReadonlySize}- />- </OptionsRow>-- <OptionsRowWithToggle- name="vim-keymap-enabled"- label={t("vim_key_bindings.use_vim_keybindings_in_code_notes")}- description={t("vim_key_bindings.enable_vim_keybindings")}- currentValue={vimKeymapEnabled}- onChange={setVimKeymapEnabled}- />- </OptionsSection>+ <div className="options-section">+ <Card heading={t("code-editor-options.title")}>+ <CardOption name="word-wrap" label={t("code_theme.word_wrapping")}>+ <FormToggle currentValue={wordWrapping} onChange={setWordWrapping} />+ </CardOption>++ {/* Avoid using "code" in the name of numeric inputs to prevent KeepassXC from triggering. */}+ <CardOption+ className="code-notes-number"+ name="editor-tab-width"+ label={t("code-editor-options.tab_width")}+ >+ <FormTextBoxWithUnit+ type="number" min={1} max={16} step={1}+ unit={t("code-editor-options.tab_width_unit")}+ currentValue={codeNoteTabWidth}+ onChange={setCodeNoteTabWidth}+ onBlur={setCodeNoteTabWidth}+ />+ </CardOption>++ <CardOption+ className="code-notes-number"+ name="source-readonly-threshold"+ label={t("code_auto_read_only_size.label")}+ description={t("text_auto_read_only_size.description")}+ >+ <FormTextBoxWithUnit+ type="number" min={0}+ unit={t("text_auto_read_only_size.unit")}+ currentValue={autoReadonlySize}+ onBlur={setAutoReadonlySize}+ />+ </CardOption>++ <CardOption+ name="vim-keymap-enabled"+ label={t("vim_key_bindings.use_vim_keybindings_in_code_notes")}+ description={t("vim_key_bindings.enable_vim_keybindings")}+ >+ <FormToggle currentValue={vimKeymapEnabled} onChange={setVimKeymapEnabled} />+ </CardOption>+ </Card>+ </div>);}@@ -113,38 +121,44 @@ function Appearance({ wordWrapping, indentSize }: AppearanceProps) {: codeNoteTheme;return (- <OptionsSection title={t("code_theme.title")} className="code-block-appearance">- <ThemeModeSelector matchesApp={matchesApp} onMatchesAppChange={setMatchesApp} />-- {matchesApp ? (- <>- <OptionsRow name="light-theme" label={t("code_theme.light_theme")}>- <FormSelect- values={lightThemes}- keyProperty="id" titleProperty="name"- currentValue={lightTheme} onChange={setLightTheme}- />- </OptionsRow>- <OptionsRow name="dark-theme" label={t("code_theme.dark_theme")}>+ <div className="options-section code-notes-appearance">+ <Card heading={t("code_theme.title")}>+ <ThemeModeSelector matchesApp={matchesApp} onMatchesAppChange={setMatchesApp} />++ {matchesApp ? (+ <>+ <CardOption name="light-theme" label={t("code_theme.light_theme")}>+ <FormSelect+ values={lightThemes}+ keyProperty="id" titleProperty="name"+ currentValue={lightTheme} onChange={setLightTheme}+ />+ </CardOption>+ <CardOption name="dark-theme" label={t("code_theme.dark_theme")}>+ <FormSelect+ values={darkThemes}+ keyProperty="id" titleProperty="name"+ currentValue={darkTheme} onChange={setDarkTheme}+ />+ </CardOption>+ </>+ ) : (+ <CardOption name="color-scheme" label={t("code_theme.color-scheme")}><FormSelect- values={darkThemes}+ values={allThemes}keyProperty="id" titleProperty="name"- currentValue={darkTheme} onChange={setDarkTheme}+ currentValue={codeNoteTheme} onChange={setCodeNoteTheme}/>- </OptionsRow>- </>- ) : (- <OptionsRow name="color-scheme" label={t("code_theme.color-scheme")}>- <FormSelect- values={allThemes}- keyProperty="id" titleProperty="name"- currentValue={codeNoteTheme} onChange={setCodeNoteTheme}- />- </OptionsRow>- )}-- <CodeNotePreview wordWrapping={wordWrapping} themeName={effectiveTheme} indentSize={indentSize} />- </OptionsSection>+ </CardOption>+ )}++ {/* The whole segment, edge to edge: a specimen of the editor rather than a control+ standing beside a label. */}+ <CardSection className="code-note-preview" noPadding>+ <CodeNotePreview wordWrapping={wordWrapping} themeName={effectiveTheme} indentSize={indentSize} />+ </CardSection>+ </Card>+ </div>);}@@ -210,9 +224,13 @@ function reindentSample(sample: string, indentSize: number): string {function CodeMimeTypes() {return (- <OptionsSection title={t("code_mime_types.title")}>- <CodeMimeTypesList />- </OptionsSection>+ <div className="options-section">+ <Card heading={t("code_mime_types.title")}>+ <CardSection>+ <CodeMimeTypesList />+ </CardSection>+ </Card>+ </div>);}diff --git a/apps/client/src/widgets/type_widgets/options/components/ThemeModeSelector.tsx b/apps/client/src/widgets/type_widgets/options/components/ThemeModeSelector.tsxindex 6dce02d0d3..2aff8f76b9 100644--- a/apps/client/src/widgets/type_widgets/options/components/ThemeModeSelector.tsx+++ b/apps/client/src/widgets/type_widgets/options/components/ThemeModeSelector.tsx@@ -1,6 +1,6 @@import { t } from "../../../../services/i18n";+import { CardOption } from "../../../react/Card";import SegmentedChoice, { SegmentedChoiceOption } from "../../../react/SegmentedChoice";-import OptionsRow from "./OptionsRow";type ThemeMode = "app" | "fixed";@@ -16,13 +16,13 @@ export default function ThemeModeSelector({ matchesApp, onMatchesAppChange }: Th];return (- <OptionsRow name="theme-mode" label={t("code_theme.theme_mode")}>+ <CardOption name="theme-mode" label={t("code_theme.theme_mode")}><SegmentedChoiceoptions={modes}currentValue={matchesApp ? "app" : "fixed"}onChange={(mode) => onMatchesAppChange(mode === "app")}collapseOnMobile/>- </OptionsRow>+ </CardOption>);}diff --git a/apps/client/src/widgets/type_widgets/options/text_notes.tsx b/apps/client/src/widgets/type_widgets/options/text_notes.tsxindex 58e7547392..b446a3b490 100644--- a/apps/client/src/widgets/type_widgets/options/text_notes.tsx+++ b/apps/client/src/widgets/type_widgets/options/text_notes.tsx@@ -20,12 +20,12 @@ import FormTextBox, { FormTextBoxWithUnit } from "../../react/FormTextBox";import FormToggle from "../../react/FormToggle";import { useColorScheme, useTriliumOption, useTriliumOptionBool } from "../../react/hooks";import { getHtml } from "../../react/RawHtml";-import SegmentedChoice, { SegmentedChoiceOption } from "../../react/SegmentedChoice";import { QUOTE_MARK_PRESETS } from "../text/quotes";import { type CustomReplacement, parseCustomReplacements } from "../text/replacements";import OptionsPageHeader from "./components/OptionsPageHeader";import RadioWithIllustration from "./components/RadioWithIllustration";import RelatedSettings from "./components/RelatedSettings";+import ThemeModeSelector from "./components/ThemeModeSelector";import { HighlightsListOptions } from "./highlights_list_options";const isNewLayout = isExperimentalFeatureEnabled("new-layout");@@ -564,7 +564,7 @@ function CodeBlockStyle() {return (<div className="options-section text-notes-code-blocks"><Card heading={t("highlighting.title")}>- <ThemeModeOption matchesApp={matchesApp} onMatchesAppChange={setMatchesApp} />+ <ThemeModeSelector matchesApp={matchesApp} onMatchesAppChange={setMatchesApp} />{matchesApp ? (<>@@ -616,31 +616,6 @@ function CodeBlockStyle() {);}-type ThemeMode = "app" | "fixed";--/**- * Whether the code block theme follows the app's own light and dark, or stays on one whatever the app- * does. Kept here rather than taken from `ThemeModeSelector`, which still speaks in option rows for- * the code notes page — the two rejoin once that page has cards of its own.- */-function ThemeModeOption({ matchesApp, onMatchesAppChange }: { matchesApp: boolean, onMatchesAppChange: (value: boolean) => void }) {- const modes: SegmentedChoiceOption<ThemeMode>[] = [- { value: "app", label: t("code_theme.match_app_appearance"), icon: "bx-brightness-half" },- { value: "fixed", label: t("code_theme.always_use_one_theme"), icon: "bx-pin" }- ];-- return (- <CardOption name="theme-mode" label={t("code_theme.theme_mode")}>- <SegmentedChoice- options={modes}- currentValue={matchesApp ? "app" : "fixed"}- onChange={(mode) => onMatchesAppChange(mode === "app")}- collapseOnMobile- />- </CardOption>- );-}-const SAMPLE_LANGUAGE = normalizeMimeTypeForCKEditor("application/javascript;env=frontend");const SAMPLE_CODE = `\const n = 10;