Skip to content

Build your personal knowledge base with Trilium Notes

client/ui: create a scroll fade utility

Adorian Doran369c16db823b
diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsx
index 7e53644f40..85e2b74967 100644
--- a/apps/client/src/widgets/collections/board/column.tsx
+++ b/apps/client/src/widgets/collections/board/column.tsx
@@ -17,6 +17,7 @@ import ActionButton from "../../react/ActionButton";
import Icon from "../../react/Icon";
import { IconPickerButton } from "../../react/IconPicker";
import { useStaticTooltip } from "../../react/hooks";
+import { useScrollFade } from "../../react/scroll_fade";
import NoteLink from "../../react/NoteLink";
import { BoardActionsContext, BoardDragStateContext, TitleEditor } from ".";
import BoardApi from "./api";
@@ -87,6 +88,8 @@ export default function Column({
const { branchIdToEdit, columnNameToEdit, dropTarget, draggedCard, dropPosition } = useContext(BoardDragStateContext);
const isEditing = (columnNameToEdit === column);
const editorRef = useRef<HTMLInputElement>(null);
+ const contentRef = useRef<HTMLDivElement>(null);
+ const scrollFade = useScrollFade(contentRef);
const { handleColumnDragStart, handleColumnDragEnd, handleDragOver, handleDragLeave, handleDrop } = useDragging({
column, columnIndex, columnItems, isEditing, api, parentNote
});
@@ -295,7 +298,12 @@ export default function Column({
</>)}
</h3>
- {!isCollapsed && <div className="board-column-content" onWheel={handleScroll}>
+ {!isCollapsed && <div
+ ref={contentRef}
+ className={clsx("board-column-content", scrollFade.className)}
+ style={scrollFade.style}
+ onWheel={handleScroll}
+ >
{(columnItems ?? []).map(({ note, branch }, index) => {
const showIndicatorBefore = dropPosition?.column === column &&
dropPosition.index === index &&
diff --git a/apps/client/src/widgets/react/scroll_fade.css b/apps/client/src/widgets/react/scroll_fade.css
new file mode 100644
index 0000000000..c46a6f7ed1
--- /dev/null
+++ b/apps/client/src/widgets/react/scroll_fade.css
@@ -0,0 +1,59 @@
+/*
+ * A custom property only animates once it is registered with a type, so both ends are declared as
+ * lengths for the transition below to interpolate. Where `@property` is unsupported the fades snap,
+ * and the `var()` fallbacks in the mask stand in for the initial values.
+ */
+@property --scroll-fade-start {
+ syntax: "<length>";
+ inherits: false;
+ initial-value: 0px;
+}
+
+@property --scroll-fade-end {
+ syntax: "<length>";
+ inherits: false;
+ initial-value: 0px;
+}
+
+/*
+ * Fades whichever edge a scroll container continues past, so what is cut off reads as going on
+ * rather than as ending.
+ *
+ * A mask rather than a painted gradient: it holds over any background, including a semi-transparent
+ * tint over a window material, which no painted color could match.
+ */
+.scroll-fade {
+ mask-image: linear-gradient(
+ var(--scroll-fade-direction, to bottom),
+ transparent,
+ black var(--scroll-fade-start, 0px),
+ black calc(100% - var(--scroll-fade-end, 0px)),
+ transparent
+ );
+ transition:
+ --scroll-fade-start var(--scroll-fade-duration, 300ms) ease,
+ --scroll-fade-end var(--scroll-fade-duration, 300ms) ease;
+}
+
+/* A gradient can only be given a physical direction, and the ends swap in a right-to-left page. */
+.scroll-fade-horizontal {
+ --scroll-fade-direction: to right;
+}
+
+body[dir=rtl] .scroll-fade-horizontal {
+ --scroll-fade-direction: to left;
+}
+
+.scroll-fade-start {
+ --scroll-fade-start: var(--scroll-fade-size, 20px);
+}
+
+.scroll-fade-end {
+ --scroll-fade-end: var(--scroll-fade-size, 20px);
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .scroll-fade {
+ transition: none;
+ }
+}