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
feat(attributes): head each section with a settings card on a phone
Elian Dorana018c5334192
diff --git a/apps/client/src/widgets/dialogs/note_attributes.css b/apps/client/src/widgets/dialogs/note_attributes.cssindex bc4c26fec8..d419cdd0c7 100644--- a/apps/client/src/widgets/dialogs/note_attributes.css+++ b/apps/client/src/widgets/dialogs/note_attributes.css@@ -1,34 +1,20 @@/*- * The panel lays its sections out in cards, which the right pane is what dresses (`#right-pane .card`- * in style.css, and RightPanelContainer.css over it) — none of which reaches a modal, where the cards- * would otherwise come out as Bootstrap draws them: bordered, rounded boxes of their own. Dressed here- * as the pane dresses them, one section under the next, each headed by a line that is pressed to put it- * away.+ * The panel lays its sections out in cards, which the right pane is what dresses (`#right-pane .card` in+ * style.css, and RightPanelContainer.css over it) — none of which reaches a modal, where the cards would+ * otherwise come out as Bootstrap draws them: bordered, rounded boxes of their own. What follows dresses+ * them for a modal instead, and dresses them differently on a phone (see the two blocks below).*/.modal.note-attributes-modal {.modal-body {padding-block: 0;}- .card {- border: 0;- border-bottom: 1px solid var(--main-border-color);- border-radius: 0;- background: transparent;-- &:last-of-type {- border-bottom: 0;- }- }-.card-header {display: flex;align-items: center;justify-content: flex-start;- padding: 4px 0;border: 0;background: transparent;- cursor: pointer;--icon-button-size: 26px;.icon-action {@@ -52,13 +38,35 @@display: flex;align-items: center;}+}++/*+ * On a desktop the sections are the pane's: transparent, one under the next, each headed by a line that+ * is pressed to fold it away.+ */+body.desktop .modal.note-attributes-modal {+ .card {+ border: 0;+ border-bottom: 1px solid var(--main-border-color);+ border-radius: 0;+ background: transparent;++ &:last-of-type {+ border-bottom: 0;+ }+ }++ .card-header {+ padding: 4px 0;+ cursor: pointer;+ }.card.collapsed .card-header > .icon-action {transform: rotate(-90deg);}- /* The one section a note has, having nothing to be put away in favour of (see RightPanelWidget),- has no chevron either — so its title starts where the others' do. */+ /* The one section a note has, having nothing to be put away in favour of (see RightPanelWidget), has+ no chevron either — so its title starts where the others' do. */.card.not-collapsible .card-header {cursor: default;padding-inline-start: 8px;@@ -67,28 +75,55 @@.card-body {padding: 0 0 8px;}-}/*- * A page rather than a sheet: the sections are the whole of what there is to read here, and a sheet- * sized to them jumps between a hand's width and a screen's as they are put away and brought back.+ * On a phone the sections are the settings pages' own cards (OptionsSection, see AttributeList.tsx): a+ * title over a surface, with nothing to fold away — the modal is a page of its own, so a section has+ * nothing to be put away in favour of. All that is left here is fitting the rows to that card, the rows+ * being full-width menu items where a settings card holds inset controls.*- * `isFullPageOnMobile` asks for the height, and being scrollable with it takes it away again — the two- * generic rules collide (`height: 100%` against `height: unset`, at equal weight, in that order in- * style.css), so the height is claimed here and passed down: the content fills the dialog, and the body- * takes what the header leaves and scrolls the sections within it.+ * A page rather than a sheet, too: the sections are the whole of what there is to read here, and a sheet+ * sized to them would stand as tall as whatever the note happens to carry. `isFullPageOnMobile` asks for+ * the height, and being scrollable with it takes it away again — the two generic rules collide+ * (`height: 100%` against `height: unset`, at equal weight, in that order in style.css) — so the height+ * is claimed here and passed down: the content fills the dialog, and the body takes what the header+ * leaves and scrolls the sections within it.*/body.mobile .modal.note-attributes-modal {+ .options-section-card {+ /* The rows bring their own padding as menu items, and reach the card's edges — so the card+ spends none of its own on them, and cuts them to its corners. */+ --options-card-padding: 0;++ padding-block: 8px;+ overflow: hidden;+ }+/* The rows are menu items and their list stands in as the menu that dresses them (see- AttributeList.tsx), but it is not a menu that opens: it sits in a card, so it keeps the items and- none of the surface a floating menu would bring with it. */+ AttributeList.tsx), but it is not a menu that opens: it sits in a card, and keeps the items alone+ out of everything a floating menu would otherwise bring with it. */.attribute-rows.dropdown-menu {- /* Overriding an `!important` of its own (style.css paints every menu), as the code-note- switcher does for the same reason: a list of menu items that is not a menu. */+ /* Overriding an `!important` of its own (style.css paints every menu), as the code-note switcher+ does for the same reason: a list of menu items that is not a menu. */background: none !important;box-shadow: none;min-width: 0;+ padding: 0;++ /* The card is the surface now, so the rows keep only what tells them apart from one another: the+ dividers between them, and whatever a row is being pressed or read in. */+ .attribute-row {+ background: transparent;+ border-radius: 0;+ }+ }++ /* What separates the note's own names from the ones Trilium reads for itself, drawn between two lists+ of rows: inset to the rows' own text rather than run to the card's edges, where it would read as+ the end of the card. */+ .attribute-rows-divider {+ margin-inline: 1em;}.modal-dialog {diff --git a/apps/client/src/widgets/sidebar/AttributeList.tsx b/apps/client/src/widgets/sidebar/AttributeList.tsxindex a795b0f6d5..a540a9fef8 100644--- a/apps/client/src/widgets/sidebar/AttributeList.tsx+++ b/apps/client/src/widgets/sidebar/AttributeList.tsx@@ -2,6 +2,7 @@ import "./AttributeList.css";import { promotedAttributeDefinitionParser } from "@triliumnext/commons";import clsx from "clsx";+import { ComponentChildren } from "preact";import { createPortal } from "preact/compat";import { useContext, useEffect, useRef, useState } from "preact/hooks";@@ -24,6 +25,7 @@ import NoItems from "../react/NoItems";import NoteLink from "../react/NoteLink";import { ParentComponent } from "../react/react_utils";import { ATTRIBUTE_HELP_PAGE } from "../ribbon/components/AttributeHelp";+import OptionsSection from "../type_widgets/options/components/OptionsSection";import RightPanelWidget, { CollapsibleWidgets } from "./RightPanelWidget";/**@@ -168,7 +170,7 @@ export default function AttributeList() {counts this whole panel as one widget (see RightPanelContainer), being one entry in itslist. Down to a single card, collapsing it away is not on offer. */}<CollapsibleWidgets.Provider value={shownCards > 1}>- <RightPanelWidget+ <AttributeSectionid="attributes"title={t("attribute_list_panel.owned", { count: sections.owned.length })}grow@@ -192,21 +194,21 @@ export default function AttributeList() {<NoItems icon="bx bx-hash" text={t("attribute_list_panel.no_attributes")} />)}</div>- </RightPanelWidget>+ </AttributeSection>{sections.inherited.length > 0 && (- <RightPanelWidget+ <AttributeSectionid="attributes-inherited"title={t("attribute_list_panel.inherited", { count: sections.inherited.length })}><div class="attribute-list-panel" onClick={() => setDetail(null)}><AttributeRowList rows={sections.inherited} {...rowProps} /></div>- </RightPanelWidget>+ </AttributeSection>)}{sections.definitions.length > 0 && (- <RightPanelWidget+ <AttributeSectionid="attributes-definitions"title={t("attribute_list_panel.definitions", { count: sections.definitions.length })}buttons={note && (@@ -220,18 +222,18 @@ export default function AttributeList() {<div class="attribute-list-panel" onClick={() => setDetail(null)}><AttributeRowList rows={sections.definitions} {...rowProps} /></div>- </RightPanelWidget>+ </AttributeSection>)}{internalRows.length > 0 && (- <RightPanelWidget+ <AttributeSectionid="attributes-internal"title={t("attribute_list_panel.internal", { count: internalRows.length })}><div class="attribute-list-panel" onClick={() => setDetail(null)}><AttributeRowList rows={internalRows} readOnly {...rowProps} /></div>- </RightPanelWidget>+ </AttributeSection>)}</CollapsibleWidgets.Provider>@@ -261,6 +263,33 @@ export default function AttributeList() {);}+interface AttributeSectionProps {+ /** What the right pane remembers the section by, collapsed state and all. */+ id: string;+ title: string;+ children: ComponentChildren;+ buttons?: ComponentChildren;+ /** Passed on to {@link RightPanelWidget}, which is the only host that has room to give. */+ grow?: boolean;+}++/**+ * One section, drawn as the layout it is in draws a titled group of things: a card of the right pane on+ * a desktop, foldable and remembered as folded; the same card the settings pages are built from on a+ * phone, where the panel is a page of its own and a title is read rather than pressed.+ */+function AttributeSection({ id, title, children, buttons, grow }: AttributeSectionProps) {+ if (IS_MOBILE) {+ return <OptionsSection title={title} actions={buttons}>{children}</OptionsSection>;+ }++ return (+ <RightPanelWidget id={id} title={title} buttons={buttons} grow={grow}>+ {children}+ </RightPanelWidget>+ );+}+interface AttributeRowListProps {rows: AttributeEntry[];/** The attribute the detail popup is showing, marked as such in the list. */diff --git a/apps/client/src/widgets/type_widgets/options/components/OptionsSection.css b/apps/client/src/widgets/type_widgets/options/components/OptionsSection.cssindex d44beca64d..4bcda2ced9 100644--- a/apps/client/src/widgets/type_widgets/options/components/OptionsSection.css+++ b/apps/client/src/widgets/type_widgets/options/components/OptionsSection.css@@ -1,3 +1,10 @@+/* The header pushes its first button to the end of the title line (`margin-inline-start: auto` in+ theme-next/pages.css, which this out-specifies as that rule reaches every button); the rest follow it+ rather than each being pushed away from the last in turn. */+.options-section:not(.tn-no-card) .options-section-header .icon-action ~ .icon-action {+ margin-inline-start: 0;+}+.options-section-card {.admonition {margin: calc(var(--options-card-padding) * -1) calc(var(--options-card-padding) * -1) 0 calc(var(--options-card-padding) * -1);diff --git a/apps/client/src/widgets/type_widgets/options/components/OptionsSection.tsx b/apps/client/src/widgets/type_widgets/options/components/OptionsSection.tsxindex 2e2bee1854..fc0e3cf447 100644--- a/apps/client/src/widgets/type_widgets/options/components/OptionsSection.tsx+++ b/apps/client/src/widgets/type_widgets/options/components/OptionsSection.tsx@@ -13,13 +13,16 @@ interface OptionsSectionProps {style?: CSSProperties;className?: string;helpUrl?: string;+ /** Buttons for the section's own header, beside the help button — e.g. one that adds to the card. */+ actions?: ComponentChildren;}-export default function OptionsSection({ title, description, children, noCard, className, helpUrl, ...rest }: OptionsSectionProps) {- const header = (title || helpUrl) && (+export default function OptionsSection({ title, description, children, noCard, className, helpUrl, actions, ...rest }: OptionsSectionProps) {+ const header = (title || helpUrl || actions) && (<div className="options-section-header">{title && <h4>{title}</h4>}{helpUrl && <HelpButton helpPage={helpUrl} />}+ {actions}</div>);