import React from 'react' import CsvExport from '../CsvExport/CsvExport' import { type CsvExportProps } from '../CsvExport/CsvExport' import Filter from '../Filter/Filter' import { type FilterProps } from '../Filter/Filter' import Icon from '../Icons/Icon' import Image from '../Image/Image' import { type ImageProps } from '../Image/Image' import SearchBar from '../SearchBar/SearchBar' import { type SearchBarProps } from '../SearchBar/SearchBar' import { Skeleton } from '../Skeleton/Skeleton' import Tooltip from '../Tooltip/Tooltip' import { type TooltipProps } from '../Tooltip/Tooltip' import { useMediaQuery } from '../../hooks/responsiveHooks' import styles from './_page-header.module.scss' type HeaderWithName = { name: React.ReactNode value: React.ReactNode tooltip?: TooltipProps image?: never } type HeaderWithImage = { image: ImageProps name?: never value?: never tooltip?: never } export type PageHeaderProps = { /** Header name, value, and optional tooltip */ header?: HeaderWithName | HeaderWithImage /** Optional `SearchBar` available */ search?: SearchBarProps /** Optional `CsvExport` available */ download?: CsvExportProps /** Optional page filter available */ pageFilterProps?: FilterProps /** Optional informational `Tooltip` available */ tooltip?: Omit /** Optionally children to appear in the left section of the `PageHeader` */ leftSectionChildren?: React.ReactNode /** Optionally children to appear in the right section of the `PageHeader` */ rightSectionChildren?: React.ReactNode /** Optionally children to appear in the bottom section of the `PageHeader` */ bottomSectionChildren?: React.ReactNode /** Optionally hide the right section divider in mobile */ hideMobileDivider?: boolean /** Optionally add loaders */ loading?: { headerName?: boolean headerValue?: boolean headerImage?: boolean } /** Optional prop to add a test id to the PageHeader for QA testing */ qaTestId?: string } const PageHeader = ({ header, search, download, tooltip, pageFilterProps, leftSectionChildren, rightSectionChildren, bottomSectionChildren, hideMobileDivider, loading, qaTestId = 'page-header', }: PageHeaderProps): React.JSX.Element => { const rightSectionOptionsCheck = rightSectionChildren || download || tooltip const rightSectionCheck = rightSectionOptionsCheck || pageFilterProps const isMobileView = useMediaQuery({ type: 'max', breakpoint: 'sm' }) return (
{/* Main Header name, value, and optional Tooltip */} {header ? ( header.image ? ( loading?.headerImage ? ( ) : ( ) ) : (
{loading?.headerName ? : header.name} {header.tooltip ? ( ) : null}
{loading?.headerValue ? (
) : (
{header.value}
)}
) ) : null} {/* Optional leftSectionChildren */} {leftSectionChildren ? leftSectionChildren : null} {header && search ? : null} {/* Optional SearchBar */} {search ? : null}
{rightSectionCheck ? (
{isMobileView && !hideMobileDivider ? : null} {/* Optional download */} {download ? : null} {/* Optional informational Tooltip */} {tooltip ? ( ) : null} {rightSectionOptionsCheck && pageFilterProps ? : null} {/* Optional filters */} {pageFilterProps ? : null} {/* Optional rightSectionChildren */} {rightSectionChildren ? rightSectionChildren : null}
) : null}
{/* Optional bottomSectionChildren */} {bottomSectionChildren ? bottomSectionChildren : null}
) } const Divider = ({ large, horizontal, }: { large?: boolean horizontal?: boolean }) => { return (
) } PageHeader.HeaderDivider = Divider export { PageHeader }