Skip to content

Build your personal knowledge base with Trilium Notes

feat(attributes): draw the rows as menu items on a phone

Elian Doran92b490c87a02
diff --git a/apps/client/src/widgets/dialogs/note_attributes.css b/apps/client/src/widgets/dialogs/note_attributes.css
index a0c9f89c52..bc4c26fec8 100644
--- a/apps/client/src/widgets/dialogs/note_attributes.css
+++ b/apps/client/src/widgets/dialogs/note_attributes.css
@@ -67,4 +67,41 @@
.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.
+ *
+ * `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 {
+ /* 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. */
+ .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. */
+ background: none !important;
+ box-shadow: none;
+ min-width: 0;
+ }
+
+ .modal-dialog {
+ height: 100%;
+ }
+
+ .modal-content {
+ height: 100%;
+ }
+
+ .modal-body {
+ flex: 1 1 auto;
+ min-height: 0;
+ overflow-y: auto;
+ }
}
diff --git a/apps/client/src/widgets/react/FormList.tsx b/apps/client/src/widgets/react/FormList.tsx
index 022aeae965..6bb0a839b6 100644
--- a/apps/client/src/widgets/react/FormList.tsx
+++ b/apps/client/src/widgets/react/FormList.tsx
@@ -109,6 +109,8 @@ export interface FormListBadge {
export interface FormListItemOpts {
children: ComponentChildren;
icon?: string;
+ /** Extra class for the icon itself, e.g. to hang a marker off its corner. */
+ iconClassName?: string;
value?: string;
title?: string;
active?: boolean;
@@ -134,7 +136,7 @@ const TOOLTIP_CONFIG: Partial<Tooltip.Options> = {
animation: false
};
-export function FormListItem({ className, icon, value, title, active, disabled, checked, container, onClick, selected, rtl, triggerCommand, description, itemRef: externalItemRef, ...contentProps }: FormListItemOpts) {
+export function FormListItem({ className, icon, iconClassName, value, title, active, disabled, checked, container, onClick, selected, rtl, triggerCommand, description, itemRef: externalItemRef, ...contentProps }: FormListItemOpts) {
const itemRef = useSyncedRef<HTMLLIElement>(externalItemRef, null);
if (checked) {
@@ -153,7 +155,7 @@ export function FormListItem({ className, icon, value, title, active, disabled,
data-trigger-command={triggerCommand}
dir={rtl ? "rtl" : undefined}
>
- <Icon icon={icon} />&nbsp;
+ <Icon icon={icon} className={iconClassName} />&nbsp;
{description ? (
<div>
<FormListContent description={description} disabled={disabled} {...contentProps} />
diff --git a/apps/client/src/widgets/sidebar/AttributeList.tsx b/apps/client/src/widgets/sidebar/AttributeList.tsx
index 8b64e73d81..a795b0f6d5 100644
--- a/apps/client/src/widgets/sidebar/AttributeList.tsx
+++ b/apps/client/src/widgets/sidebar/AttributeList.tsx
@@ -13,8 +13,10 @@ import attributes, { isBuiltinAttribute } from "../../services/attributes";
import dialog from "../../services/dialog";
import { t } from "../../services/i18n";
import server from "../../services/server";
+import { isMobile } from "../../services/utils";
import { AttributeDetail, AttributeDetailOpts, AttrType, DEFINITION_TYPES, getAttrType, RELATION_DEFINITION_TYPE } from "../attribute_widgets/attribute_detail";
import ActionButton from "../react/ActionButton";
+import { FormListItem } from "../react/FormList";
import HelpButton from "../react/HelpButton";
import { useActiveNoteContext, useTriliumEvent } from "../react/hooks";
import Icon from "../react/Icon";
@@ -282,7 +284,11 @@ interface AttributeRowListProps {
function AttributeRowList({ rows, activeAttribute, readOnly, onOpen, onDelete }: AttributeRowListProps) {
function renderRows(group: AttributeEntry[]) {
return (
- <ul class="attribute-rows">
+ // The rows are menu items on a phone (see AttributeRow), and the theme dresses a menu item
+ // through the menu around it — so the list stands in as that menu, the way the other lists
+ // of menu items outside a dropdown do (`dropdown-menu static show`, as in the code-note
+ // switcher). Static: it opens nowhere and is positioned by nothing.
+ <ul class={clsx("attribute-rows", IS_MOBILE && "dropdown-menu tn-dropdown-menu static show")}>
{group.map(({ attribute, isOwned, isSystem }, index) => (
<AttributeRow
key={attribute.attributeId ?? `new-${index}`}
@@ -330,24 +336,17 @@ function AttributeRow({ attribute, active, isSystem, showOwner, onOpen, onDelete
const rowRef = useRef<HTMLLIElement>(null);
const attrType = getAttributeKind(attribute);
const marker = getKindMarker(attribute, attrType, isSystem);
+ const kindIcon = getKindIcon(attribute, attrType);
+ const rowClass = clsx("attribute-row", active && "active");
- return (
- <li
- ref={rowRef}
- class={clsx("attribute-row", active && "active")}
- title={KIND_TITLES[attrType]}
- onClick={(e) => {
- // Keep the container's closing handler from undoing this.
- e.stopPropagation();
- onOpen(rowRef.current, e);
- }}
- >
- {/* The kind is the icon, and what is worth saying about it beyond that is a badge on its
- corner: its own tooltip names it, the badge being the only thing that says so. */}
- <span class={clsx("attribute-kind", marker?.class)} title={marker?.title}>
- <Icon icon={getKindIcon(attribute, attrType)} />
- </span>
+ function open(e: MouseEvent) {
+ // Keep the container's closing handler from undoing this.
+ e.stopPropagation();
+ onOpen(rowRef.current, e);
+ }
+ const contents = (
+ <>
<span class="attribute-name">{getDisplayName(attribute, attrType)}</span>
<AttributeValue attribute={attribute} attrType={attrType} />
@@ -375,10 +374,52 @@ function AttributeRow({ attribute, active, isSystem, showOwner, onOpen, onDelete
}}
/>
)}
+ </>
+ );
+
+ // On a phone the rows are menu items, drawn as everything else the note's menu leads to is: the
+ // panel is reached from that menu (see the note attributes modal), and a row there is something
+ // pressed with a thumb rather than pointed at.
+ if (IS_MOBILE) {
+ return (
+ <FormListItem
+ itemRef={rowRef}
+ className={rowClass}
+ icon={kindIcon}
+ // The badge hangs off the icon's own corner here, there being no wrapper to hang it on.
+ iconClassName={clsx("attribute-kind", marker?.class)}
+ title={[ KIND_TITLES[attrType], marker?.title ].filter(Boolean).join(" · ")}
+ onClick={open}
+ >
+ {contents}
+ </FormListItem>
+ );
+ }
+
+ return (
+ <li
+ ref={rowRef}
+ class={rowClass}
+ title={KIND_TITLES[attrType]}
+ onClick={open}
+ >
+ {/* The kind is the icon, and what is worth saying about it beyond that is a badge on its
+ corner: its own tooltip names it, the badge being the only thing that says so. */}
+ <span class={clsx("attribute-kind", marker?.class)} title={marker?.title}>
+ <Icon icon={kindIcon} />
+ </span>
+
+ {contents}
</li>
);
}
+/**
+ * Whether a row is a menu item, read once: what the app is running on does not change under it, and
+ * the rows are redrawn on every keystroke the popup takes.
+ */
+const IS_MOBILE = isMobile();
+
/**
* What the attribute is, as an icon. A definition takes the icon of the field it sets up, the same one
* the popup offers that field under — it needs no marker of its own, being only ever listed in a card