Skip to content

Build your personal knowledge base with Trilium Notes

style(search): shade the attribute badge's key as a keyboard shortcut

Elian Doran9cfa1e9975d8
diff --git a/apps/client/src/widgets/react/Badge.css b/apps/client/src/widgets/react/Badge.css
index d1b55c6243..24e7cf42e0 100644
--- a/apps/client/src/widgets/react/Badge.css
+++ b/apps/client/src/widgets/react/Badge.css
@@ -56,16 +56,20 @@
}
/*
- * An attribute a search matched: its kind's icon and its name, then its value in a tinted segment
- * reaching the badge's end. Muted unless the host sets `--color`.
+ * An attribute a search matched: its kind's icon and its name in a key shaded as a keyboard shortcut,
+ * then its value. Squared off as the app's other chips (`.tn-chip`), a pill being for a single token.
*/
.ext-badge.attribute-badge {
overflow: hidden;
- border-color: var(--color, var(--muted-text-color));
+ padding-inline: 0;
+ border-radius: 6px;
+ /* The line the note autocomplete's footer and dividers are drawn with. */
+ border-color: var(--attribute-badge-line-color, var(--main-border-color));
color: var(--color, var(--muted-text-color));
- &.has-value {
- padding-inline-end: 0;
+ /* On a highlighted row's background the border color fades out, so the lines take the text's. */
+ .dropdown-item:is(:hover, :focus, .tn-menu-active) & {
+ --attribute-badge-line-color: color-mix(in srgb, var(--main-text-color) 25%, transparent);
}
/* Centered by the badge, so it takes none of the Next theme's `.dropdown-item .tn-icon` offset. */
@@ -80,13 +84,28 @@
.text {
display: flex;
- align-items: center;
min-width: 0;
}
- .attribute-badge-name {
+ .attribute-badge-key {
+ display: flex;
+ align-items: center;
flex-shrink: 0;
+ padding-inline: 6px 8px;
+ /* The shade and text of a button's keyboard shortcut (`button.btn kbd` in forms.css). */
+ background: var(
+ --cmd-button-keyboard-shortcut-background,
+ color-mix(in srgb, var(--color, var(--muted-text-color)) 15%, transparent)
+ );
+ color: var(--cmd-button-keyboard-shortcut-color, var(--main-text-color));
+ }
+
+ /* A long name leaves room for the value beside it. */
+ &.has-value .attribute-badge-key {
max-width: 50%;
+ }
+
+ .attribute-badge-name {
overflow: hidden;
text-overflow: ellipsis;
}
@@ -94,12 +113,9 @@
.attribute-badge-value {
display: flex;
align-items: center;
- align-self: stretch;
min-width: 0;
- margin-inline-start: 6px;
padding-inline: 6px 8px;
- border-inline-start: 1px solid var(--color, var(--muted-text-color));
- background: color-mix(in srgb, var(--color, var(--muted-text-color)) 15%, transparent);
+ border-inline-start: 1px solid var(--attribute-badge-line-color, var(--main-border-color));
color: var(--main-text-color);
> span {
diff --git a/apps/client/src/widgets/react/Badge.spec.tsx b/apps/client/src/widgets/react/Badge.spec.tsx
index 1206f50169..f28fb857c3 100644
--- a/apps/client/src/widgets/react/Badge.spec.tsx
+++ b/apps/client/src/widgets/react/Badge.spec.tsx
@@ -37,11 +37,12 @@ describe("AttributeSnippetBadges", () => {
const [ tag, template, cut ] = container.querySelectorAll<HTMLElement>(".attrs > .ext-badge.outline");
expect(tag.classList.contains("attribute-badge")).toBe(true);
- expect(tag.querySelector(".tn-icon")?.className).toBe("bx bx-hash tn-icon");
- expect(tag.querySelector(".attribute-badge-name")?.innerHTML).toBe("<b>tag</b>");
+ expect(tag.querySelector(".attribute-badge-key > .tn-icon")?.className).toBe("bx bx-hash tn-icon");
+ expect(tag.querySelector(".attribute-badge-key > .attribute-badge-name")?.innerHTML).toBe("<b>tag</b>");
expect(tag.querySelector(".attribute-badge-value")).toBeNull();
- expect(template.querySelector(".tn-icon")?.className).toBe("bx bx-transfer tn-icon");
+ expect(template.querySelector(".attribute-badge-key > .tn-icon")?.className)
+ .toBe("bx bx-transfer tn-icon");
expect(template.querySelector(".attribute-badge-name")?.textContent).toBe("template");
expect(template.querySelector(".attribute-badge-value")?.textContent).toBe("Book");
expect(template.classList.contains("has-value")).toBe(true);
diff --git a/apps/client/src/widgets/react/Badge.tsx b/apps/client/src/widgets/react/Badge.tsx
index 5dfb22537f..2390f7c9f0 100644
--- a/apps/client/src/widgets/react/Badge.tsx
+++ b/apps/client/src/widgets/react/Badge.tsx
@@ -80,9 +80,12 @@ export function AttributeSnippetBadges({ snippet, className }: { snippet: string
key={index}
outline
className={clsx("attribute-badge", { "has-value": !!attribute.value })}
- icon={attribute.icon}
text={<>
- <RawHtml className="attribute-badge-name" html={attribute.name} />
+ {/* The icon goes with the name, the two sharing the key's shading. */}
+ <span className="attribute-badge-key">
+ <Icon icon={attribute.icon} />
+ <RawHtml className="attribute-badge-name" html={attribute.name} />
+ </span>
{attribute.value && (
// The segment spans the badge's height; the text in it can end in an
// ellipsis, which a flex container's own text cannot.