import React, { useEffect } from 'react' import { createPortal } from 'react-dom' import Button from '../Button/Button' import ButtonGroup from '../Button/ButtonGroup/ButtonGroup' import isClient from '../../services/isClient' import Pagination from '../Pagination/Pagination' import { useIsMobileView } from '../../hooks/useIsMobileView/useIsMobileView' import styles from './_page-footer.module.scss' import { c } from '../../translations/LibraryTranslationService' type ButtonType = React.ComponentProps type ButtonGroupType = React.ComponentProps type PaginationType = React.ComponentProps type ButtonProp = { type: 'button' } & ButtonType type ButtonGroupProps = { type: 'buttonGroup' } & ButtonGroupType type PaginationProps = { type: 'pagination' } & PaginationType type ButtonProps = ButtonProp | ButtonGroupProps type LeftSectionProps = ButtonProps | PaginationProps export type PageFooterProps = { /** Right section props can include 1 - 3 Buttons */ rightSection?: ButtonProps[] /** Optional : Left section props includes a single Button or Pagination */ leftSection?: LeftSectionProps /** Optional : Override default width calculation */ customWidth?: string /** Optional : Override default class */ customClass?: string /** Optional prop to add a test id to the PageFooter for QA testing */ qaTestId?: string } const PageFooter = ({ leftSection, rightSection, customWidth, customClass, qaTestId = 'page-footer', }: PageFooterProps): React.JSX.Element => { const isMobileView = useIsMobileView() if (!leftSection && !rightSection) { throw new Error(c('errorPageFooterNeedsContent')) } useEffect(() => { const element = document.querySelectorAll('.App-content')?.[0] element?.classList?.add('has-page-footer') return () => { element?.classList?.remove('has-page-footer') } }, []) return isClient ? ( createPortal(
{leftSection ? :
} {rightSection ? :
}
, document.querySelector('body') as HTMLBodyElement, ) ) : ( <> ) } export default PageFooter const LeftSection = (props: LeftSectionProps): React.JSX.Element => { const { type } = props const view = { pagination: type === 'pagination' && , button: type === 'button' &&
) }