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/desktop: switch to the new card component
Adorian Doran4c8d8c934960
diff --git a/apps/client/src/widgets/type_widgets/options/components/OptionsRow.css b/apps/client/src/widgets/type_widgets/options/components/OptionsRow.cssindex ace1ba3bae..72a5ae78e5 100644--- a/apps/client/src/widgets/type_widgets/options/components/OptionsRow.css+++ b/apps/client/src/widgets/type_widgets/options/components/OptionsRow.css@@ -112,23 +112,3 @@ button.option-row-link:disabled {opacity: 0.6;pointer-events: none;}--.search-engine-templates {- --badge-radius: 12px;- display: flex;- align-items: center;- gap: 8px;- flex-wrap: wrap;-}--.search-engine-templates .ext-badge {- --color: var(--input-background-color);- color: var(--main-text-color);- font-size: 0.85em;-}--.search-engine-templates .ext-badge.selected {- --color: var(--accented-background-color);- outline: 2px solid var(--accent-color);- outline-offset: -2px;-}diff --git a/apps/client/src/widgets/type_widgets/options/desktop.css b/apps/client/src/widgets/type_widgets/options/desktop.cssnew file mode 100644index 0000000000..f603d6c4ec--- /dev/null+++ b/apps/client/src/widgets/type_widgets/options/desktop.css@@ -0,0 +1,35 @@+/* The engines offered ready-made, as a set of chips rather than a list. A card option holds its+ controls at their natural width; this one is a set that wraps, so it gives way to the label. */+.tn-card-option > .search-engine-templates {+ flex-shrink: 1;+ min-width: 0;+}++.search-engine-templates {+ --badge-radius: 12px;+ display: flex;+ flex-wrap: wrap;+ justify-content: end;+ align-items: center;+ gap: 8px;+}++.search-engine-templates .ext-badge {+ --color: var(--input-background-color);+ color: var(--main-text-color);+ font-size: 0.85em;+}++.search-engine-templates .ext-badge.selected {+ --color: var(--accented-background-color);+ outline: 2px solid var(--accent-color);+ outline-offset: -2px;+}++/* A name is a word or two, so the box is sized to what is typed in it rather than to the row:+ Bootstrap would otherwise give it the whole width of what holds it. Not said of the URL below it,+ which is stacked and wants the line it was given. */+.desktop-search-name input {+ width: auto;+ max-width: 100%;+}diff --git a/apps/client/src/widgets/type_widgets/options/desktop.tsx b/apps/client/src/widgets/type_widgets/options/desktop.tsxindex 331f30bc08..82c441f955 100644--- a/apps/client/src/widgets/type_widgets/options/desktop.tsx+++ b/apps/client/src/widgets/type_widgets/options/desktop.tsx@@ -1,14 +1,16 @@+import "./desktop.css";+import { useMemo } from "preact/hooks";import { t } from "../../../services/i18n";import utils, { isElectron } from "../../../services/utils";import { Badge } from "../../react/Badge";+import { Card, CardOption } from "../../react/Card";import FormTextBox from "../../react/FormTextBox";+import FormToggle from "../../react/FormToggle";import { useTriliumOption, useTriliumOptionBool } from "../../react/hooks";import NoItems from "../../react/NoItems";import OptionsPageHeader from "./components/OptionsPageHeader";-import OptionsRow, { OptionsRowWithToggle } from "./components/OptionsRow";-import OptionsSection from "./components/OptionsSection";export default function DesktopSettings() {// The page is hidden from the options nav on the server (it's #electronOnly),@@ -18,9 +20,9 @@ export default function DesktopSettings() {return (<><OptionsPageHeader />- <OptionsSection>+ <div className="options-section"><NoItems text={t("desktop.web_placeholder")} icon="bx bx-desktop" />- </OptionsSection>+ </div></>);}@@ -40,28 +42,37 @@ function TrayOptionsSettings() {const [ closeToTray, setCloseToTray ] = useTriliumOptionBool("closeToTray");return (- <OptionsSection title={t("tray.title")}>- <OptionsRowWithToggle- name="tray-enabled"- label={t("tray.enable_tray")}- description={t("tray.enable_tray_description")}- currentValue={!disableTray}- onChange={async trayEnabled => {- await setDisableTray(!trayEnabled);- // Apply the change immediately so the user doesn't have to restart the app.- utils.reloadTray();- }}- />- <OptionsRowWithToggle- name="close-to-tray"- label={t("tray.close_to_tray")}- description={t("tray.close_to_tray_description")}- currentValue={closeToTray}- // Close-to-tray with no tray icon would hide the app with no way back.- disabled={disableTray}- onChange={setCloseToTray}- />- </OptionsSection>+ <div className="options-section">+ <Card heading={t("tray.title")}>+ <CardOption+ name="tray-enabled"+ label={t("tray.enable_tray")}+ description={t("tray.enable_tray_description")}+ >+ <FormToggle+ currentValue={!disableTray}+ onChange={async trayEnabled => {+ await setDisableTray(!trayEnabled);+ // Apply the change immediately so the user doesn't have to restart the app.+ utils.reloadTray();+ }}+ />+ </CardOption>++ <CardOption+ name="close-to-tray"+ label={t("tray.close_to_tray")}+ description={t("tray.close_to_tray_description")}+ >+ <FormToggle+ currentValue={closeToTray}+ // Close-to-tray with no tray icon would hide the app with no way back.+ disabled={disableTray}+ onChange={setCloseToTray}+ />+ </CardOption>+ </Card>+ </div>);}@@ -71,33 +82,42 @@ function StartupSettings() {const [ disableTray ] = useTriliumOptionBool("disableTray");return (- <OptionsSection title={t("startup.title")}>- <OptionsRowWithToggle- name="launch-on-startup"- label={t("startup.launch_on_startup")}- description={t("startup.launch_on_startup_description")}- currentValue={launchOnStartup}- onChange={async enabled => {- await setLaunchOnStartup(enabled);- // Apply the change immediately so the user doesn't have to restart the app.- utils.reapplyLaunchOnStartup();- }}- />- <OptionsRowWithToggle- name="hide-on-auto-start"- label={t("startup.hide_on_auto_start")}- description={t("startup.hide_on_auto_start_description")}- currentValue={hideOnAutoStart}- // Only meaningful when launched at login, and the tray must exist to- // bring the hidden window back.- disabled={!launchOnStartup || disableTray}- onChange={async enabled => {- await setHideOnAutoStart(enabled);- // Re-tag the autostart entry so it launches hidden (or not).- utils.reapplyLaunchOnStartup();- }}- />- </OptionsSection>+ <div className="options-section">+ <Card heading={t("startup.title")}>+ <CardOption+ name="launch-on-startup"+ label={t("startup.launch_on_startup")}+ description={t("startup.launch_on_startup_description")}+ >+ <FormToggle+ currentValue={launchOnStartup}+ onChange={async enabled => {+ await setLaunchOnStartup(enabled);+ // Apply the change immediately so the user doesn't have to restart the app.+ utils.reapplyLaunchOnStartup();+ }}+ />+ </CardOption>++ <CardOption+ name="hide-on-auto-start"+ label={t("startup.hide_on_auto_start")}+ description={t("startup.hide_on_auto_start_description")}+ >+ <FormToggle+ currentValue={hideOnAutoStart}+ // Only meaningful when launched at login, and the tray must exist to+ // bring the hidden window back.+ disabled={!launchOnStartup || disableTray}+ onChange={async enabled => {+ await setHideOnAutoStart(enabled);+ // Re-tag the autostart entry so it launches hidden (or not).+ utils.reapplyLaunchOnStartup();+ }}+ />+ </CardOption>+ </Card>+ </div>);}@@ -115,37 +135,51 @@ function SearchEngineSettings() {}, []);return (- <OptionsSection title={t("search_engine.title")} description={t("search_engine.custom_search_engine_info")}>- <OptionsRow name="predefined-templates" label={t("search_engine.predefined_templates_label")}>- <div className="search-engine-templates">- {searchEngines.map(engine => (- <Badge- key={engine.url}- icon={engine.icon}- text={engine.name}- className={customSearchEngineUrl === engine.url ? "selected" : ""}- onClick={() => {- setCustomSearchEngineName(engine.name);- setCustomSearchEngineUrl(engine.url);- }}- />- ))}- </div>- </OptionsRow>+ <div className="options-section">+ <Card+ heading={t("search_engine.title")}+ description={t("search_engine.custom_search_engine_info")}+ >+ <CardOption label={t("search_engine.predefined_templates_label")}>+ <div className="search-engine-templates">+ {searchEngines.map(engine => (+ <Badge+ key={engine.url}+ icon={engine.icon}+ text={engine.name}+ className={customSearchEngineUrl === engine.url ? "selected" : ""}+ onClick={() => {+ setCustomSearchEngineName(engine.name);+ setCustomSearchEngineUrl(engine.url);+ }}+ />+ ))}+ </div>+ </CardOption>- <OptionsRow name="custom-name" label={t("search_engine.custom_name_label")}>- <FormTextBox- currentValue={customSearchEngineName} onBlur={setCustomSearchEngineName}- placeholder={t("search_engine.custom_name_placeholder")}- />- </OptionsRow>+ <CardOption+ className="desktop-search-name"+ name="custom-name"+ label={t("search_engine.custom_name_label")}+ >+ <FormTextBox+ currentValue={customSearchEngineName} onBlur={setCustomSearchEngineName}+ placeholder={t("search_engine.custom_name_placeholder")}+ />+ </CardOption>- <OptionsRow name="custom-url" label={t("search_engine.custom_url_label")} description={t("search_engine.custom_url_description")} stacked>- <FormTextBox- currentValue={customSearchEngineUrl} onBlur={setCustomSearchEngineUrl}- placeholder={t("search_engine.custom_url_placeholder")}- />- </OptionsRow>- </OptionsSection>+ <CardOption+ name="custom-url"+ label={t("search_engine.custom_url_label")}+ description={t("search_engine.custom_url_description")}+ stacked+ >+ <FormTextBox+ currentValue={customSearchEngineUrl} onBlur={setCustomSearchEngineUrl}+ placeholder={t("search_engine.custom_url_placeholder")}+ />+ </CardOption>+ </Card>+ </div>);}