import React, { useEffect } from 'react'; import { useMediaQuery } from 'react-responsive'; import { OverlayTriggerState } from 'react-stately'; import { DOMAttributes, FocusableElement } from '@react-types/shared'; import { Icon, IconOptions } from '../Icons/Icon'; import PreviewModal from './PreviewModal'; export interface PreviewPanelProps { resource: any | null; modalState: OverlayTriggerState; previewModalOverlayProps: DOMAttributes; allowedTypes: string[] | undefined; onSelect: (resource: any) => void; onClose: () => void; ResourceComponent?: React.ElementType; selectionCallback?: (param: any) => void; resourceComponentProps?: { [x: string]: any; }; } export const PreviewPanel = function ({ resource, previewModalOverlayProps, modalState, onSelect, onClose, ResourceComponent, selectionCallback, resourceComponentProps = {}, }: PreviewPanelProps) { // Watch the media size to see if we are on mobile size const isMobile = useMediaQuery({ query: '(max-width: 640px)' }); // If we are on mobile and the selected resource changes show the preview panel modal. useEffect(() => { if (!modalState.isOpen) { modalState.setOpen(Boolean(resource && isMobile)); } }, [resource, isMobile]); const previewPanel = resource && ( <>
{ResourceComponent && ( )}
); return (
{/* Dialog has its own title */} {!isMobile &&

Resource Details

} {/* Nothing selected, show an info message */} {resource === null && (
Make a selection to see more info here.
)} {/* Resource details shows in a new modal / bottom popover on mobile size */} {resource && isMobile && modalState.isOpen && ( {previewPanel} )} {/* If not mobile, just print the details out */} {resource && !isMobile &&
{previewPanel}
}
); };