Skip to content

Build your personal knowledge base with Trilium Notes

feat(attachments): mark an attachment's icon as an attachment's

Elian Doran0db1b91ae88b
diff --git a/apps/client/src/widgets/type_widgets/Attachment.css b/apps/client/src/widgets/type_widgets/Attachment.css
index d66d7e1e87..fa896d2110 100644
--- a/apps/client/src/widgets/type_widgets/Attachment.css
+++ b/apps/client/src/widgets/type_widgets/Attachment.css
@@ -84,6 +84,11 @@
flex-wrap: wrap;
}
+ /* The card is what the icon lies on here, so that is what its paperclip is knocked out of. */
+ .attachment-icon-marker {
+ --attachment-icon-marker-tint: var(--card-background-color, transparent);
+ }
+
.attachment-title {
/* A zero basis, not `auto`: the row wraps, and a title measured at its own width — these are
hostnames and URLs — would take the whole line and send the menu below it. */
@@ -206,10 +211,43 @@
the media type's where it only says the reader put it there. Sized and placed as the note icon on a
collection's cards is, since the two sit in the same kind of header. */
.attachment-icon {
+ position: relative;
+ display: inline-flex;
flex-shrink: 0;
font-size: 1.2em;
}
+/* The paperclip overprinted on the corner, saying the thing the mark underneath cannot: this belongs to
+ a note rather than being one.
+
+ Built the way the tree builds a protected note's lock (`theme-next/shell.css`): held in the corner
+ rather than hung off it, knocked out of the glyph by a disc of the surface behind, and left in the
+ icon's own colour. Nothing of its own — no ring, no fill, no padding around it — so it reads as part
+ of the mark it qualifies rather than as something stuck on top.
+
+ The disc has to be the surface the icon is actually lying on, as the tree's is the left pane's own
+ colour. It cannot simply *be* `--card-background-color`: that is a tint of a few percent alpha, and the
+ glyph's strokes would show through the paperclip's hole. So the tint is composited over the opaque
+ window background the way the card itself composites it — a gradient of one flat colour, which is the
+ only way to lay a second background layer over a background colour. Where there is no card, the tint is
+ transparent and the disc is the window's background alone. */
+.attachment-icon-marker {
+ --attachment-icon-marker-tint: transparent;
+
+ position: absolute;
+ bottom: 0;
+ inset-inline-end: 0;
+ transform: translateX(25%);
+ font-size: 0.6em;
+ border-radius: 50%;
+ background-color: var(--main-background-color);
+ background-image: linear-gradient(var(--attachment-icon-marker-tint), var(--attachment-icon-marker-tint));
+}
+
+body[dir=rtl] .attachment-icon-marker {
+ transform: translateX(-25%);
+}
+
.attachment-title-line {
display: flex;
align-items: center;
diff --git a/apps/client/src/widgets/type_widgets/Attachment.tsx b/apps/client/src/widgets/type_widgets/Attachment.tsx
index 46b53c723f..226524db04 100644
--- a/apps/client/src/widgets/type_widgets/Attachment.tsx
+++ b/apps/client/src/widgets/type_widgets/Attachment.tsx
@@ -294,7 +294,7 @@ function AttachmentInfo({ attachment, isFullDetail, ownerNote, noteContext, view
processUrl: `ocr/process-attachment/${attachment.attachmentId}`
}) : undefined}
/>
- <Icon className="attachment-icon" icon={attachmentIcon(attachment.role, attachment.mime)} />
+ <AttachmentIcon attachment={attachment} />
<h4 className="attachment-title">
{!isFullDetail ? (
<NoteLink
@@ -352,6 +352,24 @@ function AttachmentInfo({ attachment, isFullDetail, ownerNote, noteContext, view
);
}
+/**
+ * What the attachment is, ahead of its name.
+ *
+ * Two marks rather than one. The inner is the content's, or the role's where the role is the app's own
+ * doing — but a PDF's mark is the same one a PDF note wears, and a card carrying it alone reads as a note
+ * that happens to be listed here. So it is overprinted with the paperclip the app uses for attachments
+ * everywhere else, which says the one thing the content mark cannot: this belongs to a note rather than
+ * being one.
+ */
+function AttachmentIcon({ attachment }: { attachment: FAttachment }) {
+ return (
+ <span className="attachment-icon">
+ <Icon icon={attachmentIcon(attachment.role, attachment.mime)} />
+ <Icon className="attachment-icon-marker" icon="bx bx-paperclip" />
+ </span>
+ );
+}
+
/**
* Marks an attachment the cleanup job has scheduled for erasure. Pinned over the corner of its own card
* rather than given a row of its own: the countdown is a state the attachment is in, not something to act