el.xwx.moe/components/LinkViews/Layouts/MasonryView.tsx

58 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-04-26 11:18:31 -05:00
import LinkMasonry from "@/components/LinkViews/LinkMasonry";
2024-04-23 20:48:15 -05:00
import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
import { GridLoader } from "react-spinners";
2024-04-23 20:53:33 -05:00
import Masonry from "react-masonry-css";
2024-04-25 22:56:36 -05:00
import resolveConfig from "tailwindcss/resolveConfig";
import tailwindConfig from "../../../tailwind.config.js";
import { useMemo } from "react";
2024-04-23 20:48:15 -05:00
export default function MasonryView({
2024-04-23 20:53:33 -05:00
links,
editMode,
isLoading,
2024-04-23 20:48:15 -05:00
}: {
2024-04-23 20:53:33 -05:00
links: LinkIncludingShortenedCollectionAndTags[];
editMode?: boolean;
isLoading?: boolean;
2024-04-23 20:48:15 -05:00
}) {
2024-04-25 22:56:36 -05:00
const fullConfig = resolveConfig(tailwindConfig as any);
const breakpointColumnsObj = useMemo(() => {
return {
default: 4,
1900: 3,
[fullConfig.theme.screens.xl]: 2,
[fullConfig.theme.screens.sm]: 1,
};
}, []);
2024-04-23 20:53:33 -05:00
return (
<Masonry
2024-04-25 22:56:36 -05:00
breakpointCols={breakpointColumnsObj}
columnClassName="flex flex-col gap-5 !w-full"
className="grid min-[1900px]:grid-cols-4 xl:grid-cols-3 sm:grid-cols-2 grid-cols-1 gap-5 pb-5"
2024-04-23 20:53:33 -05:00
>
{links.map((e, i) => {
return (
2024-04-26 11:18:31 -05:00
<LinkMasonry
2024-04-23 20:53:33 -05:00
key={i}
link={e}
count={i}
flipDropdown={i === links.length - 1}
editMode={editMode}
/>
);
})}
2024-04-23 20:48:15 -05:00
2024-04-23 20:53:33 -05:00
{isLoading && links.length > 0 && (
<GridLoader
color="oklch(var(--p))"
loading={true}
size={20}
className="fixed top-5 right-5 opacity-50 z-30"
/>
)}
</Masonry>
);
2024-04-23 20:48:15 -05:00
}