getting rid of some code duplication
This commit is contained in:
parent
0266675f29
commit
970b9d850e
21 changed files with 325 additions and 302 deletions
|
|
@ -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>;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue