import MUITablePagination, { TablePaginationBaseProps, TablePaginationTypeMap } from '@mui/material/TablePagination'; import { TablePaginationActionsProps } from '@mui/material/TablePagination/TablePaginationActions'; import useMediaQuery from '@mui/material/useMediaQuery'; import clsx from 'clsx'; import { ComponentType, memo, ReactNode } from 'react'; import { PaginationActions } from './PaginationActions/PaginationActions'; import css from './Pagination.module.scss'; export type MutatedMUITablePaginationProps = TablePaginationTypeMap< Record, ComponentType >['props']; export interface PaginationProps extends MutatedMUITablePaginationProps { /** The label in the displayed pages, for example "of" in "page 1 of 10" */ labelPaginationOf: ReactNode; /** Data-qa tag to apply to the search bar and input element */ 'data-qa'?: string; /** Custom CSS classes to pass to the button */ customClasses?: string | string[]; /** * The component used for displaying the actions. * Either a string to use a HTML element or a component. * @default TablePaginationActions */ customPagination?: React.ElementType; } /** * Constructs a Table pagination using pre-defined Rijkswaterstaat styling * @param props Props to pass to the table pagination * @example * ```jsx * * ``` */ export const Pagination = memo((props: PaginationProps) => { const isOnMobile = useMediaQuery('(max-width: 1024px)'); return ( `${from <= 9 ? `0${from}` : from}-${to} ${props.labelPaginationOf} ${count}` } onPageChange={props.onPageChange} onRowsPerPageChange={props.onRowsPerPageChange} className={clsx(css.tablePagination, { [css.tablePaginationMobile]: isOnMobile }, props.customClasses)} classes={{ root: css.text, selectIcon: css.selectIcon, menuItem: css.text }} rowsPerPage={props.rowsPerPage} rowsPerPageOptions={props.rowsPerPageOptions} ActionsComponent={props.customPagination || PaginationActions} data-qa={props['data-qa']} /> ); });