notionsoft-ui 1.0.38 → 1.0.39
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
CHANGED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Pagination.stories.tsx
|
|
2
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
3
|
+
import Pagination from "./pagination";
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof Pagination> = {
|
|
6
|
+
title: "Components/Pagination",
|
|
7
|
+
component: Pagination,
|
|
8
|
+
parameters: {
|
|
9
|
+
layout: "centered",
|
|
10
|
+
},
|
|
11
|
+
argTypes: {
|
|
12
|
+
lastPage: {
|
|
13
|
+
control: { type: "number", min: 1 },
|
|
14
|
+
},
|
|
15
|
+
onPageChange: {
|
|
16
|
+
action: "page changed",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default meta;
|
|
22
|
+
|
|
23
|
+
type Story = StoryObj<typeof Pagination>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Default pagination
|
|
27
|
+
*/
|
|
28
|
+
export const Default: Story = {
|
|
29
|
+
args: {
|
|
30
|
+
lastPage: 10,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Small number of pages (no ellipsis)
|
|
36
|
+
*/
|
|
37
|
+
export const SmallDataset: Story = {
|
|
38
|
+
args: {
|
|
39
|
+
lastPage: 5,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Large dataset with ellipsis behavior
|
|
45
|
+
*/
|
|
46
|
+
export const LargeDataset: Story = {
|
|
47
|
+
args: {
|
|
48
|
+
lastPage: 50,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Single page (navigation disabled)
|
|
54
|
+
*/
|
|
55
|
+
export const SinglePage: Story = {
|
|
56
|
+
args: {
|
|
57
|
+
lastPage: 1,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { ChevronLeft, ChevronRight } from "lucide-react";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
|
|
4
|
+
interface PaginationProps {
|
|
5
|
+
lastPage: number;
|
|
6
|
+
onPageChange: (page: number) => void;
|
|
7
|
+
}
|
|
8
|
+
const Pagination: React.FC<PaginationProps> = ({ lastPage, onPageChange }) => {
|
|
9
|
+
const [currentPage, setCurrentPage] = useState<number>(1);
|
|
10
|
+
const handlePrevPage = () => {
|
|
11
|
+
if (currentPage > 1) {
|
|
12
|
+
setCurrentPage(currentPage - 1);
|
|
13
|
+
onPageChange(currentPage - 1);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const handleNextPage = () => {
|
|
18
|
+
if (currentPage < lastPage) {
|
|
19
|
+
setCurrentPage(currentPage + 1);
|
|
20
|
+
onPageChange(currentPage + 1);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const handlePageClick = (page: number) => {
|
|
25
|
+
setCurrentPage(page);
|
|
26
|
+
onPageChange(page);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// Function to generate pagination numbers with ellipsis for large datasets
|
|
30
|
+
const generatePageNumbers = () => {
|
|
31
|
+
const pages: (number | string)[] = [];
|
|
32
|
+
const siblingCount = 1; // Number of pages to show around current page
|
|
33
|
+
|
|
34
|
+
if (lastPage <= 7) {
|
|
35
|
+
// If less than 7 pages, show all pages
|
|
36
|
+
for (let i = 1; i <= lastPage; i++) {
|
|
37
|
+
pages.push(i);
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
// Always show first, last, and nearby pages
|
|
41
|
+
pages.push(1);
|
|
42
|
+
if (currentPage > siblingCount + 2) pages.push("...");
|
|
43
|
+
for (
|
|
44
|
+
let i = Math.max(2, currentPage - siblingCount);
|
|
45
|
+
i <= Math.min(lastPage - 1, currentPage + siblingCount);
|
|
46
|
+
i++
|
|
47
|
+
) {
|
|
48
|
+
pages.push(i);
|
|
49
|
+
}
|
|
50
|
+
if (currentPage < lastPage - siblingCount - 1) pages.push("...");
|
|
51
|
+
pages.push(lastPage);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return pages;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const pageNumbers = generatePageNumbers();
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<div className="flex justify-center items-center select-none h-7 text-sm gap-x-1 text-primary-foreground">
|
|
61
|
+
{/* Previous Button */}
|
|
62
|
+
<ChevronLeft
|
|
63
|
+
onClick={() => {
|
|
64
|
+
if (currentPage !== 1) handlePrevPage();
|
|
65
|
+
}}
|
|
66
|
+
className={`size-8 rounded transition-[color,background-color,transform] cursor-pointer rtl:rotate-180 self-center p-2 ${
|
|
67
|
+
currentPage === 1
|
|
68
|
+
? "text-primary/50"
|
|
69
|
+
: "text-primary hover:scale-110 hover:bg-fourth/10"
|
|
70
|
+
}`}
|
|
71
|
+
/>
|
|
72
|
+
{/* Page Numbers */}
|
|
73
|
+
{pageNumbers.map((page, index) =>
|
|
74
|
+
typeof page === "number" ? (
|
|
75
|
+
<button
|
|
76
|
+
key={index}
|
|
77
|
+
onClick={() => handlePageClick(page)}
|
|
78
|
+
className={`size-8 cursor-pointer rounded transition-colors ${
|
|
79
|
+
currentPage === page
|
|
80
|
+
? "bg-fourth text-primary-foreground text-sm"
|
|
81
|
+
: "text-secondary-foreground hover:bg-fourth/10 transition-transform hover:scale-105 text-xs font-semibold"
|
|
82
|
+
}`}
|
|
83
|
+
>
|
|
84
|
+
{page}
|
|
85
|
+
</button>
|
|
86
|
+
) : (
|
|
87
|
+
<span key={index} className="px-4 py-2 text-primary">
|
|
88
|
+
...
|
|
89
|
+
</span>
|
|
90
|
+
)
|
|
91
|
+
)}
|
|
92
|
+
|
|
93
|
+
{/* Next Button */}
|
|
94
|
+
|
|
95
|
+
<ChevronRight
|
|
96
|
+
onClick={() => {
|
|
97
|
+
if (currentPage !== lastPage) handleNextPage();
|
|
98
|
+
}}
|
|
99
|
+
className={`size-8 rounded transition-[color,background-color,transform] cursor-pointer rtl:rotate-180 self-center p-2 ${
|
|
100
|
+
currentPage !== lastPage
|
|
101
|
+
? "text-primary hover:scale-110 hover:bg-fourth/10"
|
|
102
|
+
: "text-primary/50"
|
|
103
|
+
}`}
|
|
104
|
+
/>
|
|
105
|
+
</div>
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export default Pagination;
|