2023-07-20 15:13:31 -04:00
|
|
|
import { useRef } from "react";
|
2023-06-22 11:51:38 -07:00
|
|
|
import classNames from "classnames";
|
|
|
|
import { Disclosure, Transition } from '@headlessui/react';
|
|
|
|
import { MdKeyboardArrowDown } from "react-icons/md";
|
|
|
|
|
2022-10-04 13:15:49 -07:00
|
|
|
import ErrorBoundary from "components/errorboundry";
|
2022-08-24 10:44:35 +03:00
|
|
|
import List from "components/bookmarks/list";
|
2023-09-03 10:05:25 -04:00
|
|
|
import ResolvedIcon from "components/resolvedicon";
|
2022-08-24 10:44:35 +03:00
|
|
|
|
2023-09-03 10:05:25 -04:00
|
|
|
export default function BookmarksGroup({ bookmarks, layout, disableCollapse }) {
|
2023-07-20 15:13:31 -04:00
|
|
|
const panel = useRef();
|
2022-08-24 10:44:35 +03:00
|
|
|
return (
|
2023-09-03 10:05:25 -04:00
|
|
|
<div
|
|
|
|
key={bookmarks.name}
|
|
|
|
className={classNames(
|
2023-09-10 23:36:54 +02:00
|
|
|
"bookmark-group",
|
2023-09-03 10:05:25 -04:00
|
|
|
layout?.style === "row" ? "basis-full" : "basis-full md:basis-1/4 lg:basis-1/5 xl:basis-1/6",
|
|
|
|
layout?.header === false ? "flex-1 px-1 -my-1" : "flex-1 p-1"
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<Disclosure defaultOpen>
|
|
|
|
{({ open }) => (
|
|
|
|
<>
|
|
|
|
{layout?.header !== false && (
|
|
|
|
<Disclosure.Button disabled={disableCollapse} className="flex w-full select-none items-center group">
|
|
|
|
{layout?.icon && (
|
2023-09-10 23:36:54 +02:00
|
|
|
<div className="flex-shrink-0 mr-2 w-7 h-7 bookmark-group-icon">
|
2023-09-03 10:05:25 -04:00
|
|
|
<ResolvedIcon icon={layout.icon} />
|
|
|
|
</div>
|
|
|
|
)}
|
2023-09-10 23:36:54 +02:00
|
|
|
<h2 className="text-theme-800 dark:text-theme-300 text-xl font-medium bookmark-group-name">{bookmarks.name}</h2>
|
2023-09-03 10:05:25 -04:00
|
|
|
<MdKeyboardArrowDown
|
|
|
|
className={classNames(
|
|
|
|
disableCollapse ? "hidden" : "",
|
|
|
|
"transition-all opacity-0 group-hover:opacity-100 ml-auto text-theme-800 dark:text-theme-300 text-xl",
|
|
|
|
open ? "" : "rotate-180"
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</Disclosure.Button>
|
|
|
|
)}
|
|
|
|
<Transition
|
|
|
|
// Otherwise the transition group does display: none and cancels animation
|
|
|
|
className="!block"
|
|
|
|
unmount={false}
|
|
|
|
beforeLeave={() => {
|
|
|
|
panel.current.style.height = `${panel.current.scrollHeight}px`;
|
|
|
|
setTimeout(() => {
|
|
|
|
panel.current.style.height = `0`;
|
|
|
|
}, 1);
|
|
|
|
}}
|
|
|
|
beforeEnter={() => {
|
|
|
|
panel.current.style.height = `0px`;
|
|
|
|
setTimeout(() => {
|
|
|
|
panel.current.style.height = `${panel.current.scrollHeight}px`;
|
|
|
|
}, 1);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Disclosure.Panel className="transition-all overflow-hidden duration-300 ease-out" ref={panel} static>
|
|
|
|
<ErrorBoundary>
|
|
|
|
<List bookmarks={bookmarks.bookmarks} layout={layout} />
|
|
|
|
</ErrorBoundary>
|
|
|
|
</Disclosure.Panel>
|
|
|
|
</Transition>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Disclosure>
|
2022-08-24 10:44:35 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|