Skip to content

Build your personal knowledge base with Trilium Notes

feat(table): show a single colour as the chip a set of colours wears

Elian Doran018af8035fad
diff --git a/apps/client/src/widgets/attribute_widgets/label_value_display.tsx b/apps/client/src/widgets/attribute_widgets/label_value_display.tsx
index 63d3a7112f..df5d85b941 100644
--- a/apps/client/src/widgets/attribute_widgets/label_value_display.tsx
+++ b/apps/client/src/widgets/attribute_widgets/label_value_display.tsx
@@ -78,10 +78,9 @@ function renderFlag(value: string) {
}
/**
- * A colour as the square it is read as where the colour cannot be the whole ground: a single-valued
- * cell, whose surface is the row's — flooding it would hide striping, hover and selection — and a
- * chip being edited, which also holds the button removing it, a mark no user-picked ground can be
- * trusted to keep visible. A chip only being read holds neither, and wears the colour itself.
+ * A colour as the square it is read as where the colour cannot be the whole ground: a chip being
+ * edited, which also holds the button removing it, a mark no user-picked ground can be trusted to
+ * keep visible. A chip only being read holds nothing, and wears the colour itself.
*
* The colour is the one thing about the swatch that cannot be told beforehand; its shape and size are
* its class's. A value naming no colour is dropped by the browser, leaving the outline behind rather
diff --git a/apps/client/src/widgets/collections/table/columns.spec.ts b/apps/client/src/widgets/collections/table/columns.spec.ts
index 802fe2aa3a..f0d741f59b 100644
--- a/apps/client/src/widgets/collections/table/columns.spec.ts
+++ b/apps/client/src/widgets/collections/table/columns.spec.ts
@@ -243,7 +243,7 @@ describe("buildColumnDefinitions — colour columns", () => {
expect(success).toHaveBeenCalledWith("");
});
- it("shows a colour as a swatch, naming it in the tooltip, and an unset one as nothing", () => {
+ it("shows a colour as the chip a set of colours wears, and an unset one as nothing", () => {
const [ column ] = buildColumnDefinitions({
info: [ { name: "tint", type: "color" } ],
movableRows: false,
@@ -253,21 +253,23 @@ describe("buildColumnDefinitions — colour columns", () => {
const formatter = column?.formatter;
if (typeof formatter !== "function") throw new Error("expected a formatter of its own");
- const format = (value: unknown) =>
- formatter({ getValue: () => value } as CellComponent, {}, () => {}) as HTMLElement;
+ const chipOf = (value: unknown) => (
+ formatter({ getValue: () => value } as CellComponent, {}, () => {}) as HTMLElement
+ ).querySelector<HTMLElement>(".label-color-chip");
- // Filling the cell instead would paint over the row's own striping, hover and selection.
- const swatch = format("#ff2e88");
- expect(swatch.className).toBe("label-color-swatch");
- expect(swatch.style.backgroundColor).toBe("#ff2e88");
- expect(swatch.title).toBe("#ff2e88");
+ // A chip of the colour rather than a filled cell, which would paint over the row's own
+ // striping, hover and selection.
+ const chip = chipOf("#ff2e88");
+ expect(chip?.style.backgroundColor).toBe("#ff2e88");
+ expect(chip?.title).toBe("#ff2e88");
- // A cell holds whatever the label does: text naming no colour keeps the swatch, which the
- // browser leaves unpainted, and says what is stored where it can be read.
- expect(format("nonsense").title).toBe("nonsense");
+ // A cell holds whatever the label does: text naming no colour keeps the chip, whose ground
+ // the browser refuses, and says what is stored where it can be read.
+ expect(chipOf("nonsense")?.title).toBe("nonsense");
+ // An unset cell holds no colour at all, so it wears no chip either.
for (const empty of [ "", undefined, null ]) {
- expect(format(empty).className).toBe("");
+ expect(chipOf(empty)).toBeNull();
}
});
diff --git a/apps/client/src/widgets/collections/table/columns.tsx b/apps/client/src/widgets/collections/table/columns.tsx
index 0c705fa5ac..b033d0714e 100644
--- a/apps/client/src/widgets/collections/table/columns.tsx
+++ b/apps/client/src/widgets/collections/table/columns.tsx
@@ -8,7 +8,7 @@ import type { CellComponent, ColumnComponent, ColumnDefinition, EmptyCallback, F
import froca from "../../../services/froca.js";
import { safeUrlHref } from "../../../utils/url.js";
-import { applyLinkScheme, asLabelValues, ColorSwatch, formatLabelDate, LabelValueChips } from "../../attribute_widgets/label_value_display.jsx";
+import { applyLinkScheme, asLabelValues, formatLabelDate, LabelValueChips } from "../../attribute_widgets/label_value_display.jsx";
import LabelValueInput from "../../attribute_widgets/label_value_input.jsx";
import MultiValueInput from "../../attribute_widgets/multi_value_input.jsx";
import Icon from "../../react/Icon.jsx";
@@ -507,9 +507,10 @@ function ColorEditor({ cell, success }: EditorOpts) {
}
/**
- * A colour cell as the swatch its editor shows, so that reading and editing a colour look alike, and
- * so that the row keeps its own striping, hover and selection — all of which a cell flooded with the
- * colour, as Tabulator's own colour formatter fills it, hides.
+ * A colour cell as the chip a set of colours wears, one chip for the one value, so a colour column
+ * reads the same whether each note holds one or several. A chip rather than flooding the cell, as
+ * Tabulator's own colour formatter fills it: the chip is a surface of its own, leaving the row its
+ * striping, hover and selection.
*/
function ColorFormatter({ cell }: FormatterOpts) {
const value = cell.getValue();
@@ -517,7 +518,7 @@ function ColorFormatter({ cell }: FormatterOpts) {
// A formatter hands back an element, so an unset cell is an empty one rather than nothing at all.
if (!color) return <span />;
- return <ColorSwatch color={color} />;
+ return <LabelValueChips values={[ color ]} labelType="color" />;
}
/** A flag cell as the chip a set of flags shows, with an unset cell holding no chip at all. */