mirror of
https://github.com/zadam/trilium.git
synced 2025-12-19 05:44:24 +01:00
feat(layout/inline-title): intersection observer
This commit is contained in:
parent
912f90accf
commit
9ab5eef984
@ -1,5 +1,5 @@
|
|||||||
.component.inline-title-row {
|
.component.inline-title-row {
|
||||||
contain: none;
|
contain: none;
|
||||||
padding-block: 2em;
|
padding-bottom: 2em;
|
||||||
padding-inline-start: 24px;
|
padding-inline-start: 24px;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import "./InlineTitle.css";
|
import "./InlineTitle.css";
|
||||||
|
|
||||||
import { useEffect, useState } from "preact/hooks";
|
import { useEffect, useRef, useState } from "preact/hooks";
|
||||||
|
|
||||||
import FNote from "../../entities/fnote";
|
import FNote from "../../entities/fnote";
|
||||||
import { useNoteContext } from "../react/hooks";
|
import { useNoteContext } from "../react/hooks";
|
||||||
@ -8,6 +8,7 @@ import { useNoteContext } from "../react/hooks";
|
|||||||
export default function InlineTitle() {
|
export default function InlineTitle() {
|
||||||
const { note, parentComponent } = useNoteContext();
|
const { note, parentComponent } = useNoteContext();
|
||||||
const [ shown, setShown ] = useState(shouldShow(note));
|
const [ shown, setShown ] = useState(shouldShow(note));
|
||||||
|
const containerRef= useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setShown(shouldShow(note));
|
setShown(shouldShow(note));
|
||||||
@ -21,13 +22,24 @@ export default function InlineTitle() {
|
|||||||
?.querySelector("&> .title-row");
|
?.querySelector("&> .title-row");
|
||||||
if (!titleRow) return;
|
if (!titleRow) return;
|
||||||
|
|
||||||
titleRow.classList.add("collapse");
|
const observer = new IntersectionObserver((entries) => {
|
||||||
|
titleRow.classList.toggle("collapse", entries[0].isIntersecting);
|
||||||
|
});
|
||||||
|
if (containerRef.current) {
|
||||||
|
observer.observe(containerRef.current);
|
||||||
|
}
|
||||||
|
|
||||||
return () => titleRow.classList.remove("collapse");
|
return () => {
|
||||||
|
titleRow.classList.remove("collapse");
|
||||||
|
observer.disconnect();
|
||||||
|
};
|
||||||
}, [ shown, parentComponent ]);
|
}, [ shown, parentComponent ]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="inline-title-row">
|
<div
|
||||||
|
ref={containerRef}
|
||||||
|
className="inline-title-row"
|
||||||
|
>
|
||||||
Title goes here.
|
Title goes here.
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -53,7 +53,7 @@ body.experimental-feature-new-layout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
&.collapse {
|
&.collapse {
|
||||||
display: none !important;
|
visibility: hidden;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user