import React, {FC, PropsWithChildren} from "react"; import {useFloating, offset, autoUpdate, FloatingPortal} from "@floating-ui/react"; import {useIsPresent} from "framer-motion"; export type ContentWithSidebarsProps = { leftSidebar?: React.ReactNode, rightSidebar?: React.ReactNode, width: number, height?: number, fitHeightToContent?: boolean, floatingZIndex?: number, leftSidebarPortal?: boolean, } export const ContentWithSidebars: FC = ({ children, leftSidebar, rightSidebar, width, height, fitHeightToContent = false, floatingZIndex = 10000, leftSidebarPortal = true, }) => { const isPresent = useIsPresent(); const shouldFitHeightToContent = fitHeightToContent && typeof height === 'number' const {refs: leftRefs, floatingStyles: leftFloatingStyles} = useFloating({ placement: 'left-start', strategy: leftSidebarPortal ? 'fixed' : 'absolute', middleware: [offset(48)], whileElementsMounted: autoUpdate, }); /*const {refs: rightRefs, floatingStyles: rightFloatingStyles} = useFloating({ placement: 'right-start', middleware: [offset(48)], whileElementsMounted: autoUpdate, });*/ const renderedLeftSidebar = leftSidebar && (
{leftSidebar}
) return <>
{ leftRefs.setReference(node); /*rightRefs.setReference(node);*/ }} className={`relative w-full flex justify-center ${shouldFitHeightToContent ? 'overflow-y-auto max-h-full' : 'overflow-y-scroll h-full'}`}> {children}
{!leftSidebarPortal && renderedLeftSidebar}
{leftSidebarPortal && renderedLeftSidebar && ( {renderedLeftSidebar} )} {/*rightSidebar && (
{rightSidebar}
)*/} }