UNPKG

8.31 kBTypeScriptView Raw
1import * as React from 'react';
2import { PolymorphicProps, SlotComponentProps } from '../utils';
3import TablePaginationActions from './TablePaginationActions';
4import { ItemAriaLabelType } from './common.types';
5export interface LabelDisplayedRowsArgs {
6 from: number;
7 to: number;
8 count: number;
9 page: number;
10}
11export interface TablePaginationRootSlotPropsOverrides {
12}
13export interface TablePaginationActionsSlotPropsOverrides {
14}
15export interface TablePaginationSelectSlotPropsOverrides {
16}
17export interface TablePaginationSelectLabelSlotPropsOverrides {
18}
19export interface TablePaginationMenuItemSlotPropsOverrides {
20}
21export interface TablePaginationDisplayedRowsSlotPropsOverrides {
22}
23export interface TablePaginationToolbarSlotPropsOverrides {
24}
25export interface TablePaginationSpacerSlotPropsOverrides {
26}
27export interface TablePaginationOwnProps {
28 /**
29 * @ignore
30 */
31 colSpan?: number;
32 /**
33 * The components used for each slot inside the TablePagination.
34 * Either a string to use a HTML element or a component.
35 * @default {}
36 */
37 slots?: TablePaginationSlots;
38 /**
39 * The props used for each slot inside the TablePagination.
40 * @default {}
41 */
42 slotProps?: {
43 root?: SlotComponentProps<'td', TablePaginationRootSlotPropsOverrides, TablePaginationOwnerState>;
44 actions?: SlotComponentProps<typeof TablePaginationActions, TablePaginationActionsSlotPropsOverrides, TablePaginationOwnerState>;
45 select?: SlotComponentProps<'select', TablePaginationSelectSlotPropsOverrides, TablePaginationOwnerState>;
46 selectLabel?: SlotComponentProps<'p', TablePaginationSelectLabelSlotPropsOverrides, TablePaginationOwnerState>;
47 menuItem?: SlotComponentProps<'option', TablePaginationMenuItemSlotPropsOverrides, TablePaginationOwnerState>;
48 displayedRows?: SlotComponentProps<'p', TablePaginationDisplayedRowsSlotPropsOverrides, TablePaginationOwnerState>;
49 toolbar?: SlotComponentProps<'div', TablePaginationToolbarSlotPropsOverrides, TablePaginationOwnerState>;
50 spacer?: SlotComponentProps<'div', TablePaginationSpacerSlotPropsOverrides, TablePaginationOwnerState>;
51 };
52 /**
53 * The total number of rows.
54 *
55 * To enable server side pagination for an unknown number of items, provide -1.
56 */
57 count: number;
58 /**
59 * Accepts a function which returns a string value that provides a user-friendly name for the current page.
60 * This is important for screen reader users.
61 *
62 * For localization purposes, you can use the provided [translations](/material-ui/guides/localization/).
63 * @param {string} type The link or button type to format ('first' | 'last' | 'next' | 'previous').
64 * @returns {string}
65 * @default function defaultGetAriaLabel(type: ItemAriaLabelType) {
66 * return `Go to ${type} page`;
67 * }
68 */
69 getItemAriaLabel?: (type: ItemAriaLabelType) => string;
70 /**
71 * Customize the displayed rows label. Invoked with a `{ from, to, count, page }`
72 * object.
73 *
74 * For localization purposes, you can use the provided [translations](/material-ui/guides/localization/).
75 * @default function defaultLabelDisplayedRows({ from, to, count }: LabelDisplayedRowsArgs) {
76 * return `${from}–${to} of ${count !== -1 ? count : `more than ${to}`}`;
77 * }
78 */
79 labelDisplayedRows?: (paginationInfo: LabelDisplayedRowsArgs) => React.ReactNode;
80 /**
81 * Id of the label element within the pagination.
82 */
83 labelId?: string;
84 /**
85 * Customize the rows per page label.
86 *
87 * For localization purposes, you can use the provided [translations](/material-ui/guides/localization/).
88 * @default 'Rows per page:'
89 */
90 labelRowsPerPage?: React.ReactNode;
91 /**
92 * Callback fired when the page is changed.
93 *
94 * @param {React.MouseEvent<HTMLButtonElement> | null} event The event source of the callback.
95 * @param {number} page The page selected.
96 */
97 onPageChange: (event: React.MouseEvent<HTMLButtonElement> | null, page: number) => void;
98 /**
99 * Callback fired when the number of rows per page is changed.
100 *
101 * @param {React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>} event The event source of the callback.
102 */
103 onRowsPerPageChange?: React.ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement>;
104 /**
105 * The zero-based index of the current page.
106 */
107 page: number;
108 /**
109 * The number of rows per page.
110 *
111 * Set -1 to display all the rows.
112 */
113 rowsPerPage: number;
114 /**
115 * Customizes the options of the rows per page select field. If less than two options are
116 * available, no select field will be displayed.
117 * Use -1 for the value with a custom label to show all the rows.
118 * @default [10, 25, 50, 100]
119 */
120 rowsPerPageOptions?: Array<number | {
121 value: number;
122 label: string;
123 }>;
124 /**
125 * Id of the select element within the pagination.
126 */
127 selectId?: string;
128}
129export interface TablePaginationSlots {
130 /**
131 * The component that renders the root.
132 * @default 'td'
133 */
134 root?: React.ElementType;
135 /**
136 * The component that renders the actions.
137 * @default TablePaginationActions
138 */
139 actions?: React.ElementType;
140 /**
141 * The component that renders the select.
142 * @default 'select'
143 */
144 select?: React.ElementType;
145 /**
146 * The component that renders the select label.
147 * @default 'p'
148 */
149 selectLabel?: React.ElementType;
150 /**
151 * The component that renders the menu item.
152 * @default 'option'
153 */
154 menuItem?: React.ElementType;
155 /**
156 * The component that renders the displayed rows.
157 * @default 'p'
158 */
159 displayedRows?: React.ElementType;
160 /**
161 * The component that renders the toolbar.
162 * @default 'div'
163 */
164 toolbar?: React.ElementType;
165 /**
166 * The component that renders the spacer.
167 * @default 'div'
168 */
169 spacer?: React.ElementType;
170}
171export interface TablePaginationTypeMap<AdditionalProps = {}, RootComponentType extends React.ElementType = 'td'> {
172 props: TablePaginationOwnProps & AdditionalProps;
173 defaultComponent: RootComponentType;
174}
175export type TablePaginationProps<RootComponentType extends React.ElementType = TablePaginationTypeMap['defaultComponent']> = PolymorphicProps<TablePaginationTypeMap<{}, RootComponentType>, RootComponentType>;
176export type TablePaginationOwnerState = TablePaginationOwnProps;
177export type TablePaginationRootSlotProps = {
178 children?: React.ReactNode;
179 className?: string;
180 colSpan?: number;
181 ownerState: TablePaginationOwnerState;
182 ref?: React.Ref<any>;
183};
184export type TablePaginationSelectSlotProps = {
185 ['aria-label']: string;
186 ['aria-labelledby']?: string;
187 children?: React.ReactNode;
188 className?: string;
189 id?: string;
190 onChange: (event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => void;
191 ownerState: TablePaginationOwnerState;
192 value: React.SelectHTMLAttributes<HTMLSelectElement>['value'];
193};
194export type TablePaginationActionsSlotProps = {
195 className?: string;
196 count: number;
197 getItemAriaLabel: (type: ItemAriaLabelType) => string;
198 onPageChange: (event: React.MouseEvent<HTMLButtonElement> | null, page: number) => void;
199 ownerState: TablePaginationOwnerState;
200 page: number;
201 rowsPerPage: number;
202};
203export type TablePaginationMenuItemSlotProps = {
204 children?: React.ReactNode;
205 className?: string;
206 ownerState: TablePaginationOwnerState;
207 value: React.SelectHTMLAttributes<HTMLSelectElement>['value'];
208};
209export type TablePaginationSelectLabelSlotProps = {
210 children?: React.ReactNode;
211 className?: string;
212 id?: string;
213 ownerState: TablePaginationOwnerState;
214};
215export type TablePaginationDisplayedRowsSlotProps = {
216 children?: React.ReactNode;
217 className?: string;
218 ownerState: TablePaginationOwnerState;
219};
220export type TablePaginationToolbarSlotProps = {
221 children?: React.ReactNode;
222 className?: string;
223 ownerState: TablePaginationOwnerState;
224};
225export type TablePaginationSpacerSlotProps = {
226 className?: string;
227 ownerState: TablePaginationOwnerState;
228};