mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 15:48:32 -06:00
moving v2 to top level
This commit is contained in:
36
src/components/Expandable.tsx
Normal file
36
src/components/Expandable.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
"use client";
|
||||
import { ReactNode, Dispatch, SetStateAction, useState, useRef } from "react";
|
||||
|
||||
export function Expandable({
|
||||
children,
|
||||
ExpandableElement,
|
||||
defaultExpanded = false,
|
||||
}: {
|
||||
children: ReactNode;
|
||||
ExpandableElement: (props: {
|
||||
setIsExpanded: Dispatch<SetStateAction<boolean>>;
|
||||
isExpanded: boolean;
|
||||
}) => ReactNode;
|
||||
defaultExpanded?: boolean;
|
||||
}) {
|
||||
const [isExpanded, setIsExpanded] = useState(defaultExpanded);
|
||||
const expandRef = useRef<HTMLDivElement | null>(null);
|
||||
|
||||
return (
|
||||
<>
|
||||
<ExpandableElement
|
||||
setIsExpanded={setIsExpanded}
|
||||
isExpanded={isExpanded}
|
||||
/>
|
||||
<div
|
||||
ref={expandRef}
|
||||
className={` overflow-hidden transition-all `}
|
||||
style={{
|
||||
maxHeight: isExpanded ? expandRef?.current?.scrollHeight : "0",
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user