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
client/collections/board: update the design of the dragged set of cards
Adorian Doranb3da7df7d0cc
diff --git a/apps/client/src/widgets/collections/board/board_drag.spec.tsx b/apps/client/src/widgets/collections/board/board_drag.spec.tsxindex 0bbd67dd8f..5564af2c79 100644--- a/apps/client/src/widgets/collections/board/board_drag.spec.tsx+++ b/apps/client/src/widgets/collections/board/board_drag.spec.tsx@@ -66,6 +66,31 @@ describe("useBoardDrag, carrying a card", () => {expect(copy?.querySelector(".title")).toBeNull();});+ /** Two cards on the move leave one card behind the copy. */+ it("stacks one card behind a pair", () => {+ setup({ carried: [ "n1", "n2" ] });++ press(card("n1"), 50, 60);+ move(90, 90);++ expect(preview()?.dataset.layers).toBe("2");+ expect(preview()?.textContent).toBe("2");+ });++ /**+ * The stack says a set is on the move and the number says how big it is, so the stack stops at+ * the depth the stylesheet draws however many cards are carried.+ */+ it("stacks no deeper than three, whatever the selection holds", () => {+ setup({ carried: [ "n1", "n2", "n3", "n4", "n5" ] });++ press(card("n1"), 50, 60);+ move(90, 90);++ expect(preview()?.dataset.layers).toBe("3");+ expect(preview()?.textContent).toBe("5");+ });+it("carries a copy under the pointer without redrawing the board", () => {setup();const element = card("n1");diff --git a/apps/client/src/widgets/collections/board/board_drag.ts b/apps/client/src/widgets/collections/board/board_drag.tsindex 09b625e506..bc96471978 100644--- a/apps/client/src/widgets/collections/board/board_drag.ts+++ b/apps/client/src/widgets/collections/board/board_drag.ts@@ -20,6 +20,12 @@ const TOUCH_TOLERANCE = 8;/** How much a carried card shrinks. Written with the movement, a class could not add to it. */const DRAG_SCALE = 0.9;+/**+ * How many cards a carried selection is drawn as, however many are on the move: the one holding the+ * count and the two behind it. `index.css` draws the ones behind from `data-layers`.+ */+const STACK_LAYERS = 3;+/** How tall a carried column is allowed to stand, so a full one can be seen past. */const COLUMN_DRAG_MAX_HEIGHT = 150;@@ -627,10 +633,17 @@ function lift(held: Gesture, container: HTMLElement) {};}-/** A card-shaped copy standing for the cards being carried, with their number in the middle. */+/**+ * A card-shaped copy standing for the cards being carried, with their number in the middle and a+ * stack drawn behind it.+ *+ * `data-layers` counts the copy itself, so two cards on the move leave one card behind it and any+ * more leave two. The number in the middle is what says how many there really are.+ */function countPreview(count: number) {const preview = document.createElement("div");preview.className = "board-note board-drag-count";+ preview.dataset.layers = String(Math.min(count, STACK_LAYERS));preview.textContent = String(count);return preview;}diff --git a/apps/client/src/widgets/collections/board/index.css b/apps/client/src/widgets/collections/board/index.cssindex d51138a8db..9ad1bc4758 100644--- a/apps/client/src/widgets/collections/board/index.css+++ b/apps/client/src/widgets/collections/board/index.css@@ -25,6 +25,12 @@/* The lift a card takes under the pointer, named so that a picked-out card can carry its ringand this shadow together. */--board-item-hover-shadow: 2px 4px 8px rgba(0, 0, 0, 0.1);+ /* What a carried card casts, which the stack of a carried selection is drawn behind. */+ --board-drag-shadow: 4px 8px 16px rgba(0, 0, 0, 0.5);+ /* How far each card of a carried stack stands out from the one in front of it. */+ --board-drag-stack-offset: 4px;+ /* The ring a carried card wears, which the stack behind it starts clear of. */+ --board-drag-ring-width: 3px;/* The ring a picked-out card carries. */--board-selected-ring-color: var(--link-color);@@ -467,14 +473,6 @@ body.mobile .board-view-container .board-add-column {opacity: 0.4;}-/* What a carried selection is drawn as: one card-shaped block holding how many are on the move. */-.board-view-container .board-note.board-drag-count {- display: flex;- align-items: center;- justify-content: center;- font-size: 1.6em;- font-weight: 600;-}.board-view-container .board-note:hover > .edit-icon {position: absolute;@@ -531,7 +529,8 @@ body.mobile .board-view-container .board-add-column {/* The card is focused by the press that picks it up and then taken out of the page, which drops thefocus; the copy carries the ring on so what is being moved still reads as what is focused. */.board-view-container .board-note.board-drag-preview {- outline: 3px solid var(--board-focus-outline-color, var(--board-focus-outline-plain-color));+ outline: var(--board-drag-ring-width) solid+ var(--board-focus-outline-color, var(--board-focus-outline-plain-color));outline-offset: 0;}@@ -546,7 +545,64 @@ body.mobile .board-view-container .board-add-column {pointer-events: none;cursor: move;opacity: 0.85;- box-shadow: 4px 8px 16px rgba(0, 0, 0, 0.5);+ box-shadow: var(--board-drag-shadow);+}++/* What a carried selection is drawn as: one card-shaped block holding how many are on the move. */+.board-view-container .board-note.board-drag-count {+ display: flex;+ align-items: center;+ justify-content: center;+ font-size: 1.6em;+ font-weight: 600;++ /* The card's own colour, which the stack behind it is drawn in at lower opacity. */+ --board-drag-stack-card:+ var(--board-item-hue)+ var(--board-item-saturation)+ var(--board-item-background-lightness);+}++/* The cards behind the one carried, drawn as copies of its shape rather than as elements: only the+ sliver past the front card shows, and a real card would repeat the ring the front one carries.+ Each is a fill with a copy one pixel wider behind it, which is what draws its edge.++ Every offset starts past the ring, which is drawn over the shapes below and would otherwise take+ its own width out of the first card alone, leaving that one standing out less than the rest. */+.board-view-container .board-note.board-drag-count {+ --board-drag-stack-1:+ calc(var(--board-drag-ring-width) + var(--board-drag-stack-offset));+ --board-drag-stack-2:+ calc(var(--board-drag-ring-width) + var(--board-drag-stack-offset) * 2 + 1px);++ /* Each card behind stands back a little further than the one in front of it. */+ --board-drag-stack-fade-1: 85%;+ --board-drag-stack-fade-2: 75%;+}++.board-view-container .board-note.board-drag-count[data-layers="2"] {+ box-shadow:+ var(--board-drag-stack-1) var(--board-drag-stack-1) 0 0+ hsl(var(--board-drag-stack-card) / var(--board-drag-stack-fade-1)),+ var(--board-drag-stack-1) var(--board-drag-stack-1) 0 1px+ color-mix(in srgb, var(--board-selected-ring-color)+ var(--board-drag-stack-fade-1), transparent),+ var(--board-drag-shadow);+}++.board-view-container .board-note.board-drag-count[data-layers="3"] {+ box-shadow:+ var(--board-drag-stack-1) var(--board-drag-stack-1) 0 0+ hsl(var(--board-drag-stack-card) / var(--board-drag-stack-fade-1)),+ var(--board-drag-stack-1) var(--board-drag-stack-1) 0 1px+ color-mix(in srgb, var(--board-selected-ring-color)+ var(--board-drag-stack-fade-1), transparent),+ var(--board-drag-stack-2) var(--board-drag-stack-2) 0 0+ hsl(var(--board-drag-stack-card) / var(--board-drag-stack-fade-2)),+ var(--board-drag-stack-2) var(--board-drag-stack-2) 0 1px+ color-mix(in srgb, var(--board-selected-ring-color)+ var(--board-drag-stack-fade-2), transparent),+ var(--board-drag-shadow);}/* Reaching the end of the board scrolls neither the page nor anything else. */