Skip to content

Commit

Permalink
feat: add displayname to portal
Browse files Browse the repository at this point in the history
  • Loading branch information
mfts committed Aug 13, 2024
1 parent a3a57a8 commit c039bf6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
5 changes: 2 additions & 3 deletions components/documents/documents-list.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { memo, useCallback, useMemo, useState } from "react";
import { memo, useCallback, useState } from "react";
import React from "react";

import { TeamContextType } from "@/context/team-context";
Expand Down Expand Up @@ -26,10 +26,9 @@ import UploadZone from "@/components/upload-zone";

import { FolderWithCount } from "@/lib/swr/use-documents";
import { DocumentWithLinksAndLinkCountAndViewCount } from "@/lib/types";
import { cn } from "@/lib/utils";

import { Button } from "../ui/button";
import Portal from "../ui/portal";
import { Portal } from "../ui/portal";
import DocumentCard from "./document-card";
import { DraggableItem } from "./drag-and-drop/draggable-item";
import { DroppableFolder } from "./drag-and-drop/droppable-folder";
Expand Down
17 changes: 10 additions & 7 deletions components/ui/portal.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import { useLayoutEffect, useState } from "react";
import * as React from "react";

import * as Portal from "@radix-ui/react-portal";
import * as PortalPrimitive from "@radix-ui/react-portal";

export default ({
const Portal = ({
containerId,
children,
}: {
containerId?: string | null;
children: React.ReactElement;
}) => {
const [mounted, setMounted] = useState(false);
useLayoutEffect(() => setMounted(true), []);
const [mounted, setMounted] = React.useState(false);
React.useLayoutEffect(() => setMounted(true), []);

return (
<Portal.Root
<PortalPrimitive.Root
container={
containerId && mounted
? document.getElementById(containerId)
: undefined
}
>
{children}
</Portal.Root>
</PortalPrimitive.Root>
);
};
Portal.displayName = PortalPrimitive.Root.displayName;

export { Portal };

0 comments on commit c039bf6

Please sign in to comment.