UNPKG

4.05 kBTypeScriptView Raw
1import * as React from 'react';
2import { ColorValue, StyleProp, View, ViewStyle } from 'react-native';
3import type { ThemeProp } from 'src/types';
4export type Props = React.ComponentPropsWithRef<typeof View> & PaginationControlsProps & PaginationDropdownProps & {
5 /**
6 * Label text for select page dropdown to display.
7 */
8 selectPageDropdownLabel?: React.ReactNode;
9 /**
10 * AccessibilityLabel for `selectPageDropdownLabel`.
11 */
12 selectPageDropdownAccessibilityLabel?: string;
13 /**
14 * Label text to display which indicates current pagination.
15 */
16 label?: React.ReactNode;
17 /**
18 * AccessibilityLabel for `label`.
19 */
20 accessibilityLabel?: string;
21 style?: StyleProp<ViewStyle>;
22 /**
23 * @optional
24 */
25 theme?: ThemeProp;
26};
27type PaginationDropdownProps = {
28 /**
29 * The current number of rows per page.
30 */
31 numberOfItemsPerPage?: number;
32 /**
33 * Options for a number of rows per page to choose from.
34 */
35 numberOfItemsPerPageList?: Array<number>;
36 /**
37 * The function to set the number of rows per page.
38 */
39 onItemsPerPageChange?: (numberOfItemsPerPage: number) => void;
40 /**
41 * Color of the dropdown item ripple effect.
42 */
43 dropdownItemRippleColor?: ColorValue;
44 /**
45 * Color of the select page dropdown ripple effect.
46 */
47 selectPageDropdownRippleColor?: ColorValue;
48 /**
49 * @optional
50 */
51 theme?: ThemeProp;
52};
53type PaginationControlsProps = {
54 /**
55 * The currently visible page (starting with 0).
56 */
57 page: number;
58 /**
59 * The total number of pages.
60 */
61 numberOfPages: number;
62 /**
63 * Function to execute on page change.
64 */
65 onPageChange: (page: number) => void;
66 /**
67 * Whether to show fast forward and fast rewind buttons in pagination. False by default.
68 */
69 showFastPaginationControls?: boolean;
70 /**
71 * Color of the pagination control ripple effect.
72 */
73 paginationControlRippleColor?: ColorValue;
74 /**
75 * @optional
76 */
77 theme?: ThemeProp;
78};
79/**
80 * A component to show pagination for data table.
81 *
82 * ## Usage
83 * ```js
84 * import * as React from 'react';
85 * import { DataTable } from 'react-native-paper';
86 *
87 * const numberOfItemsPerPageList = [2, 3, 4];
88 *
89 * const items = [
90 * {
91 * key: 1,
92 * name: 'Page 1',
93 * },
94 * {
95 * key: 2,
96 * name: 'Page 2',
97 * },
98 * {
99 * key: 3,
100 * name: 'Page 3',
101 * },
102 * ];
103 *
104 * const MyComponent = () => {
105 * const [page, setPage] = React.useState(0);
106 * const [numberOfItemsPerPage, onItemsPerPageChange] = React.useState(numberOfItemsPerPageList[0]);
107 * const from = page * numberOfItemsPerPage;
108 * const to = Math.min((page + 1) * numberOfItemsPerPage, items.length);
109 *
110 * React.useEffect(() => {
111 * setPage(0);
112 * }, [numberOfItemsPerPage]);
113 *
114 * return (
115 * <DataTable>
116 * <DataTable.Pagination
117 * page={page}
118 * numberOfPages={Math.ceil(items.length / numberOfItemsPerPage)}
119 * onPageChange={page => setPage(page)}
120 * label={`${from + 1}-${to} of ${items.length}`}
121 * showFastPaginationControls
122 * numberOfItemsPerPageList={numberOfItemsPerPageList}
123 * numberOfItemsPerPage={numberOfItemsPerPage}
124 * onItemsPerPageChange={onItemsPerPageChange}
125 * selectPageDropdownLabel={'Rows per page'}
126 * />
127 * </DataTable>
128 * );
129 * };
130 *
131 * export default MyComponent;
132 * ```
133 */
134declare const DataTablePagination: {
135 ({ label, accessibilityLabel, page, numberOfPages, onPageChange, style, showFastPaginationControls, numberOfItemsPerPageList, numberOfItemsPerPage, onItemsPerPageChange, selectPageDropdownLabel, selectPageDropdownAccessibilityLabel, selectPageDropdownRippleColor, dropdownItemRippleColor, theme: themeOverrides, ...rest }: Props): React.JSX.Element;
136 displayName: string;
137};
138export default DataTablePagination;
139export { DataTablePagination };
140//# sourceMappingURL=DataTablePagination.d.ts.map
\No newline at end of file