@pushwoosh/dumb-components 1.1.148 → 1.1.149
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AccessForbidden/AccessForbidden.d.ts +3 -0
- package/AccessForbidden/AccessForbidden.js +3 -0
- package/Alert/Alert.d.ts +7 -0
- package/Alert/Alert.js +7 -0
- package/Alert/types.d.ts +6 -0
- package/ApplicationPreloader/ApplicationPreloader.d.ts +8 -0
- package/ApplicationPreloader/ApplicationPreloader.js +6 -0
- package/Badge/Badge.d.ts +6 -0
- package/Badge/Badge.js +6 -0
- package/Badge/types.d.ts +6 -0
- package/Banner/Banner.d.ts +7 -0
- package/Banner/Banner.js +7 -0
- package/Banner/types.d.ts +16 -0
- package/Button/Button.d.ts +19 -0
- package/Button/GhostButton.d.ts +1 -0
- package/Button/GhostButton.js +1 -0
- package/Button/RemoveButton.d.ts +6 -0
- package/Button/RemoveButton.js +6 -0
- package/Button/types.d.ts +21 -0
- package/Calendar/CalendarDropdown/CalendarDropdown.d.ts +12 -0
- package/Calendar/CalendarDropdown/CalendarDropdown.js +12 -0
- package/Calendar/CalendarDropdown/helpers.d.ts +4 -0
- package/Calendar/CalendarDropdown/helpers.js +4 -0
- package/Calendar/CalendarDropdown/types.d.ts +33 -0
- package/Calendar/CalendarSuperForm/CalendarSuperForm.d.ts +7 -0
- package/Calendar/CalendarSuperForm/CalendarSuperForm.js +7 -0
- package/Calendar/CalendarSuperForm/types.d.ts +36 -10
- package/Calendar/helpers.d.ts +10 -0
- package/Calendar/helpers.js +10 -0
- package/Calendar/types.d.ts +16 -1
- package/CardMetric/CardMetric.d.ts +7 -0
- package/CardMetric/CardMetric.js +7 -0
- package/CardMetric/types.d.ts +13 -0
- package/Checkbox/Checkbox.d.ts +6 -0
- package/Checkbox/Checkbox.js +6 -0
- package/Checkbox/types.d.ts +13 -0
- package/Chip/Chip.d.ts +7 -0
- package/Chip/Chip.js +7 -0
- package/Chip/Chip.types.d.ts +9 -0
- package/CodeEditor/CodeEditor.d.ts +7 -0
- package/CodeEditor/CodeEditor.js +7 -0
- package/CodeEditor/languages/html.d.ts +1 -0
- package/CodeEditor/languages/html.js +1 -0
- package/CodeEditor/languages/json.d.ts +1 -0
- package/CodeEditor/languages/json.js +1 -0
- package/CodeEditor/languages/liquid.d.ts +1 -0
- package/CodeEditor/languages/liquid.js +1 -0
- package/CodeEditor/types.d.ts +11 -0
- package/CrashScreen/CrashScreen.d.ts +4 -0
- package/CrashScreen/CrashScreen.js +4 -0
- package/DateTimePicker/components/DatePicker/DatePicker.d.ts +5 -0
- package/DateTimePicker/components/DatePicker/DatePicker.js +5 -0
- package/DateTimePicker/components/DatePicker/types.d.ts +9 -0
- package/DateTimePicker/components/DatePickerField/DatePickerField.d.ts +5 -0
- package/DateTimePicker/components/DatePickerField/DatePickerField.js +5 -0
- package/DateTimePicker/components/DatePickerField/types.d.ts +9 -0
- package/DateTimePicker/components/DateTimePicker/DateTimePicker.d.ts +5 -0
- package/DateTimePicker/components/DateTimePicker/DateTimePicker.js +5 -0
- package/DateTimePicker/components/DateTimePicker/types.d.ts +6 -0
- package/DateTimePicker/components/DateTimePickerField/DateTimePickerField.d.ts +5 -0
- package/DateTimePicker/components/DateTimePickerField/DateTimePickerField.js +5 -0
- package/DateTimePicker/components/DateTimePickerField/types.d.ts +9 -0
- package/DateTimePicker/types.d.ts +5 -0
- package/Drawer/components/Drawer/Drawer.d.ts +11 -0
- package/Drawer/components/Drawer/Drawer.js +11 -0
- package/Drawer/components/Drawer/types.d.ts +9 -0
- package/Drawer/components/DrawerContent/styles.d.ts +3 -0
- package/Drawer/components/DrawerContent/styles.js +3 -0
- package/Drawer/components/DrawerDocs/DrawerDocs.d.ts +7 -0
- package/Drawer/components/DrawerDocs/DrawerDocs.js +7 -0
- package/Drawer/components/DrawerDocs/hooks.d.ts +4 -0
- package/Drawer/components/DrawerDocs/hooks.js +4 -0
- package/Drawer/components/DrawerDocs/types.d.ts +4 -0
- package/DropdownMenu/components/DropdownMenu/DropdownMenu.d.ts +12 -0
- package/DropdownMenu/components/DropdownMenu/DropdownMenu.js +12 -0
- package/DropdownMenu/components/DropdownMenu/types.d.ts +15 -0
- package/DropdownMenu/components/DropdownMenuButton/DropdownMenuButton.d.ts +8 -0
- package/DropdownMenu/components/DropdownMenuButton/DropdownMenuButton.js +8 -0
- package/DropdownMenu/components/DropdownMenuButton/types.d.ts +16 -0
- package/DropdownMenu/components/DropdownMenuItem/DropdownMenuItem.d.ts +7 -0
- package/DropdownMenu/components/DropdownMenuItem/DropdownMenuItem.js +7 -0
- package/DropdownMenu/components/DropdownMenuItem/types.d.ts +6 -0
- package/DropdownMenu/components/DropdownMenuSection/DropdownMenuSection.d.ts +8 -0
- package/DropdownMenu/components/DropdownMenuSection/DropdownMenuSection.js +8 -0
- package/DropdownMenu/components/DropdownMenuSection/types.d.ts +3 -0
- package/DropdownMenu/components/DropdownMenuSubmenu/DropdownMenuSubmenu.d.ts +9 -0
- package/DropdownMenu/components/DropdownMenuSubmenu/DropdownMenuSubmenu.js +9 -0
- package/DropdownMenu/components/DropdownMenuSubmenu/types.d.ts +5 -0
- package/EditableField/EditableField.d.ts +9 -0
- package/EditableField/EditableField.js +9 -0
- package/EditableField/types.d.ts +12 -0
- package/EmailTemplatePreview/EmailTemplatePreview.d.ts +7 -0
- package/EmailTemplatePreview/EmailTemplatePreview.js +7 -0
- package/EmailTemplatePreview/components/NoEmailTemplatePreview/NoEmailTemplatePreview.d.ts +4 -0
- package/EmailTemplatePreview/components/NoEmailTemplatePreview/NoEmailTemplatePreview.js +4 -0
- package/EmailTemplatePreview/helpers.d.ts +8 -0
- package/EmailTemplatePreview/helpers.js +8 -0
- package/EmailTemplatePreview/types.d.ts +7 -0
- package/EnhancedInput/EnhancedInput.d.ts +7 -0
- package/EnhancedInput/EnhancedInput.js +7 -0
- package/EnhancedInput/SearchInput.d.ts +6 -0
- package/EnhancedInput/SearchInput.js +6 -0
- package/EnhancedInput/types.d.ts +5 -0
- package/ExportResult/ExportResult.d.ts +7 -0
- package/ExportResult/ExportResult.js +7 -0
- package/ExportResult/types.d.ts +7 -0
- package/ExternalImagePreview/ExternalImagePreview.d.ts +7 -0
- package/ExternalImagePreview/ExternalImagePreview.js +7 -0
- package/ExternalImagePreview/types.d.ts +7 -0
- package/FieldBox/FieldBox.d.ts +9 -0
- package/FieldBox/FieldBox.js +9 -0
- package/FieldBox/types.d.ts +10 -0
- package/FrequencyCapping/FrequencyCappingEdit.d.ts +7 -0
- package/FrequencyCapping/FrequencyCappingEdit.js +7 -0
- package/FrequencyCapping/FrequencyCappingInApps.d.ts +7 -0
- package/FrequencyCapping/FrequencyCappingInApps.js +7 -0
- package/FrequencyCapping/FrequencyCappingReadonly.d.ts +3 -0
- package/FrequencyCapping/FrequencyCappingReadonly.js +3 -0
- package/FrequencyCapping/types.d.ts +37 -0
- package/FrequencyCapping/types.js +1 -0
- package/GetStartedPage/GetStartedPage.d.ts +7 -0
- package/GetStartedPage/GetStartedPage.js +7 -0
- package/GetStartedPage/types.d.ts +7 -0
- package/InputFile/InputFile.d.ts +7 -0
- package/InputFile/InputFile.js +7 -0
- package/InputFile/types.d.ts +18 -0
- package/Link/Link.d.ts +18 -0
- package/Link/types.d.ts +17 -0
- package/Modal/components/Modal/Modal.d.ts +11 -0
- package/Modal/components/Modal/Modal.js +11 -0
- package/Modal/components/Modal/types.d.ts +6 -0
- package/Modal/components/ModalConfirm/ModalConfirm.d.ts +8 -0
- package/Modal/components/ModalConfirm/ModalConfirm.js +8 -0
- package/Modal/components/ModalConfirm/ModalConfirmProvider.d.ts +7 -0
- package/Modal/components/ModalConfirm/ModalConfirmProvider.js +7 -0
- package/Modal/components/ModalConfirm/hooks.d.ts +8 -0
- package/Modal/components/ModalConfirm/hooks.js +8 -0
- package/Modal/components/ModalConfirm/types.d.ts +16 -0
- package/Modal/components/ModalContent/styles.d.ts +5 -0
- package/Modal/components/ModalContent/styles.js +5 -0
- package/Modal/components/ModalTitle/ModalTitle.d.ts +6 -0
- package/Modal/components/ModalTitle/ModalTitle.js +6 -0
- package/Modal/components/ModalTitle/types.d.ts +3 -0
- package/NotificationInbox/NotificationBar.d.ts +7 -0
- package/NotificationInbox/NotificationBar.js +7 -0
- package/NotificationInbox/NotificationBell.d.ts +7 -0
- package/NotificationInbox/NotificationBell.js +7 -0
- package/NotificationInbox/NotificationInbox.d.ts +7 -0
- package/NotificationInbox/NotificationInbox.js +7 -0
- package/NotificationInbox/types.d.ts +31 -0
- package/NumberPicker/NumberPicker.d.ts +7 -0
- package/NumberPicker/NumberPicker.js +7 -0
- package/NumberPicker/types.d.ts +12 -0
- package/PageHeader/components/AutosizeInput/AutosizeInput.d.ts +7 -0
- package/PageHeader/components/AutosizeInput/AutosizeInput.js +7 -0
- package/PageHeader/components/AutosizeInput/types.d.ts +7 -0
- package/PageHeader/components/PageHeader/PageHeader.d.ts +7 -0
- package/PageHeader/components/PageHeader/PageHeader.js +7 -0
- package/PageHeader/components/PageHeader/types.d.ts +13 -0
- package/PageHeader/components/PageHeaderEditable/PageHeaderEditable.d.ts +7 -0
- package/PageHeader/components/PageHeaderEditable/PageHeaderEditable.js +7 -0
- package/PageHeader/components/PageHeaderEditable/types.d.ts +19 -0
- package/Pagination/Pagination.d.ts +7 -0
- package/Pagination/Pagination.js +7 -0
- package/Pagination/types.d.ts +7 -0
- package/Popover/Popover.d.ts +10 -0
- package/Popover/Popover.js +10 -0
- package/Popover/styles.d.ts +1 -0
- package/Popover/styles.js +1 -0
- package/Popover/types.d.ts +9 -0
- package/ProgressBar/ProgressBar.d.ts +6 -0
- package/ProgressBar/ProgressBar.js +6 -0
- package/ProgressBar/types.d.ts +7 -0
- package/PushPreview/PushPreview.d.ts +7 -0
- package/PushPreview/PushPreview.js +7 -0
- package/PushPreview/types.d.ts +17 -0
- package/Radio/Radio.d.ts +7 -0
- package/Radio/Radio.js +7 -0
- package/Radio/types.d.ts +14 -0
- package/RadioCard/RadioCard.d.ts +7 -0
- package/RadioCard/RadioCard.js +7 -0
- package/RadioCard/types.d.ts +7 -0
- package/ReCaptcha/ReCaptcha.d.ts +8 -0
- package/ReCaptcha/ReCaptcha.js +8 -0
- package/ReCaptcha/helpers.d.ts +4 -0
- package/ReCaptcha/helpers.js +4 -0
- package/ReCaptcha/hooks.d.ts +4 -0
- package/ReCaptcha/hooks.js +4 -0
- package/ReCaptcha/types.d.ts +5 -0
- package/RichMessageEditor/RichMessageEditor.d.ts +8 -0
- package/RichMessageEditor/RichMessageEditor.js +8 -0
- package/RichMessageEditor/RichMessageEditor.types.d.ts +10 -0
- package/RichMessageEditor/RichMessageViewer.d.ts +10 -0
- package/RichMessageEditor/RichMessageViewer.js +7 -0
- package/RichMessageEditor/slate/types.d.ts +5 -0
- package/RichMessageEditor/types.d.ts +1 -0
- package/RichmediaPreview/RichmediaPreview.d.ts +7 -0
- package/RichmediaPreview/RichmediaPreview.js +7 -0
- package/RichmediaPreview/hooks.d.ts +4 -0
- package/RichmediaPreview/hooks.js +4 -0
- package/RichmediaPreview/types.d.ts +13 -0
- package/Select/Select.d.ts +22 -0
- package/Select/Select.js +22 -0
- package/Select/constants.d.ts +1 -0
- package/Select/constants.js +1 -0
- package/Select/types.d.ts +19 -0
- package/SendRate/SendRateEdit.d.ts +7 -0
- package/SendRate/SendRateEdit.js +7 -0
- package/SendRate/SendRateReadonly.d.ts +3 -0
- package/SendRate/SendRateReadonly.js +3 -0
- package/SendRate/types.d.ts +20 -0
- package/Skeleton/TextSkeleton.d.ts +6 -0
- package/Skeleton/TextSkeleton.js +6 -0
- package/Skeleton/styles.d.ts +2 -0
- package/Skeleton/styles.js +2 -0
- package/Skeleton/types.d.ts +11 -0
- package/SortButton/SortButton.d.ts +6 -0
- package/SortButton/SortButton.js +6 -0
- package/SortButton/types.d.ts +11 -0
- package/Spinner/Spinner.d.ts +6 -0
- package/Spinner/Spinner.js +6 -0
- package/Spinner/types.d.ts +4 -0
- package/StatisticCard/StatisticCard.d.ts +7 -0
- package/StatisticCard/StatisticCard.js +7 -0
- package/StatisticCard/types.d.ts +21 -0
- package/Switch/Switch.d.ts +6 -0
- package/Switch/Switch.js +6 -0
- package/Switch/types.d.ts +8 -0
- package/Tabs/components/Tab/Tab.d.ts +4 -0
- package/Tabs/components/Tab/Tab.js +4 -0
- package/Tabs/components/Tab/types.d.ts +6 -0
- package/Tabs/components/TabBar/TabBar.d.ts +3 -0
- package/Tabs/components/TabBar/TabBar.js +3 -0
- package/Tabs/components/TabBar/types.d.ts +2 -0
- package/Tabs/components/TabPanel/TabPanel.d.ts +4 -0
- package/Tabs/components/TabPanel/TabPanel.js +4 -0
- package/Tabs/components/TabPanel/types.d.ts +3 -0
- package/Tabs/components/Tabs/Tabs.d.ts +11 -0
- package/Tabs/components/Tabs/Tabs.js +11 -0
- package/Tabs/components/Tabs/types.d.ts +4 -0
- package/Tabs/types.d.ts +4 -0
- package/Toast/Toast.d.ts +5 -0
- package/Toast/Toast.js +5 -0
- package/Toast/ToastProvider.d.ts +7 -0
- package/Toast/ToastProvider.js +7 -0
- package/Toast/hooks.d.ts +8 -0
- package/Toast/hooks.js +8 -0
- package/Toast/types.d.ts +24 -0
- package/Tooltip/Tooltip.d.ts +7 -0
- package/Tooltip/Tooltip.js +7 -0
- package/Tooltip/TooltipTrigger.d.ts +13 -0
- package/Tooltip/TooltipTrigger.js +7 -0
- package/Tooltip/types.d.ts +12 -0
- package/hooks/useElementWidth.d.ts +4 -3
- package/hooks/useElementWidth.js +4 -3
- package/hooks/useLayer.d.ts +7 -0
- package/hooks/useLayer.js +7 -0
- package/hooks/useOnClickOutside.d.ts +7 -0
- package/hooks/useOnClickOutside.js +7 -0
- package/native/Input.d.ts +3 -0
- package/native/Input.js +1 -0
- package/native/NativeTimeInput.d.ts +1 -0
- package/native/NativeTimeInput.js +1 -0
- package/native/Select.d.ts +1 -0
- package/native/Select.js +1 -0
- package/native/Textarea.d.ts +1 -0
- package/native/Textarea.js +1 -0
- package/package.json +2 -3
- package/polyglot/react.d.ts +19 -0
- package/polyglot/react.js +19 -0
- package/polyglot/types.d.ts +4 -0
- package/shared/dropdownField/FieldInput.d.ts +1 -0
- package/shared/dropdownField/FieldInput.js +1 -0
- package/shared/dropdownField/FieldShell.d.ts +4 -0
- package/shared/dropdownField/FieldShell.js +4 -0
- package/shared/dropdownField/SuggestionsDropdown.d.ts +4 -0
- package/shared/dropdownField/SuggestionsDropdown.js +4 -0
- package/shared/dropdownField/constants.d.ts +1 -0
- package/shared/dropdownField/constants.js +1 -0
- package/shared/dropdownField/shared.d.ts +7 -0
- package/shared/dropdownField/shared.js +7 -0
- package/shared/dropdownField/types.d.ts +7 -0
- package/shared/dropdownField/useActiveIndex.d.ts +4 -0
- package/shared/dropdownField/useActiveIndex.js +4 -0
- package/shared/dropdownField/useAsyncItems.d.ts +4 -0
- package/shared/dropdownField/useAsyncItems.js +4 -0
- package/shared/dropdownField/useDebouncedValue.d.ts +1 -0
- package/shared/dropdownField/useDebouncedValue.js +1 -0
- package/shared/dropdownField/useDropdownItems.d.ts +4 -0
- package/shared/dropdownField/useDropdownItems.js +4 -0
- package/shared/dropdownField/useDropdownPosition.d.ts +4 -0
- package/shared/dropdownField/useDropdownPosition.js +4 -0
- package/shared/dropdownField/useFieldOpenEffects.d.ts +4 -0
- package/shared/dropdownField/useFieldOpenEffects.js +4 -0
- package/shared/dropdownField/useListNavigation.d.ts +5 -0
- package/shared/dropdownField/useListNavigation.js +5 -0
- package/Alert/ai-documentation.md +0 -132
- package/Badge/ai-documentation.md +0 -155
- package/Banner/ai-documentation.md +0 -285
- package/Button/ai-documentation.md +0 -247
- package/CardMetric/ai-documentation.md +0 -277
- package/Checkbox/ai-documentation.md +0 -231
- package/Chip/ai-documentation.md +0 -281
- package/CodeEditor/ai-documentation.md +0 -350
- package/DateTimePicker/ai-documentation.md +0 -400
- package/Drawer/ai-documentation.md +0 -417
- package/EnhancedInput/ai-documentation.md +0 -352
- package/InputFile/ai-documentation.md +0 -420
- package/Modal/ai-documentation.md +0 -285
- package/PageHeader/ai-documentation.md +0 -511
- package/Pagination/ai-documentation.md +0 -509
- package/Popover/ai-documentation.md +0 -625
- package/ProgressBar/ai-documentation.md +0 -533
- package/Radio/ai-documentation.md +0 -243
- package/Select/ai-documentation.md +0 -374
- package/Skeleton/ai-documentation.md +0 -574
- package/Spinner/ai-documentation.md +0 -607
- package/Switch/ai-documentation.md +0 -312
- package/Tabs/ai-documentation.md +0 -475
- package/Toast/ai-documentation.md +0 -220
- package/Tooltip/ai-documentation.md +0 -340
- package/ai-documentation.md +0 -124
- package/native/ai-documentation.md +0 -485
|
@@ -1,509 +0,0 @@
|
|
|
1
|
-
# Pagination Component - @pushwoosh/dumb-components
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
- **Component Name**: Pagination
|
|
6
|
-
- **Import Path**: `@pushwoosh/dumb-components`
|
|
7
|
-
- **Files**:
|
|
8
|
-
- `/src/Pagination/Pagination.tsx` - Main component implementation
|
|
9
|
-
- `/src/Pagination/types.ts` - TypeScript type definitions
|
|
10
|
-
- `/src/Pagination/styles.ts` - Styled components
|
|
11
|
-
- `/src/Pagination/helpers.ts` - Helper utilities
|
|
12
|
-
- `/src/Pagination/index.ts` - Component exports
|
|
13
|
-
- **Type**: Navigation
|
|
14
|
-
- **Description**: A pagination component for navigating through multiple pages of content. Features smart page number display, ellipsis for large page ranges, navigation arrows, and loading states.
|
|
15
|
-
|
|
16
|
-
## TypeScript Interfaces
|
|
17
|
-
|
|
18
|
-
```typescript
|
|
19
|
-
export type PaginationProps = Omit<JSX.IntrinsicElements['div'], 'ref'> & {
|
|
20
|
-
readonly boxRef?: Ref<HTMLDivElement>;
|
|
21
|
-
readonly activePage: string | number;
|
|
22
|
-
readonly totalPages: string | number;
|
|
23
|
-
readonly adjacentPagesCount?: number;
|
|
24
|
-
readonly isLoading?: boolean;
|
|
25
|
-
readonly onChangePage: (page: number) => any;
|
|
26
|
-
};
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## Import & Usage
|
|
30
|
-
|
|
31
|
-
```typescript
|
|
32
|
-
import { Pagination } from '@pushwoosh/dumb-components';
|
|
33
|
-
|
|
34
|
-
// Basic usage
|
|
35
|
-
function MyComponent() {
|
|
36
|
-
const [currentPage, setCurrentPage] = useState(1);
|
|
37
|
-
const totalPages = 10;
|
|
38
|
-
|
|
39
|
-
return (
|
|
40
|
-
<div>
|
|
41
|
-
{/* Your content */}
|
|
42
|
-
<div>Page {currentPage} content...</div>
|
|
43
|
-
|
|
44
|
-
{/* Pagination */}
|
|
45
|
-
<Pagination
|
|
46
|
-
activePage={currentPage}
|
|
47
|
-
totalPages={totalPages}
|
|
48
|
-
onChangePage={setCurrentPage}
|
|
49
|
-
/>
|
|
50
|
-
</div>
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// With loading state
|
|
55
|
-
function LoadingPagination() {
|
|
56
|
-
const [currentPage, setCurrentPage] = useState(1);
|
|
57
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
58
|
-
const totalPages = 25;
|
|
59
|
-
|
|
60
|
-
const handlePageChange = async (page: number) => {
|
|
61
|
-
setIsLoading(true);
|
|
62
|
-
try {
|
|
63
|
-
await fetchPageData(page);
|
|
64
|
-
setCurrentPage(page);
|
|
65
|
-
} catch (error) {
|
|
66
|
-
console.error('Failed to load page:', error);
|
|
67
|
-
} finally {
|
|
68
|
-
setIsLoading(false);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
return (
|
|
73
|
-
<Pagination
|
|
74
|
-
activePage={currentPage}
|
|
75
|
-
totalPages={totalPages}
|
|
76
|
-
isLoading={isLoading}
|
|
77
|
-
onChangePage={handlePageChange}
|
|
78
|
-
/>
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
## Advanced Examples
|
|
84
|
-
|
|
85
|
-
```typescript
|
|
86
|
-
// Data table with pagination
|
|
87
|
-
function DataTable() {
|
|
88
|
-
const [currentPage, setCurrentPage] = useState(1);
|
|
89
|
-
const [data, setData] = useState([]);
|
|
90
|
-
const [totalCount, setTotalCount] = useState(0);
|
|
91
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
92
|
-
|
|
93
|
-
const itemsPerPage = 10;
|
|
94
|
-
const totalPages = Math.ceil(totalCount / itemsPerPage);
|
|
95
|
-
|
|
96
|
-
const loadData = async (page: number) => {
|
|
97
|
-
setIsLoading(true);
|
|
98
|
-
try {
|
|
99
|
-
const response = await fetchData({
|
|
100
|
-
page,
|
|
101
|
-
limit: itemsPerPage
|
|
102
|
-
});
|
|
103
|
-
setData(response.data);
|
|
104
|
-
setTotalCount(response.total);
|
|
105
|
-
} catch (error) {
|
|
106
|
-
console.error('Failed to load data:', error);
|
|
107
|
-
} finally {
|
|
108
|
-
setIsLoading(false);
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
useEffect(() => {
|
|
113
|
-
loadData(currentPage);
|
|
114
|
-
}, [currentPage]);
|
|
115
|
-
|
|
116
|
-
const handlePageChange = (page: number) => {
|
|
117
|
-
setCurrentPage(page);
|
|
118
|
-
// Optionally scroll to top
|
|
119
|
-
window.scrollTo({ top: 0, behavior: 'smooth' });
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
return (
|
|
123
|
-
<div>
|
|
124
|
-
<table>
|
|
125
|
-
<thead>
|
|
126
|
-
<tr>
|
|
127
|
-
<th>ID</th>
|
|
128
|
-
<th>Name</th>
|
|
129
|
-
<th>Email</th>
|
|
130
|
-
<th>Status</th>
|
|
131
|
-
</tr>
|
|
132
|
-
</thead>
|
|
133
|
-
<tbody>
|
|
134
|
-
{isLoading ? (
|
|
135
|
-
<tr>
|
|
136
|
-
<td colSpan={4}>Loading...</td>
|
|
137
|
-
</tr>
|
|
138
|
-
) : (
|
|
139
|
-
data.map(item => (
|
|
140
|
-
<tr key={item.id}>
|
|
141
|
-
<td>{item.id}</td>
|
|
142
|
-
<td>{item.name}</td>
|
|
143
|
-
<td>{item.email}</td>
|
|
144
|
-
<td>{item.status}</td>
|
|
145
|
-
</tr>
|
|
146
|
-
))
|
|
147
|
-
)}
|
|
148
|
-
</tbody>
|
|
149
|
-
</table>
|
|
150
|
-
|
|
151
|
-
{totalPages > 1 && (
|
|
152
|
-
<div style={{ marginTop: '20px', display: 'flex', justifyContent: 'center' }}>
|
|
153
|
-
<Pagination
|
|
154
|
-
activePage={currentPage}
|
|
155
|
-
totalPages={totalPages}
|
|
156
|
-
isLoading={isLoading}
|
|
157
|
-
onChangePage={handlePageChange}
|
|
158
|
-
/>
|
|
159
|
-
</div>
|
|
160
|
-
)}
|
|
161
|
-
</div>
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// Search results with pagination
|
|
166
|
-
function SearchResults() {
|
|
167
|
-
const [query, setQuery] = useState('');
|
|
168
|
-
const [currentPage, setCurrentPage] = useState(1);
|
|
169
|
-
const [results, setResults] = useState([]);
|
|
170
|
-
const [totalResults, setTotalResults] = useState(0);
|
|
171
|
-
const [isSearching, setIsSearching] = useState(false);
|
|
172
|
-
|
|
173
|
-
const resultsPerPage = 20;
|
|
174
|
-
const totalPages = Math.ceil(totalResults / resultsPerPage);
|
|
175
|
-
|
|
176
|
-
const performSearch = async (searchQuery: string, page: number) => {
|
|
177
|
-
if (!searchQuery.trim()) {
|
|
178
|
-
setResults([]);
|
|
179
|
-
setTotalResults(0);
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
setIsSearching(true);
|
|
184
|
-
try {
|
|
185
|
-
const response = await searchAPI({
|
|
186
|
-
query: searchQuery,
|
|
187
|
-
page,
|
|
188
|
-
limit: resultsPerPage
|
|
189
|
-
});
|
|
190
|
-
setResults(response.results);
|
|
191
|
-
setTotalResults(response.totalCount);
|
|
192
|
-
} catch (error) {
|
|
193
|
-
console.error('Search failed:', error);
|
|
194
|
-
setResults([]);
|
|
195
|
-
setTotalResults(0);
|
|
196
|
-
} finally {
|
|
197
|
-
setIsSearching(false);
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
// Search when query changes
|
|
202
|
-
useEffect(() => {
|
|
203
|
-
setCurrentPage(1);
|
|
204
|
-
performSearch(query, 1);
|
|
205
|
-
}, [query]);
|
|
206
|
-
|
|
207
|
-
// Load new page
|
|
208
|
-
const handlePageChange = (page: number) => {
|
|
209
|
-
setCurrentPage(page);
|
|
210
|
-
performSearch(query, page);
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
return (
|
|
214
|
-
<div>
|
|
215
|
-
<input
|
|
216
|
-
type="text"
|
|
217
|
-
placeholder="Search..."
|
|
218
|
-
value={query}
|
|
219
|
-
onChange={(e) => setQuery(e.target.value)}
|
|
220
|
-
/>
|
|
221
|
-
|
|
222
|
-
<div>
|
|
223
|
-
{isSearching ? (
|
|
224
|
-
<div>Searching...</div>
|
|
225
|
-
) : (
|
|
226
|
-
<div>
|
|
227
|
-
<p>{totalResults} results found</p>
|
|
228
|
-
{results.map(result => (
|
|
229
|
-
<div key={result.id} style={{ padding: '10px', borderBottom: '1px solid #eee' }}>
|
|
230
|
-
<h3>{result.title}</h3>
|
|
231
|
-
<p>{result.description}</p>
|
|
232
|
-
</div>
|
|
233
|
-
))}
|
|
234
|
-
</div>
|
|
235
|
-
)}
|
|
236
|
-
</div>
|
|
237
|
-
|
|
238
|
-
{totalPages > 1 && (
|
|
239
|
-
<Pagination
|
|
240
|
-
activePage={currentPage}
|
|
241
|
-
totalPages={totalPages}
|
|
242
|
-
isLoading={isSearching}
|
|
243
|
-
onChangePage={handlePageChange}
|
|
244
|
-
/>
|
|
245
|
-
)}
|
|
246
|
-
</div>
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// Custom adjacent pages count
|
|
251
|
-
function CustomPagination() {
|
|
252
|
-
const [currentPage, setCurrentPage] = useState(1);
|
|
253
|
-
const totalPages = 100;
|
|
254
|
-
|
|
255
|
-
return (
|
|
256
|
-
<div>
|
|
257
|
-
<h3>Default Adjacent Pages (2)</h3>
|
|
258
|
-
<Pagination
|
|
259
|
-
activePage={currentPage}
|
|
260
|
-
totalPages={totalPages}
|
|
261
|
-
onChangePage={setCurrentPage}
|
|
262
|
-
/>
|
|
263
|
-
|
|
264
|
-
<h3>More Adjacent Pages (5)</h3>
|
|
265
|
-
<Pagination
|
|
266
|
-
activePage={currentPage}
|
|
267
|
-
totalPages={totalPages}
|
|
268
|
-
adjacentPagesCount={5}
|
|
269
|
-
onChangePage={setCurrentPage}
|
|
270
|
-
/>
|
|
271
|
-
|
|
272
|
-
<h3>Fewer Adjacent Pages (1)</h3>
|
|
273
|
-
<Pagination
|
|
274
|
-
activePage={currentPage}
|
|
275
|
-
totalPages={totalPages}
|
|
276
|
-
adjacentPagesCount={1}
|
|
277
|
-
onChangePage={setCurrentPage}
|
|
278
|
-
/>
|
|
279
|
-
</div>
|
|
280
|
-
);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
// URL-synced pagination
|
|
284
|
-
function URLSyncedPagination() {
|
|
285
|
-
const [searchParams, setSearchParams] = useSearchParams();
|
|
286
|
-
const currentPage = parseInt(searchParams.get('page') || '1', 10);
|
|
287
|
-
const [data, setData] = useState([]);
|
|
288
|
-
const [totalPages, setTotalPages] = useState(0);
|
|
289
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
290
|
-
|
|
291
|
-
const handlePageChange = (page: number) => {
|
|
292
|
-
setSearchParams({ page: page.toString() });
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
const loadPageData = async (page: number) => {
|
|
296
|
-
setIsLoading(true);
|
|
297
|
-
try {
|
|
298
|
-
const response = await fetchPageData(page);
|
|
299
|
-
setData(response.data);
|
|
300
|
-
setTotalPages(response.totalPages);
|
|
301
|
-
} catch (error) {
|
|
302
|
-
console.error('Failed to load page:', error);
|
|
303
|
-
} finally {
|
|
304
|
-
setIsLoading(false);
|
|
305
|
-
}
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
useEffect(() => {
|
|
309
|
-
loadPageData(currentPage);
|
|
310
|
-
}, [currentPage]);
|
|
311
|
-
|
|
312
|
-
return (
|
|
313
|
-
<div>
|
|
314
|
-
<div>
|
|
315
|
-
{isLoading ? (
|
|
316
|
-
<div>Loading page {currentPage}...</div>
|
|
317
|
-
) : (
|
|
318
|
-
<div>
|
|
319
|
-
<h2>Page {currentPage} Data</h2>
|
|
320
|
-
{data.map(item => (
|
|
321
|
-
<div key={item.id}>{item.name}</div>
|
|
322
|
-
))}
|
|
323
|
-
</div>
|
|
324
|
-
)}
|
|
325
|
-
</div>
|
|
326
|
-
|
|
327
|
-
{totalPages > 1 && (
|
|
328
|
-
<Pagination
|
|
329
|
-
activePage={currentPage}
|
|
330
|
-
totalPages={totalPages}
|
|
331
|
-
isLoading={isLoading}
|
|
332
|
-
onChangePage={handlePageChange}
|
|
333
|
-
/>
|
|
334
|
-
)}
|
|
335
|
-
</div>
|
|
336
|
-
);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
// Form with pagination for long lists
|
|
340
|
-
function FormWithPagination() {
|
|
341
|
-
const [selectedItems, setSelectedItems] = useState<number[]>([]);
|
|
342
|
-
const [currentPage, setCurrentPage] = useState(1);
|
|
343
|
-
const [allItems, setAllItems] = useState<any[]>([]);
|
|
344
|
-
|
|
345
|
-
const itemsPerPage = 5;
|
|
346
|
-
const totalPages = Math.ceil(allItems.length / itemsPerPage);
|
|
347
|
-
const startIndex = (currentPage - 1) * itemsPerPage;
|
|
348
|
-
const currentItems = allItems.slice(startIndex, startIndex + itemsPerPage);
|
|
349
|
-
|
|
350
|
-
const toggleItemSelection = (itemId: number) => {
|
|
351
|
-
setSelectedItems(prev =>
|
|
352
|
-
prev.includes(itemId)
|
|
353
|
-
? prev.filter(id => id !== itemId)
|
|
354
|
-
: [...prev, itemId]
|
|
355
|
-
);
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
const handleSubmit = () => {
|
|
359
|
-
console.log('Selected items:', selectedItems);
|
|
360
|
-
// Process selected items
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
return (
|
|
364
|
-
<form>
|
|
365
|
-
<h3>Select Items ({selectedItems.length} selected)</h3>
|
|
366
|
-
|
|
367
|
-
<div>
|
|
368
|
-
{currentItems.map(item => (
|
|
369
|
-
<label key={item.id} style={{ display: 'block', padding: '8px' }}>
|
|
370
|
-
<input
|
|
371
|
-
type="checkbox"
|
|
372
|
-
checked={selectedItems.includes(item.id)}
|
|
373
|
-
onChange={() => toggleItemSelection(item.id)}
|
|
374
|
-
/>
|
|
375
|
-
{item.name}
|
|
376
|
-
</label>
|
|
377
|
-
))}
|
|
378
|
-
</div>
|
|
379
|
-
|
|
380
|
-
{totalPages > 1 && (
|
|
381
|
-
<Pagination
|
|
382
|
-
activePage={currentPage}
|
|
383
|
-
totalPages={totalPages}
|
|
384
|
-
onChangePage={setCurrentPage}
|
|
385
|
-
/>
|
|
386
|
-
)}
|
|
387
|
-
|
|
388
|
-
<button type="button" onClick={handleSubmit}>
|
|
389
|
-
Submit Selected ({selectedItems.length})
|
|
390
|
-
</button>
|
|
391
|
-
</form>
|
|
392
|
-
);
|
|
393
|
-
}
|
|
394
|
-
```
|
|
395
|
-
|
|
396
|
-
## Props Reference
|
|
397
|
-
|
|
398
|
-
| Prop | Type | Default | Required | Description |
|
|
399
|
-
|------|------|---------|----------|-------------|
|
|
400
|
-
| `boxRef` | `Ref<HTMLDivElement>` | `undefined` | No | Ref for the pagination container |
|
|
401
|
-
| `activePage` | `string \| number` | - | Yes | Currently active page number |
|
|
402
|
-
| `totalPages` | `string \| number` | - | Yes | Total number of pages |
|
|
403
|
-
| `adjacentPagesCount` | `number` | `2` | No | Number of pages to show on each side of active page |
|
|
404
|
-
| `isLoading` | `boolean` | `false` | No | Whether pagination is in loading state |
|
|
405
|
-
| `onChangePage` | `(page: number) => any` | - | Yes | Callback fired when page changes |
|
|
406
|
-
|
|
407
|
-
## AI Agent Guidelines
|
|
408
|
-
|
|
409
|
-
### Recommended Patterns
|
|
410
|
-
|
|
411
|
-
1. **Controlled State**: Always manage pagination state in parent component
|
|
412
|
-
```typescript
|
|
413
|
-
const [currentPage, setCurrentPage] = useState(1);
|
|
414
|
-
|
|
415
|
-
<Pagination
|
|
416
|
-
activePage={currentPage}
|
|
417
|
-
totalPages={totalPages}
|
|
418
|
-
onChangePage={setCurrentPage}
|
|
419
|
-
/>
|
|
420
|
-
```
|
|
421
|
-
|
|
422
|
-
2. **Loading States**: Handle async page changes properly
|
|
423
|
-
```typescript
|
|
424
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
425
|
-
|
|
426
|
-
const handlePageChange = async (page: number) => {
|
|
427
|
-
setIsLoading(true);
|
|
428
|
-
await loadPageData(page);
|
|
429
|
-
setIsLoading(false);
|
|
430
|
-
setCurrentPage(page);
|
|
431
|
-
};
|
|
432
|
-
```
|
|
433
|
-
|
|
434
|
-
3. **URL Synchronization**: Sync pagination with browser URL for better UX
|
|
435
|
-
```typescript
|
|
436
|
-
const [searchParams, setSearchParams] = useSearchParams();
|
|
437
|
-
const page = parseInt(searchParams.get('page') || '1', 10);
|
|
438
|
-
|
|
439
|
-
const handlePageChange = (newPage: number) => {
|
|
440
|
-
setSearchParams({ page: newPage.toString() });
|
|
441
|
-
};
|
|
442
|
-
```
|
|
443
|
-
|
|
444
|
-
### Common Mistakes to Avoid
|
|
445
|
-
|
|
446
|
-
1. **Invalid Page Numbers**: Don't pass page numbers outside valid range (1 to totalPages)
|
|
447
|
-
2. **Missing Loading States**: Always disable pagination during data loading
|
|
448
|
-
3. **Inconsistent State**: Ensure activePage and displayed data are synchronized
|
|
449
|
-
4. **Memory Leaks**: Cancel pending requests when component unmounts or page changes
|
|
450
|
-
5. **Poor Performance**: Don't reload all data when only page changes
|
|
451
|
-
|
|
452
|
-
### Integration Tips
|
|
453
|
-
|
|
454
|
-
1. **Data Management**: Works well with server-side pagination
|
|
455
|
-
```typescript
|
|
456
|
-
// Server-side pagination
|
|
457
|
-
const response = await fetchData({
|
|
458
|
-
page: currentPage,
|
|
459
|
-
limit: itemsPerPage,
|
|
460
|
-
sort: 'createdAt',
|
|
461
|
-
order: 'desc'
|
|
462
|
-
});
|
|
463
|
-
```
|
|
464
|
-
|
|
465
|
-
2. **Search Integration**: Reset to page 1 when search query changes
|
|
466
|
-
```typescript
|
|
467
|
-
useEffect(() => {
|
|
468
|
-
setCurrentPage(1); // Reset to first page
|
|
469
|
-
performSearch(query);
|
|
470
|
-
}, [query]);
|
|
471
|
-
```
|
|
472
|
-
|
|
473
|
-
3. **Form Integration**: Preserve selections across pages
|
|
474
|
-
```typescript
|
|
475
|
-
const [globalSelections, setGlobalSelections] = useState(new Set());
|
|
476
|
-
|
|
477
|
-
// Maintain selections when changing pages
|
|
478
|
-
const handlePageChange = (page: number) => {
|
|
479
|
-
// Save current page selections
|
|
480
|
-
saveCurrentPageSelections();
|
|
481
|
-
// Load new page
|
|
482
|
-
setCurrentPage(page);
|
|
483
|
-
};
|
|
484
|
-
```
|
|
485
|
-
|
|
486
|
-
4. **Accessibility**: Component handles keyboard navigation automatically
|
|
487
|
-
5. **Performance Optimization**: Use React.memo for list items to prevent unnecessary re-renders
|
|
488
|
-
|
|
489
|
-
6. **Error Handling**: Handle pagination errors gracefully
|
|
490
|
-
```typescript
|
|
491
|
-
const handlePageChange = async (page: number) => {
|
|
492
|
-
try {
|
|
493
|
-
await loadPageData(page);
|
|
494
|
-
setCurrentPage(page);
|
|
495
|
-
} catch (error) {
|
|
496
|
-
// Stay on current page if load fails
|
|
497
|
-
console.error('Failed to load page:', error);
|
|
498
|
-
// Optionally show error message to user
|
|
499
|
-
}
|
|
500
|
-
};
|
|
501
|
-
```
|
|
502
|
-
|
|
503
|
-
## Related Components
|
|
504
|
-
|
|
505
|
-
- **Button**: Used internally for page navigation buttons
|
|
506
|
-
- **Spinner**: Often used together for loading states
|
|
507
|
-
- **Table**: Commonly used with data tables
|
|
508
|
-
- **Select**: Alternative for page size selection
|
|
509
|
-
- **Input**: For jump-to-page functionality
|