Skip to content

Build your personal knowledge base with Trilium Notes

client/options/related settings component: switch to the new card component

Adorian Dorana35c03a62f79
diff --git a/apps/client/src/widgets/react/Card.css b/apps/client/src/widgets/react/Card.css
index 8ad1c567e0..afdd210f6d 100644
--- a/apps/client/src/widgets/react/Card.css
+++ b/apps/client/src/widgets/react/Card.css
@@ -86,6 +86,28 @@
}
}
+/* A segment that leads somewhere rather than holding a control: it keeps the page's own text colour
+ and gives up the underline, the chevron at its end standing in for both. */
+.tn-card-section-link {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ color: inherit;
+ text-decoration: none;
+ cursor: pointer;
+
+ &:hover {
+ color: inherit;
+ }
+}
+
+.tn-card-section-chevron {
+ flex-shrink: 0;
+ margin-inline-start: auto;
+ color: var(--muted-text-color);
+ font-size: 1.3em;
+}
+
.tn-card-option-stacked {
flex-direction: column;
align-items: stretch;
diff --git a/apps/client/src/widgets/react/Card.tsx b/apps/client/src/widgets/react/Card.tsx
index 5fc6dbd65b..06930061f6 100644
--- a/apps/client/src/widgets/react/Card.tsx
+++ b/apps/client/src/widgets/react/Card.tsx
@@ -66,8 +66,22 @@ export interface CardSectionProps {
subSections?: JSX.Element | JSX.Element[];
subSectionsVisible?: boolean;
highlightOnHover?: boolean;
- onAction?: () => void;
+ /** Called when the section is pressed. Handed the event, which a link's handler may need. */
+ onAction?: (event: MouseEvent) => void;
noPadding?: boolean;
+ /**
+ * Makes the section a segment that leads somewhere rather than one holding a control: it becomes
+ * an `<a>` carrying this address, highlights on hover, and reads a chevron on its trailing edge.
+ *
+ * A card of these is a card of anchors — do not mix them with ordinary segments, whose rounded
+ * first and last corners are matched by element type.
+ */
+ href?: string;
+ /**
+ * Opts the link out of the options dialog's contained navigation, which would otherwise swallow
+ * the click before {@link CardSectionProps.onAction} ever saw it. Ignored without an `href`.
+ */
+ noContainedNavigation?: boolean;
}
interface CardSectionContextType {
@@ -80,16 +94,28 @@ export function CardSection(props: {children: ComponentChildren} & CardSectionPr
const parentContext = useContext(CardSectionContext);
const nestingLevel = (parentContext && parentContext.nestingLevel + 1) ?? 0;
+ const className = clsx("tn-card-section", props.className, {
+ "tn-card-section-nested": nestingLevel > 0,
+ "tn-card-highlight-on-hover": props.highlightOnHover || props.onAction || props.href,
+ "tn-no-padding": props.noPadding
+ });
+ const style = {"--tn-card-section-nesting-level": (nestingLevel) ? nestingLevel : null};
+
return <>
- <section className={clsx("tn-card-section", props.className, {
- "tn-card-section-nested": nestingLevel > 0,
- "tn-card-highlight-on-hover": props.highlightOnHover || props.onAction,
- "tn-no-padding": props.noPadding
- })}
- style={{"--tn-card-section-nesting-level": (nestingLevel) ? nestingLevel : null}}
+ {props.href
+ ? <a className={clsx(className, "tn-card-section-link", "no-tooltip-preview")}
+ style={style}
+ href={props.href}
+ data-no-contained-navigation={props.noContainedNavigation ? "" : undefined}
onClick={props.onAction}>
- {props.children}
- </section>
+ {props.children}
+ <span className="tn-card-section-chevron bx bx-chevron-right" />
+ </a>
+ : <section className={className}
+ style={style}
+ onClick={props.onAction}>
+ {props.children}
+ </section>}
{props.subSectionsVisible && props.subSections &&
<CardSectionContext.Provider value={{nestingLevel}}>
diff --git a/apps/client/src/widgets/type_widgets/options/components/OptionsRow.css b/apps/client/src/widgets/type_widgets/options/components/OptionsRow.css
index 72a5ae78e5..4a64977f66 100644
--- a/apps/client/src/widgets/type_widgets/options/components/OptionsRow.css
+++ b/apps/client/src/widgets/type_widgets/options/components/OptionsRow.css
@@ -71,44 +71,13 @@
@container (max-width: 600px) {
/* Rows with compact inputs (toggles, icon buttons) keep the inline layout;
only rows with wide inputs (text boxes, selects) stack on narrow widths. */
- .option-row:not(.option-row-link):not(.stacked):not(:has(.switch-widget)):not(:has(.icon-action)) {
+ .option-row:not(.stacked):not(:has(.switch-widget)):not(:has(.icon-action)) {
flex-direction: column;
align-items: stretch;
gap: 8px;
}
- .option-row:not(.option-row-link):not(.stacked):not(:has(.switch-widget)):not(:has(.icon-action)) .option-row-input {
+ .option-row:not(.stacked):not(:has(.switch-widget)):not(:has(.icon-action)) .option-row-input {
width: 100%;
}
}
-
-.option-row-link {
- text-decoration: none;
- color: inherit;
- margin-inline: calc(-1 * var(--options-card-padding, 15px));
- padding-inline: var(--options-card-padding, 15px);
- transition: background-color 250ms ease-in-out;
-}
-
-.option-row-link:hover {
- background: var(--hover-item-background-color);
-}
-
-button.option-row-link {
- background: none;
- border: none;
- border-bottom: 1px solid var(--main-border-color);
- width: calc(100% + 2 * var(--options-card-padding, 15px));
- text-align: left;
- font: inherit;
- cursor: pointer;
-}
-
-button.option-row-link:last-child {
- border-bottom: none;
-}
-
-button.option-row-link:disabled {
- opacity: 0.6;
- pointer-events: none;
-}
diff --git a/apps/client/src/widgets/type_widgets/options/components/OptionsRow.tsx b/apps/client/src/widgets/type_widgets/options/components/OptionsRow.tsx
index 39ef9bb459..e30d3a6007 100644
--- a/apps/client/src/widgets/type_widgets/options/components/OptionsRow.tsx
+++ b/apps/client/src/widgets/type_widgets/options/components/OptionsRow.tsx
@@ -35,35 +35,6 @@ export default function OptionsRow({ name, label, description, children, centere
);
}
-interface OptionsRowLinkProps {
- label: string;
- description?: string;
- href: string;
- onClick?: (e: MouseEvent) => void;
- /** Opts out of the options dialog's contained link navigation (which runs before `onClick`),
- * so that `onClick` gets to handle the click itself. */
- noContainedNavigation?: boolean;
-}
-
-export function OptionsRowLink({ label, description, href, onClick, noContainedNavigation }: OptionsRowLinkProps) {
- return (
- <a
- href={href}
- className="option-row option-row-link no-tooltip-preview"
- onClick={onClick}
- data-no-contained-navigation={noContainedNavigation ? "" : undefined}
- >
- <div className="option-row-label">
- <label style={{ cursor: "pointer" }}>{label}</label>
- {description && <small className="option-row-description">{description}</small>}
- </div>
- <div className="option-row-input">
- <span className="bx bx-chevron-right" />
- </div>
- </a>
- );
-}
-
interface OptionsRowWithToggleProps {
name: string;
label: ComponentChildren;
diff --git a/apps/client/src/widgets/type_widgets/options/components/RelatedSettings.tsx b/apps/client/src/widgets/type_widgets/options/components/RelatedSettings.tsx
index 83c9079f5b..e10a86742f 100644
--- a/apps/client/src/widgets/type_widgets/options/components/RelatedSettings.tsx
+++ b/apps/client/src/widgets/type_widgets/options/components/RelatedSettings.tsx
@@ -1,8 +1,7 @@
import appContext from "../../../../components/app_context";
import { t } from "../../../../services/i18n";
+import { Card, CardOption } from "../../../react/Card";
import type { OptionPages } from "../../ContentWidget";
-import { OptionsRowLink } from "./OptionsRow";
-import OptionsSection from "./OptionsSection";
interface RelatedSettingsItem {
title: string;
@@ -35,31 +34,33 @@ export default function RelatedSettings({ items, title }: RelatedSettingsProps)
}
return (
- <OptionsSection title={title ?? t("settings.related_settings")}>
- {filteredItems.map((item) => {
- const { targetPage, targetNoteId, onClick } = item;
- return (
- <OptionsRowLink
- key={targetPage ?? targetNoteId}
- label={item.title}
- description={item.description}
- href={targetNoteId
- ? `#root/_hidden/${targetNoteId}`
- : `#root/_hidden/_options/${targetPage}`}
- noContainedNavigation={!!targetNoteId || !!onClick}
- onClick={onClick ?? (targetNoteId
- ? (e) => {
- // Hidden-subtree config notes open hoisted, in a tree-sidebar popup.
- // stopPropagation keeps the global `a` click handler
- // (link.ts `goToLink`) from navigating by href instead.
- e.preventDefault();
- e.stopPropagation();
- void appContext.triggerCommand("openInTreePopup", { noteIdOrPath: targetNoteId, hoistedNoteId: targetNoteId });
- }
- : undefined)}
- />
- );
- })}
- </OptionsSection>
+ <div className="options-section">
+ <Card heading={title ?? t("settings.related_settings")}>
+ {filteredItems.map((item) => {
+ const { targetPage, targetNoteId, onClick } = item;
+ return (
+ <CardOption
+ key={targetPage ?? targetNoteId}
+ label={item.title}
+ description={item.description}
+ href={targetNoteId
+ ? `#root/_hidden/${targetNoteId}`
+ : `#root/_hidden/_options/${targetPage}`}
+ noContainedNavigation={!!targetNoteId || !!onClick}
+ onAction={onClick ?? (targetNoteId
+ ? (e) => {
+ // Hidden-subtree config notes open hoisted, in a tree-sidebar popup.
+ // stopPropagation keeps the global `a` click handler
+ // (link.ts `goToLink`) from navigating by href instead.
+ e.preventDefault();
+ e.stopPropagation();
+ void appContext.triggerCommand("openInTreePopup", { noteIdOrPath: targetNoteId, hoistedNoteId: targetNoteId });
+ }
+ : undefined)}
+ />
+ );
+ })}
+ </Card>
+ </div>
);
}