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(table): tell a flag chip's answer by a wash of its colour
Elian Doran5d3d5c4a60e4
diff --git a/apps/client/src/widgets/attribute_widgets/label_value_display.css b/apps/client/src/widgets/attribute_widgets/label_value_display.cssindex 9c256c853b..7989f57550 100644--- a/apps/client/src/widgets/attribute_widgets/label_value_display.css+++ b/apps/client/src/widgets/attribute_widgets/label_value_display.css@@ -23,6 +23,31 @@opacity: 0.55;}+/* A flag's chip takes a wash of the answer it carries — a wash rather than the colour outright, so+ the mark stays the thing that says it and the wash only lets it be told from across the table.+ Doubled with .tn-chip to outweigh the chip's own ground whichever stylesheet loads last.++ The mark itself keeps to the muted grey only on the chip's own neutral ground; on a wash it takes+ its answer's colour instead, leaned well toward the theme's text colour — deepened on a light+ theme, lifted on a dark one — so it stands on the tint rather than sinking into it. */+.tn-chip.label-flag-chip-set {+ background-color: color-mix(in srgb, var(--bs-success) 25%, transparent);++ .label-flag-set {+ color: color-mix(in srgb, var(--bs-success) 40%, var(--main-text-color));+ }+}++.tn-chip.label-flag-chip-unset {+ background-color: color-mix(in srgb, var(--bs-danger) 25%, transparent);++ .label-flag-unset {+ color: color-mix(in srgb, var(--bs-danger) 40%, var(--main-text-color));+ /* The wash already sets an unset flag apart; a mark also drawn back would fade into it. */+ opacity: 1;+ }+}+/** A read-only chip that is the colour it stands for. Holding nothing — no text, no button — it has* nothing to hold it open, so it is sized to show a stretch of the colour at the height the swatchdiff --git a/apps/client/src/widgets/attribute_widgets/label_value_display.tsx b/apps/client/src/widgets/attribute_widgets/label_value_display.tsxindex 25eacf5193..63d3a7112f 100644--- a/apps/client/src/widgets/attribute_widgets/label_value_display.tsx+++ b/apps/client/src/widgets/attribute_widgets/label_value_display.tsx@@ -111,7 +111,15 @@ export function LabelValueChips({ values, labelType, className }: {// ground rather than showing a colour it is not.<span key={value} className="tn-chip label-color-chip" title={value} style={{ backgroundColor: value }} />) : (- <span key={value} className="tn-chip"><span>{renderLabelValue(value, labelType)}</span></span>+ // A flag's chip takes a wash of the answer it carries, so a row of checks and+ // crosses reads apart at a glance, before the marks themselves are.+ <span+ key={value}+ className={clsx("tn-chip", labelType === "boolean" &&+ (value === "true" ? "label-flag-chip-set" : "label-flag-chip-unset"))}+ >+ <span>{renderLabelValue(value, labelType)}</span>+ </span>)))}</span>diff --git a/apps/client/src/widgets/collections/table/columns.spec.ts b/apps/client/src/widgets/collections/table/columns.spec.tsindex 7d0c4548a3..802fe2aa3a 100644--- a/apps/client/src/widgets/collections/table/columns.spec.ts+++ b/apps/client/src/widgets/collections/table/columns.spec.ts@@ -170,6 +170,33 @@ describe("buildColumnDefinitions — typed columns", () => {expect(url({ getValue: () => "javascript:alert(1)" } as CellComponent)).toBe("about:blank");expect(url({ getValue: () => "https://example.com" } as CellComponent)).toBe("https://example.com");});++ it("shows a single flag as the chip a set of flags wears, and an unset cell as nothing", () => {+ const [ column ] = buildColumnDefinitions({+ info: [ { name: "done", type: "boolean" } ],+ movableRows: false,+ existingColumnData: undefined,+ rowNumberHint: 1+ }).filter((candidate) => candidate.field === "labels.done");++ 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;++ // A stored label holds the text "true", a value fresh from the tickCross editor a real+ // boolean; either reads as the one chip, washed with its answer.+ for (const set of [ "true", true ]) {+ expect(format(set).querySelector(".tn-chip")?.className).toContain("label-flag-chip-set");+ expect(format(set).querySelector(".tn-icon")?.getAttribute("title")).toBe("true");+ }+ expect(format(false).querySelector(".tn-chip")?.className).toContain("label-flag-chip-unset");++ // An unset cell holds no flag at all, so it wears no chip either.+ for (const empty of [ "", undefined, null ]) {+ expect(format(empty).querySelector(".tn-chip")).toBeNull();+ }+ });});describe("buildColumnDefinitions — colour columns", () => {@@ -383,12 +410,16 @@ describe("buildColumnDefinitions — multi-valued columns", () => {) as HTMLElement;};- // A flag reads as the mark a column of single flags shows, not as the word "true".+ // A flag reads as the mark a column of single flags shows, not as the word "true" — and its+ // chip takes a wash of the answer, telling checks from crosses across the table.const flags = format("boolean", [ "true", "false" ]);expect([ ...flags.querySelectorAll(".tn-icon") ].map((mark) => mark.getAttribute("title"))).toEqual([ "true", "false" ]);expect(flags.querySelector(".label-flag-set")?.className).toContain("bx-check");expect(flags.querySelector(".label-flag-unset")?.className).toContain("bx-x");+ const chips = [ ...flags.querySelectorAll(".tn-chip") ];+ expect(chips[0]?.className).toContain("label-flag-chip-set");+ expect(chips[1]?.className).toContain("label-flag-chip-unset");// And a colour floods the chip itself — read-only, the chip holds nothing the colour could// hide — with the stored text kept to the tooltip.diff --git a/apps/client/src/widgets/collections/table/columns.tsx b/apps/client/src/widgets/collections/table/columns.tsxindex 2a61cd10b5..0c705fa5ac 100644--- a/apps/client/src/widgets/collections/table/columns.tsx+++ b/apps/client/src/widgets/collections/table/columns.tsx@@ -46,7 +46,9 @@ const labelTypeMappings: Record<ColumnType, Partial<ColumnDefinition>> = {editor: wrapEditor(SelectEditor)},boolean: {- formatter: "tickCross",+ // The same chip a set of flags wears, one chip for the one value, so a column of flags+ // reads the same whether each note holds one or several. Toggling stays Tabulator's own.+ formatter: wrapFormatter(FlagFormatter),editor: "tickCross",// Values arrive as strings ("true"/"false") from stored labels but as real booleans// once toggled via the editor; the boolean sorter normalizes both, whereas the default@@ -518,17 +520,44 @@ function ColorFormatter({ cell }: FormatterOpts) {return <ColorSwatch color={color} />;}+/** A flag cell as the chip a set of flags shows, with an unset cell holding no chip at all. */+function FlagFormatter({ cell }: FormatterOpts) {+ const value = cell.getValue();+ // A stored label arrives as the text "true"/"false", but one just toggled through the tickCross+ // editor is a real boolean; the chip reads the stored spelling of either.+ const flag = typeof value === "boolean" ? String(value) : value;+ if (typeof flag !== "string" || !flag) return <span />;++ return <LabelValueChips values={[ flag ]} labelType="boolean" />;+}++/**+ * A relation cell's editor stands over its cell as the multi-valued editor does, and by the same+ * class: what is typed into it is a note's title, which a column sized for the title it *shows* is+ * rarely wide enough to search by — the box takes at least the cell's width, and grows past it up to+ * the editor's usual ceiling. The list of matches is appended to the body, so it outgrows the cell+ * either way; it is the box being typed into that needs the room.+ */function RelationEditor({ cell, success }: EditorOpts) {const inputRef = useRef<HTMLInputElement>(null);useEffect(() => inputRef.current?.focus());- return <NoteAutocomplete- inputRef={inputRef}- noteId={cell.getValue()}- opts={{- allowCreatingNotes: true,- hideAllButtons: true- }}- noteIdChanged={success}- />;+ return (+ <div className="table-values-editor">+ {/* Framed as the editor's other fields are: an editing cell strips the border and+ background from the boxes within, which leaves an unwrapped one adrift on the+ editor's own surface. */}+ <div className="tn-field">+ <NoteAutocomplete+ inputRef={inputRef}+ noteId={cell.getValue()}+ opts={{+ allowCreatingNotes: true,+ hideAllButtons: true+ }}+ noteIdChanged={success}+ />+ </div>+ </div>+ );}diff --git a/apps/client/src/widgets/react/Chip.css b/apps/client/src/widgets/react/Chip.cssindex fd2d82bdd4..931c654a2e 100644--- a/apps/client/src/widgets/react/Chip.css+++ b/apps/client/src/widgets/react/Chip.css@@ -21,7 +21,11 @@outline: 2px solid var(--input-focus-outline-color);}- > input.form-control {+ /* Also reaching a box one step down: some boxes come wrapped in a group of their own — the note+ autocomplete brings one — and left there the box would keep its frame, drawing a second border+ just within the field's. */+ > input.form-control,+ > .input-group > input.form-control {flex: 1;min-width: 6ch;width: auto;@@ -36,6 +40,22 @@}}+ /* The group is only the box's wrapping, so it takes the room the box would and adds nothing of+ its own to the eye — in any state: a group is elsewhere a field in its own right, wearing a+ focus ring and a ground of its own, which here would draw a second frame just within the+ field's whenever the box in it is hovered or focused. */+ > .input-group {+ flex: 1;+ border: none;++ &,+ &:hover,+ &:focus-within {+ outline: none;+ background: transparent;+ }+ }+/* A chip standing for a value holds text rather than a box to type in, so it needs none of thefield styling the chip leaves to its contents — only room for the word itself. */> .tn-chip > span {