import type { Updater } from '@tanstack/react-table'; import type { DataTestId } from '../../../../core/types/data-props.js'; import type { StylingProps } from '../../../../core/types/styling-props.js'; /** * @public */ export interface DataTablePaginationBaseProps extends StylingProps, DataTestId { /** * The element's unique identifier. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id). */ id?: string; /** * Page size options to be displayed in the page size select. * @defaultValue [10, 20, 50, 100, 250, 500, 1000] */ pageSizeOptions?: number[]; /** * Allows opting out of automatic page index reset when new data is being set. * Be aware that if you turn off `autoResetPageIndex`, you may need to add logic * to handle resetting the pageIndex yourself. * * @remarks If the page index is resetting when you think it should not be, before * using this setting, check that you have your table input objects properly * memoized (for example rowSelection object). * @defaultValue true */ autoResetPageIndex?: boolean; /** Called when the page index changes. Provides the changed page index along with the underlying trigger. */ onPageIndexChange?: (pageIndex: number, trigger: 'user' | 'internal') => void; /** Handler that is called when the page size changes. */ onPageSizeChange?: (pageSize: number) => void; } /** * @public */ export interface DataTablePaginationPageIndexUncontrolledProps extends DataTablePaginationBaseProps { /** * Initial page index in an uncontrolled scenario. * @defaultValue 0 */ defaultPageIndex?: number; /** Current page index in a controlled scenario. */ pageIndex?: never; } /** * @public */ export interface DataTablePaginationPageIndexControlledProps extends DataTablePaginationBaseProps { /** * Initial page index in an uncontrolled scenario. * @defaultValue 0 */ defaultPageIndex?: never; /** Current page index in a controlled scenario. */ pageIndex: number; } /** * @public */ export interface DataTablePaginationPageSizeUncontrolledProps extends DataTablePaginationBaseProps { /** * Default number of rows per page (uncontrolled). * @defaultValue 100 */ defaultPageSize?: number; /** Number of rows per page (controlled) */ pageSize?: never; } /** * @public */ export interface DataTablePaginationPageSizeControlledProps extends DataTablePaginationBaseProps { /** * Default number of rows per page (uncontrolled). * @defaultValue 100 */ defaultPageSize?: never; /** Number of rows per page (controlled) */ pageSize: number; } /** * @public */ export interface DataTablePaginationClientSideProps extends DataTablePaginationBaseProps { /** Whether the previous page is available (if not, the go to previous page button should be disabled). */ enablePreviousPage?: never; /** Whether the next page is available (if not, the go to next page button should be disabled). */ enableNextPage?: never; /** * The total number of rows. * Will be used to determine the total number of pages to display the indicator "Page X of Y" for server-side pagination. */ totalRowsCount?: never; } /** * @public */ export interface DataTablePaginationServerSideProps extends DataTablePaginationBaseProps { /** Whether the previous page is available (if not, the go to previous page button should be disabled). */ enablePreviousPage: boolean; /** Whether the next page is available (if not, the go to next page button should be disabled). */ enableNextPage: boolean; /** * The total number of rows. * Will be used to determine the total number of pages to display the indicator "Page X of Y" for server-side pagination. */ totalRowsCount?: number; } /** * DataTable.Pagination props. * @public */ export type DataTablePaginationProps = (DataTablePaginationPageIndexUncontrolledProps | DataTablePaginationPageIndexControlledProps) & (DataTablePaginationPageSizeUncontrolledProps | DataTablePaginationPageSizeControlledProps) & (DataTablePaginationClientSideProps | DataTablePaginationServerSideProps); /** @internal */ export interface DataTablePaginationState { pageIndex: number; pageSize: number; enableNextPage?: boolean; enablePreviousPage?: boolean; totalRowsCount?: number; } /** @internal */ export interface DataTablePaginationOptions { enablePagination?: boolean; availablePaginationOptions?: number[]; autoResetPageIndex?: boolean; getPaginationRowModel?: (table: TTable) => () => TRowModel; manualPagination?: boolean; onPaginationChange?: (updaterOrValue: Updater, trigger?: 'user' | 'internal') => void; pageCount?: number; /** * Whether the page index is controlled. */ controlledPageIndex?: boolean; } /** @internal */ export interface DataTablePaginationInitialTableState { pagination?: Partial; } /** @internal */ export interface DataTablePaginationTableState { pagination: DataTablePaginationState; } /** @internal */ export interface DataTablePaginationInstance { /** * Updates the page index using the provided function or value. * @param updater - update function or value * @param trigger - whether the change was triggered by user interaction or internally */ setPageIndex: (updater: Updater, trigger?: 'user' | 'internal') => void; /** * Sets or updates the pagination state. * @param updater - update function or value * @param trigger - whether the change was triggered by user interaction or internally */ setPagination: (updater: Updater, trigger?: 'user' | 'internal') => void; }