feat(layout): make edited notes collapsible

This commit is contained in:
Elian Doran
2025-12-14 20:15:17 +02:00
parent 9d7e2855d3
commit f7b911dc0b
4 changed files with 86 additions and 13 deletions

View File

@@ -0,0 +1,28 @@
.collapsible {
.collapsible-title {
line-height: 1em;
display: flex;
align-items: center;
.arrow {
font-size: 1.3em;
transition: transform 250ms ease-in;
}
}
.collapsible-body {
height: 0;
overflow: hidden;
transition: height 250ms ease-in;
}
.collapsible-inner-body {
padding-top: 0.5em;
}
&.expanded {
.collapsible-title .arrow {
transform: rotate(90deg);
}
}
}

View File

@@ -0,0 +1,42 @@
import "./Collapsible.css";
import clsx from "clsx";
import { ComponentChildren, HTMLAttributes } from "preact";
import { useRef, useState } from "preact/hooks";
import Icon from "./Icon";
interface CollapsibleProps extends Pick<HTMLAttributes<HTMLDivElement>, "className"> {
title: string;
children: ComponentChildren;
}
export default function Collapsible({ title, children, className }: CollapsibleProps) {
const bodyRef = useRef<HTMLDivElement>(null);
const [ expanded, setExpanded ] = useState(false);
return (
<div className={clsx("collapsible", className, expanded && "expanded")}>
<div
className="collapsible-title"
onClick={() => setExpanded(!expanded)}
>
<Icon className="arrow" icon="bx bx-chevron-right" />&nbsp;
{title}
</div>
<div
ref={bodyRef}
className="collapsible-body"
style={{
height: expanded ? bodyRef.current?.scrollHeight : "0",
}}
>
<div className="collapsible-inner-body">
{children}
</div>
</div>
</div>
);
}