getting rid of some code duplication

This commit is contained in:
Joeri Exelmans 2025-11-14 16:52:09 +01:00
parent 0266675f29
commit 970b9d850e
21 changed files with 325 additions and 302 deletions

View file

@ -1,21 +0,0 @@
import { usePersistentState } from "@/hooks/usePersistentState"
import { DetailsHTMLAttributes, Dispatch, PropsWithChildren, SetStateAction } from "react";
type Props = {
localStorageKey: string,
initiallyOpen?: boolean,
} & DetailsHTMLAttributes<HTMLDetailsElement>;
// A <details> node that remembers whether it was open or closed by storing that state in localStorage.
export function PersistentDetailsLocalStorage({localStorageKey, initiallyOpen, children, ...rest}: PropsWithChildren<Props>) {
const [open, setOpen] = usePersistentState(localStorageKey, initiallyOpen);
return <details open={open} onToggle={e => setOpen(e.newState === "open")} {...rest}>
{children}
</details>;
}
export function PersistentDetails({state, setState, children, ...rest}: PropsWithChildren<{state: boolean, setState: Dispatch<SetStateAction<boolean>>}>) {
return <details open={state} onToggle={e => setState(e.newState === "open")} {...rest}>
{children}
</details>;
}