@superdangerous/app-framework 4.16.35 → 4.16.36
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/package.json +4 -4
- package/ui/dist/data-table.d.mts +457 -0
- package/ui/dist/data-table.d.ts +457 -0
- package/ui/dist/data-table.js +2 -0
- package/ui/dist/data-table.js.map +1 -0
- package/ui/dist/data-table.mjs +2 -0
- package/ui/dist/data-table.mjs.map +1 -0
- package/ui/dist/index.d.mts +2 -454
- package/ui/dist/index.d.ts +2 -454
- package/ui/data-table/components/BatchActionsBar.tsx +0 -53
- package/ui/data-table/components/ColumnVisibility.tsx +0 -111
- package/ui/data-table/components/DataTable.tsx +0 -498
- package/ui/data-table/components/DataTablePage.tsx +0 -244
- package/ui/data-table/components/MultiSelectFilter.tsx +0 -153
- package/ui/data-table/components/Pagination.tsx +0 -203
- package/ui/data-table/components/PaginationControls.tsx +0 -122
- package/ui/data-table/components/TableFilters.tsx +0 -145
- package/ui/data-table/components/index.ts +0 -44
- package/ui/data-table/components/types.ts +0 -181
- package/ui/data-table/hooks/index.ts +0 -17
- package/ui/data-table/hooks/useColumnOrder.ts +0 -237
- package/ui/data-table/hooks/useColumnVisibility.ts +0 -128
- package/ui/data-table/hooks/usePagination.ts +0 -160
- package/ui/data-table/hooks/useResizableColumns.ts +0 -282
- package/ui/data-table/index.ts +0 -87
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DataTablePage - Full-height data table layout with integrated header
|
|
3
|
-
*
|
|
4
|
-
* This component provides a desktop-app style layout where:
|
|
5
|
-
* - The header contains search, filters, action buttons, AND pagination controls
|
|
6
|
-
* - The data table fills the available vertical space between header and footer
|
|
7
|
-
* - Pagination controls appear inline in the header (right side)
|
|
8
|
-
*
|
|
9
|
-
* Usage:
|
|
10
|
-
* ```tsx
|
|
11
|
-
* <DataTablePage
|
|
12
|
-
* title="Issues"
|
|
13
|
-
* description="Review and manage detected code issues"
|
|
14
|
-
* search={searchTerm}
|
|
15
|
-
* onSearchChange={setSearchTerm}
|
|
16
|
-
* searchPlaceholder="Search issues..."
|
|
17
|
-
* filters={filterOptions}
|
|
18
|
-
* activeFilterCount={countActiveFilters}
|
|
19
|
-
* onClearFilters={clearFilters}
|
|
20
|
-
* pagination={pagination}
|
|
21
|
-
* actions={<>
|
|
22
|
-
* <Button>Refresh</Button>
|
|
23
|
-
* <Button>Export</Button>
|
|
24
|
-
* </>}
|
|
25
|
-
* >
|
|
26
|
-
* <DataTable ... hidePagination />
|
|
27
|
-
* </DataTablePage>
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
import React from 'react';
|
|
32
|
-
import { Search, Filter, X } from 'lucide-react';
|
|
33
|
-
import { Input } from '../../components/base/input';
|
|
34
|
-
import { Button } from '../../components/base/button';
|
|
35
|
-
import { Popover, PopoverContent, PopoverTrigger } from '../../components/base/popover';
|
|
36
|
-
import { cn } from '../../src/utils/cn';
|
|
37
|
-
import { PaginationControls, type PaginationControlsProps } from './PaginationControls';
|
|
38
|
-
|
|
39
|
-
export interface FilterOption {
|
|
40
|
-
id: string;
|
|
41
|
-
label: string;
|
|
42
|
-
render: () => React.ReactNode;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface DataTablePageProps {
|
|
46
|
-
/** Page title */
|
|
47
|
-
title: string;
|
|
48
|
-
/** Page description */
|
|
49
|
-
description?: string;
|
|
50
|
-
/** Search term */
|
|
51
|
-
search?: string;
|
|
52
|
-
/** Search change handler */
|
|
53
|
-
onSearchChange?: (value: string) => void;
|
|
54
|
-
/** Search placeholder text */
|
|
55
|
-
searchPlaceholder?: string;
|
|
56
|
-
/** Filter options for popover */
|
|
57
|
-
filters?: FilterOption[];
|
|
58
|
-
/** Number of active filters */
|
|
59
|
-
activeFilterCount?: number;
|
|
60
|
-
/** Clear all filters handler */
|
|
61
|
-
onClearFilters?: () => void;
|
|
62
|
-
/** Pagination props from usePagination hook */
|
|
63
|
-
pagination?: PaginationControlsProps;
|
|
64
|
-
/** Extra content to render next to the title (e.g. HelpTooltip) */
|
|
65
|
-
titleExtra?: React.ReactNode;
|
|
66
|
-
/** Action buttons to show in the header */
|
|
67
|
-
actions?: React.ReactNode;
|
|
68
|
-
/** Content before the table (e.g., BatchActionsBar) */
|
|
69
|
-
beforeTable?: React.ReactNode;
|
|
70
|
-
/** The DataTable component */
|
|
71
|
-
children: React.ReactNode;
|
|
72
|
-
/** Additional class for the container */
|
|
73
|
-
className?: string;
|
|
74
|
-
/** Whether to show a loading state */
|
|
75
|
-
loading?: boolean;
|
|
76
|
-
/** Loading component to show */
|
|
77
|
-
loadingComponent?: React.ReactNode;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function DataTablePage({
|
|
81
|
-
title,
|
|
82
|
-
description,
|
|
83
|
-
titleExtra,
|
|
84
|
-
search,
|
|
85
|
-
onSearchChange,
|
|
86
|
-
searchPlaceholder = 'Search...',
|
|
87
|
-
filters,
|
|
88
|
-
activeFilterCount = 0,
|
|
89
|
-
onClearFilters,
|
|
90
|
-
pagination,
|
|
91
|
-
actions,
|
|
92
|
-
beforeTable,
|
|
93
|
-
children,
|
|
94
|
-
className,
|
|
95
|
-
loading,
|
|
96
|
-
loadingComponent,
|
|
97
|
-
}: DataTablePageProps) {
|
|
98
|
-
// Always show pagination controls when pagination is provided (for row count selector)
|
|
99
|
-
const showPagination = pagination && pagination.totalItems > 0;
|
|
100
|
-
|
|
101
|
-
return (
|
|
102
|
-
<div className={cn('flex flex-col h-full', className)}>
|
|
103
|
-
{/* Page Header - has horizontal padding */}
|
|
104
|
-
<div className="data-table-page-header flex-shrink-0 space-y-4 pb-4">
|
|
105
|
-
{/* Title */}
|
|
106
|
-
<div>
|
|
107
|
-
<div className="group flex items-center gap-2">
|
|
108
|
-
<h1 className="text-3xl font-bold">{title}</h1>
|
|
109
|
-
{titleExtra}
|
|
110
|
-
</div>
|
|
111
|
-
{description && (
|
|
112
|
-
<p className="text-muted-foreground">{description}</p>
|
|
113
|
-
)}
|
|
114
|
-
</div>
|
|
115
|
-
|
|
116
|
-
{/* Controls Row: Search | Filters | Pagination | Spacer | Actions */}
|
|
117
|
-
<div className="flex items-center gap-3 flex-wrap">
|
|
118
|
-
{/* Search Input - responsive width */}
|
|
119
|
-
{onSearchChange !== undefined && (
|
|
120
|
-
<div className="relative w-full sm:w-auto sm:min-w-[200px] sm:max-w-xs">
|
|
121
|
-
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground pointer-events-none z-10" />
|
|
122
|
-
<Input
|
|
123
|
-
placeholder={searchPlaceholder}
|
|
124
|
-
value={search || ''}
|
|
125
|
-
onChange={(e) => onSearchChange(e.target.value)}
|
|
126
|
-
className="pl-9 h-9"
|
|
127
|
-
/>
|
|
128
|
-
{search && (
|
|
129
|
-
<button
|
|
130
|
-
type="button"
|
|
131
|
-
onClick={() => onSearchChange('')}
|
|
132
|
-
className="absolute right-2 top-1/2 transform -translate-y-1/2 p-1 rounded-sm hover:bg-muted"
|
|
133
|
-
>
|
|
134
|
-
<X className="h-3 w-3 text-muted-foreground" />
|
|
135
|
-
</button>
|
|
136
|
-
)}
|
|
137
|
-
</div>
|
|
138
|
-
)}
|
|
139
|
-
|
|
140
|
-
{/* Filters Popover */}
|
|
141
|
-
{filters && filters.length > 0 && (
|
|
142
|
-
<Popover>
|
|
143
|
-
<PopoverTrigger asChild>
|
|
144
|
-
<Button variant="outline" size="sm" className="gap-2 h-9">
|
|
145
|
-
<Filter className="h-4 w-4" />
|
|
146
|
-
<span className="hidden sm:inline">Filters</span>
|
|
147
|
-
{activeFilterCount > 0 && (
|
|
148
|
-
<span className="rounded-full bg-primary text-primary-foreground px-2 py-0.5 text-xs font-medium">
|
|
149
|
-
{activeFilterCount}
|
|
150
|
-
</span>
|
|
151
|
-
)}
|
|
152
|
-
</Button>
|
|
153
|
-
</PopoverTrigger>
|
|
154
|
-
<PopoverContent
|
|
155
|
-
className="w-80 overflow-y-auto"
|
|
156
|
-
align="start"
|
|
157
|
-
collisionPadding={16}
|
|
158
|
-
style={{ maxHeight: 'var(--radix-popover-content-available-height)' }}
|
|
159
|
-
>
|
|
160
|
-
<div className="space-y-4">
|
|
161
|
-
<div className="flex items-center justify-between">
|
|
162
|
-
<h4 className="font-medium text-sm">Filters</h4>
|
|
163
|
-
{activeFilterCount > 0 && onClearFilters && (
|
|
164
|
-
<Button
|
|
165
|
-
variant="ghost"
|
|
166
|
-
size="sm"
|
|
167
|
-
onClick={onClearFilters}
|
|
168
|
-
className="h-auto p-0 text-xs text-destructive hover:text-destructive"
|
|
169
|
-
>
|
|
170
|
-
Clear all
|
|
171
|
-
</Button>
|
|
172
|
-
)}
|
|
173
|
-
</div>
|
|
174
|
-
|
|
175
|
-
<div className="space-y-3">
|
|
176
|
-
{filters.map((filter) => (
|
|
177
|
-
<div key={filter.id} className="space-y-1.5">
|
|
178
|
-
<label className="text-xs font-medium text-muted-foreground">
|
|
179
|
-
{filter.label}
|
|
180
|
-
</label>
|
|
181
|
-
{filter.render()}
|
|
182
|
-
</div>
|
|
183
|
-
))}
|
|
184
|
-
</div>
|
|
185
|
-
</div>
|
|
186
|
-
</PopoverContent>
|
|
187
|
-
</Popover>
|
|
188
|
-
)}
|
|
189
|
-
|
|
190
|
-
{/* Clear filters button (visible when filters are active) */}
|
|
191
|
-
{activeFilterCount > 0 && onClearFilters && (
|
|
192
|
-
<Button
|
|
193
|
-
variant="ghost"
|
|
194
|
-
size="sm"
|
|
195
|
-
onClick={onClearFilters}
|
|
196
|
-
className="h-9 gap-1.5 text-muted-foreground hover:text-foreground"
|
|
197
|
-
title="Clear filters"
|
|
198
|
-
>
|
|
199
|
-
<X className="h-4 w-4" />
|
|
200
|
-
<span className="hidden sm:inline">Clear</span>
|
|
201
|
-
</Button>
|
|
202
|
-
)}
|
|
203
|
-
|
|
204
|
-
{/* Pagination Controls (after filters) */}
|
|
205
|
-
{showPagination && (
|
|
206
|
-
<PaginationControls {...pagination} />
|
|
207
|
-
)}
|
|
208
|
-
|
|
209
|
-
{/* Spacer */}
|
|
210
|
-
<div className="flex-1" />
|
|
211
|
-
|
|
212
|
-
{/* Action buttons (right side) - never wrap */}
|
|
213
|
-
{actions && (
|
|
214
|
-
<div className="flex items-center gap-2 flex-shrink-0">
|
|
215
|
-
{actions}
|
|
216
|
-
</div>
|
|
217
|
-
)}
|
|
218
|
-
</div>
|
|
219
|
-
</div>
|
|
220
|
-
|
|
221
|
-
{/* Before Table Content (e.g., BatchActionsBar) - with padding */}
|
|
222
|
-
{beforeTable && (
|
|
223
|
-
<div className="px-6 pb-2">
|
|
224
|
-
{beforeTable}
|
|
225
|
-
</div>
|
|
226
|
-
)}
|
|
227
|
-
|
|
228
|
-
{/* Table Container - edge to edge, scrolls both directions */}
|
|
229
|
-
<div className="relative flex-1 min-h-0">
|
|
230
|
-
<div className="data-table-scroll-container h-full">
|
|
231
|
-
{loading ? (
|
|
232
|
-
loadingComponent || (
|
|
233
|
-
<div className="flex items-center justify-center h-full">
|
|
234
|
-
<div className="text-muted-foreground">Loading...</div>
|
|
235
|
-
</div>
|
|
236
|
-
)
|
|
237
|
-
) : (
|
|
238
|
-
children
|
|
239
|
-
)}
|
|
240
|
-
</div>
|
|
241
|
-
</div>
|
|
242
|
-
</div>
|
|
243
|
-
);
|
|
244
|
-
}
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Checkbox } from '../../components/base/checkbox';
|
|
3
|
-
import { Button } from '../../components/base/button';
|
|
4
|
-
import { cn } from '../../src/utils/cn';
|
|
5
|
-
|
|
6
|
-
export interface MultiSelectOption<T extends string = string> {
|
|
7
|
-
/** Unique value for this option */
|
|
8
|
-
value: T;
|
|
9
|
-
/** Display label */
|
|
10
|
-
label: string;
|
|
11
|
-
/** Optional custom render for the label (e.g., with icon/flag) */
|
|
12
|
-
render?: () => React.ReactNode;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface MultiSelectFilterProps<T extends string = string> {
|
|
16
|
-
/** Available options to select from */
|
|
17
|
-
options: MultiSelectOption<T>[];
|
|
18
|
-
/** Currently selected values */
|
|
19
|
-
selected: Set<T>;
|
|
20
|
-
/** Called when selection changes */
|
|
21
|
-
onChange: (selected: Set<T>) => void;
|
|
22
|
-
/** Maximum height before scrolling (default: 200px) */
|
|
23
|
-
maxHeight?: number;
|
|
24
|
-
/** Number of columns for grid layout (default: 2) */
|
|
25
|
-
columns?: 1 | 2 | 3;
|
|
26
|
-
/** Show select all / clear buttons */
|
|
27
|
-
showBulkActions?: boolean;
|
|
28
|
-
/** Optional className for the container */
|
|
29
|
-
className?: string;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* MultiSelectFilter - A checkbox-based multi-select filter component
|
|
34
|
-
*
|
|
35
|
-
* Designed to work with the TableFilters popover for filtering data tables.
|
|
36
|
-
* Supports custom rendering per option (for flags, badges, icons, etc.)
|
|
37
|
-
*/
|
|
38
|
-
export function MultiSelectFilter<T extends string = string>({
|
|
39
|
-
options,
|
|
40
|
-
selected,
|
|
41
|
-
onChange,
|
|
42
|
-
maxHeight = 200,
|
|
43
|
-
columns = 2,
|
|
44
|
-
showBulkActions = true,
|
|
45
|
-
className,
|
|
46
|
-
}: MultiSelectFilterProps<T>) {
|
|
47
|
-
const handleToggle = (value: T) => {
|
|
48
|
-
const newSelected = new Set(selected);
|
|
49
|
-
if (newSelected.has(value)) {
|
|
50
|
-
newSelected.delete(value);
|
|
51
|
-
} else {
|
|
52
|
-
newSelected.add(value);
|
|
53
|
-
}
|
|
54
|
-
onChange(newSelected);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const handleSelectAll = () => {
|
|
58
|
-
onChange(new Set(options.map(o => o.value)));
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const handleClear = () => {
|
|
62
|
-
onChange(new Set());
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const gridCols = {
|
|
66
|
-
1: 'grid-cols-1',
|
|
67
|
-
2: 'grid-cols-2',
|
|
68
|
-
3: 'grid-cols-3',
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const allSelected = options.length > 0 && selected.size === options.length;
|
|
72
|
-
const noneSelected = selected.size === 0;
|
|
73
|
-
|
|
74
|
-
return (
|
|
75
|
-
<div className={cn('space-y-2', className)}>
|
|
76
|
-
{/* Bulk action buttons */}
|
|
77
|
-
{showBulkActions && options.length > 3 && (
|
|
78
|
-
<div className="flex items-center gap-2 text-xs">
|
|
79
|
-
<Button
|
|
80
|
-
type="button"
|
|
81
|
-
variant="ghost"
|
|
82
|
-
size="sm"
|
|
83
|
-
onClick={handleSelectAll}
|
|
84
|
-
disabled={allSelected}
|
|
85
|
-
className="h-6 px-2 text-xs text-muted-foreground hover:text-foreground"
|
|
86
|
-
>
|
|
87
|
-
Select all
|
|
88
|
-
</Button>
|
|
89
|
-
<span className="text-muted-foreground">·</span>
|
|
90
|
-
<Button
|
|
91
|
-
type="button"
|
|
92
|
-
variant="ghost"
|
|
93
|
-
size="sm"
|
|
94
|
-
onClick={handleClear}
|
|
95
|
-
disabled={noneSelected}
|
|
96
|
-
className="h-6 px-2 text-xs text-muted-foreground hover:text-foreground"
|
|
97
|
-
>
|
|
98
|
-
Clear
|
|
99
|
-
</Button>
|
|
100
|
-
{selected.size > 0 && (
|
|
101
|
-
<>
|
|
102
|
-
<span className="text-muted-foreground">·</span>
|
|
103
|
-
<span className="text-muted-foreground">
|
|
104
|
-
{selected.size} selected
|
|
105
|
-
</span>
|
|
106
|
-
</>
|
|
107
|
-
)}
|
|
108
|
-
</div>
|
|
109
|
-
)}
|
|
110
|
-
|
|
111
|
-
{/* Options grid */}
|
|
112
|
-
<div
|
|
113
|
-
className={cn('overflow-y-auto', options.length > 6 && 'pr-1')}
|
|
114
|
-
style={{ maxHeight: `${maxHeight}px` }}
|
|
115
|
-
>
|
|
116
|
-
<div className={cn('grid gap-1', gridCols[columns])}>
|
|
117
|
-
{options.map((option) => (
|
|
118
|
-
<label
|
|
119
|
-
key={option.value}
|
|
120
|
-
className={cn(
|
|
121
|
-
'flex items-center gap-2 px-2 py-1.5 rounded-md cursor-pointer',
|
|
122
|
-
'hover:bg-muted/50 transition-colors',
|
|
123
|
-
selected.has(option.value) && 'bg-muted/30'
|
|
124
|
-
)}
|
|
125
|
-
>
|
|
126
|
-
<Checkbox
|
|
127
|
-
checked={selected.has(option.value)}
|
|
128
|
-
onCheckedChange={() => handleToggle(option.value)}
|
|
129
|
-
className="h-3.5 w-3.5"
|
|
130
|
-
/>
|
|
131
|
-
{option.render ? (
|
|
132
|
-
<span className="flex items-center gap-1.5 text-sm truncate">
|
|
133
|
-
{option.render()}
|
|
134
|
-
</span>
|
|
135
|
-
) : (
|
|
136
|
-
<span className="text-sm truncate">{option.label}</span>
|
|
137
|
-
)}
|
|
138
|
-
</label>
|
|
139
|
-
))}
|
|
140
|
-
</div>
|
|
141
|
-
</div>
|
|
142
|
-
|
|
143
|
-
{/* Empty state */}
|
|
144
|
-
{options.length === 0 && (
|
|
145
|
-
<div className="text-sm text-muted-foreground text-center py-2">
|
|
146
|
-
No options available
|
|
147
|
-
</div>
|
|
148
|
-
)}
|
|
149
|
-
</div>
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export default MultiSelectFilter;
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ChevronLeft,
|
|
3
|
-
ChevronRight,
|
|
4
|
-
ChevronsLeft,
|
|
5
|
-
ChevronsRight,
|
|
6
|
-
} from 'lucide-react';
|
|
7
|
-
import { Button } from '../../components/base/button';
|
|
8
|
-
import {
|
|
9
|
-
Select,
|
|
10
|
-
SelectContent,
|
|
11
|
-
SelectItem,
|
|
12
|
-
SelectTrigger,
|
|
13
|
-
SelectValue,
|
|
14
|
-
} from '../../components/base/select';
|
|
15
|
-
import { cn } from '../../src/utils/cn';
|
|
16
|
-
|
|
17
|
-
interface PaginationProps {
|
|
18
|
-
page: number;
|
|
19
|
-
pageSize: number;
|
|
20
|
-
totalPages: number;
|
|
21
|
-
totalItems: number;
|
|
22
|
-
startIndex: number;
|
|
23
|
-
endIndex: number;
|
|
24
|
-
canGoNext: boolean;
|
|
25
|
-
canGoPrev: boolean;
|
|
26
|
-
pageSizeOptions: number[];
|
|
27
|
-
onPageChange: (page: number) => void;
|
|
28
|
-
onPageSizeChange: (size: number) => void;
|
|
29
|
-
onNextPage: () => void;
|
|
30
|
-
onPrevPage: () => void;
|
|
31
|
-
onFirstPage: () => void;
|
|
32
|
-
onLastPage: () => void;
|
|
33
|
-
className?: string;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function Pagination({
|
|
37
|
-
page,
|
|
38
|
-
pageSize,
|
|
39
|
-
totalPages,
|
|
40
|
-
totalItems,
|
|
41
|
-
startIndex,
|
|
42
|
-
endIndex,
|
|
43
|
-
canGoNext,
|
|
44
|
-
canGoPrev,
|
|
45
|
-
pageSizeOptions,
|
|
46
|
-
onPageChange,
|
|
47
|
-
onPageSizeChange,
|
|
48
|
-
onNextPage,
|
|
49
|
-
onPrevPage,
|
|
50
|
-
onFirstPage,
|
|
51
|
-
onLastPage,
|
|
52
|
-
className,
|
|
53
|
-
}: PaginationProps) {
|
|
54
|
-
// Generate page numbers to show
|
|
55
|
-
const getPageNumbers = () => {
|
|
56
|
-
const pages: (number | 'ellipsis')[] = [];
|
|
57
|
-
const showPages = 5; // Max pages to show
|
|
58
|
-
const halfShow = Math.floor(showPages / 2);
|
|
59
|
-
|
|
60
|
-
let startPage = Math.max(1, page - halfShow);
|
|
61
|
-
let endPage = Math.min(totalPages, page + halfShow);
|
|
62
|
-
|
|
63
|
-
// Adjust range if near edges
|
|
64
|
-
if (page <= halfShow) {
|
|
65
|
-
endPage = Math.min(totalPages, showPages);
|
|
66
|
-
}
|
|
67
|
-
if (page > totalPages - halfShow) {
|
|
68
|
-
startPage = Math.max(1, totalPages - showPages + 1);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Add first page and ellipsis if needed
|
|
72
|
-
if (startPage > 1) {
|
|
73
|
-
pages.push(1);
|
|
74
|
-
if (startPage > 2) {
|
|
75
|
-
pages.push('ellipsis');
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Add middle pages
|
|
80
|
-
for (let i = startPage; i <= endPage; i++) {
|
|
81
|
-
if (i !== 1 && i !== totalPages) {
|
|
82
|
-
pages.push(i);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Add ellipsis and last page if needed
|
|
87
|
-
if (endPage < totalPages) {
|
|
88
|
-
if (endPage < totalPages - 1) {
|
|
89
|
-
pages.push('ellipsis');
|
|
90
|
-
}
|
|
91
|
-
pages.push(totalPages);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return pages;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
if (totalItems === 0) {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return (
|
|
102
|
-
<div
|
|
103
|
-
className={cn(
|
|
104
|
-
'flex flex-col sm:flex-row items-center justify-between gap-4 px-2 py-3',
|
|
105
|
-
className
|
|
106
|
-
)}
|
|
107
|
-
>
|
|
108
|
-
{/* Items info */}
|
|
109
|
-
<div className="text-sm text-muted-foreground">
|
|
110
|
-
Showing {startIndex} to {endIndex} of {totalItems} items
|
|
111
|
-
</div>
|
|
112
|
-
|
|
113
|
-
{/* Controls */}
|
|
114
|
-
<div className="flex items-center gap-4">
|
|
115
|
-
{/* Page size selector */}
|
|
116
|
-
<div className="flex items-center gap-2">
|
|
117
|
-
<span className="text-sm text-muted-foreground">Per page:</span>
|
|
118
|
-
<Select
|
|
119
|
-
value={String(pageSize)}
|
|
120
|
-
onValueChange={(v) => onPageSizeChange(Number(v))}
|
|
121
|
-
>
|
|
122
|
-
<SelectTrigger className="w-20 h-8">
|
|
123
|
-
<SelectValue />
|
|
124
|
-
</SelectTrigger>
|
|
125
|
-
<SelectContent>
|
|
126
|
-
{pageSizeOptions.map((size) => (
|
|
127
|
-
<SelectItem key={size} value={String(size)}>
|
|
128
|
-
{size}
|
|
129
|
-
</SelectItem>
|
|
130
|
-
))}
|
|
131
|
-
</SelectContent>
|
|
132
|
-
</Select>
|
|
133
|
-
</div>
|
|
134
|
-
|
|
135
|
-
{/* Page navigation */}
|
|
136
|
-
<div className="flex items-center gap-1">
|
|
137
|
-
<Button
|
|
138
|
-
variant="outline"
|
|
139
|
-
size="icon"
|
|
140
|
-
className="h-8 w-8"
|
|
141
|
-
onClick={onFirstPage}
|
|
142
|
-
disabled={!canGoPrev}
|
|
143
|
-
title="First page"
|
|
144
|
-
>
|
|
145
|
-
<ChevronsLeft className="h-4 w-4" />
|
|
146
|
-
</Button>
|
|
147
|
-
<Button
|
|
148
|
-
variant="outline"
|
|
149
|
-
size="icon"
|
|
150
|
-
className="h-8 w-8"
|
|
151
|
-
onClick={onPrevPage}
|
|
152
|
-
disabled={!canGoPrev}
|
|
153
|
-
title="Previous page"
|
|
154
|
-
>
|
|
155
|
-
<ChevronLeft className="h-4 w-4" />
|
|
156
|
-
</Button>
|
|
157
|
-
|
|
158
|
-
{/* Page numbers */}
|
|
159
|
-
<div className="flex items-center gap-1">
|
|
160
|
-
{getPageNumbers().map((pageNum, idx) =>
|
|
161
|
-
pageNum === 'ellipsis' ? (
|
|
162
|
-
<span key={`ellipsis-${idx}`} className="px-2 text-muted-foreground">
|
|
163
|
-
...
|
|
164
|
-
</span>
|
|
165
|
-
) : (
|
|
166
|
-
<Button
|
|
167
|
-
key={pageNum}
|
|
168
|
-
variant={page === pageNum ? 'default' : 'outline'}
|
|
169
|
-
size="icon"
|
|
170
|
-
className="h-8 w-8"
|
|
171
|
-
onClick={() => onPageChange(pageNum)}
|
|
172
|
-
>
|
|
173
|
-
{pageNum}
|
|
174
|
-
</Button>
|
|
175
|
-
)
|
|
176
|
-
)}
|
|
177
|
-
</div>
|
|
178
|
-
|
|
179
|
-
<Button
|
|
180
|
-
variant="outline"
|
|
181
|
-
size="icon"
|
|
182
|
-
className="h-8 w-8"
|
|
183
|
-
onClick={onNextPage}
|
|
184
|
-
disabled={!canGoNext}
|
|
185
|
-
title="Next page"
|
|
186
|
-
>
|
|
187
|
-
<ChevronRight className="h-4 w-4" />
|
|
188
|
-
</Button>
|
|
189
|
-
<Button
|
|
190
|
-
variant="outline"
|
|
191
|
-
size="icon"
|
|
192
|
-
className="h-8 w-8"
|
|
193
|
-
onClick={onLastPage}
|
|
194
|
-
disabled={!canGoNext}
|
|
195
|
-
title="Last page"
|
|
196
|
-
>
|
|
197
|
-
<ChevronsRight className="h-4 w-4" />
|
|
198
|
-
</Button>
|
|
199
|
-
</div>
|
|
200
|
-
</div>
|
|
201
|
-
</div>
|
|
202
|
-
);
|
|
203
|
-
}
|