@mijn-ui/react-pagination 0.0.3 → 0.0.5

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.
@@ -0,0 +1,36 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as React from 'react';
3
+ import { UnstyledProps } from '@mijn-ui/react-utilities/shared';
4
+
5
+ type PaginationContextType = {
6
+ paginationRange: number[];
7
+ currentPage: number;
8
+ prevEllipsisActive: boolean;
9
+ nextEllipsisActive: boolean;
10
+ setPage: (page: number) => void;
11
+ goToPreviousPage: () => void;
12
+ goToNextPage: () => void;
13
+ };
14
+ type PaginationProps = {
15
+ totalPages: number;
16
+ itemsPerPage: number;
17
+ children: React.ReactNode;
18
+ currentPage?: number;
19
+ onChangePage?: (page: number) => void;
20
+ } & UnstyledProps;
21
+ declare const Pagination: React.FC<PaginationProps>;
22
+ declare const usePagination: () => PaginationContextType;
23
+ type PaginationContentProps = React.ComponentPropsWithRef<"nav"> & UnstyledProps;
24
+ declare const PaginationContent: ({ className, unstyled, ...props }: PaginationContentProps) => react_jsx_runtime.JSX.Element;
25
+ type PaginationListProps = React.ComponentProps<"ul"> & UnstyledProps;
26
+ declare const PaginationList: ({ className, unstyled, ...props }: PaginationListProps) => react_jsx_runtime.JSX.Element;
27
+ type PaginationPreviousButtonProps = React.ComponentProps<"button"> & UnstyledProps;
28
+ declare const PaginationPreviousButton: ({ className, unstyled, ...props }: PaginationPreviousButtonProps) => react_jsx_runtime.JSX.Element;
29
+ type PaginationNextButtonProps = React.ComponentProps<"button"> & UnstyledProps;
30
+ declare const PaginationNextButton: ({ className, unstyled, ...props }: PaginationNextButtonProps) => react_jsx_runtime.JSX.Element;
31
+ type PaginationPreviousEllipsisProps = React.ComponentProps<"span"> & UnstyledProps;
32
+ declare const PaginationPreviousEllipsis: ({ className, unstyled, ...props }: PaginationPreviousEllipsisProps) => react_jsx_runtime.JSX.Element | undefined;
33
+ type PaginationNextEllipsisProps = React.ComponentProps<"span"> & UnstyledProps;
34
+ declare const PaginationNextEllipsis: ({ className, unstyled, ...props }: PaginationNextEllipsisProps) => react_jsx_runtime.JSX.Element | undefined;
35
+
36
+ export { Pagination, PaginationContent, PaginationList, PaginationNextButton, PaginationNextEllipsis, PaginationPreviousButton, PaginationPreviousEllipsis, usePagination };
package/dist/index.js ADDED
@@ -0,0 +1,266 @@
1
+ "use client"
2
+
3
+ // src/pagination.tsx
4
+ import * as React from "react";
5
+ import { buttonStyles } from "@mijn-ui/react-button";
6
+ import { UnstyledProvider, useUnstyled } from "@mijn-ui/react-utilities/context";
7
+ import { applyUnstyled } from "@mijn-ui/react-utilities/shared";
8
+ import { LuMoreHorizontal } from "react-icons/lu";
9
+ import { jsx } from "react/jsx-runtime";
10
+ var usePaginationRange = ({
11
+ totalPages,
12
+ itemsPerPage,
13
+ currentPage
14
+ }) => {
15
+ const totalPageCount = Math.ceil(totalPages / itemsPerPage);
16
+ const visiblePages = 3;
17
+ if (totalPageCount <= visiblePages) {
18
+ return {
19
+ range: Array.from({ length: totalPageCount }, (_, i) => i + 1),
20
+ prevEllipsisActive: false,
21
+ nextEllipsisActive: false
22
+ };
23
+ }
24
+ if (currentPage <= 2) {
25
+ return {
26
+ range: [1, 2, 3],
27
+ prevEllipsisActive: false,
28
+ nextEllipsisActive: totalPageCount > 3
29
+ };
30
+ }
31
+ if (currentPage >= totalPageCount - 1) {
32
+ return {
33
+ range: [totalPageCount - 2, totalPageCount - 1, totalPageCount],
34
+ prevEllipsisActive: totalPageCount > 3,
35
+ nextEllipsisActive: false
36
+ };
37
+ }
38
+ const leftBound = currentPage - 1;
39
+ const rightBound = currentPage + 1;
40
+ const range = Array.from(
41
+ { length: rightBound - leftBound + 1 },
42
+ (_, i) => i + leftBound
43
+ );
44
+ return {
45
+ range,
46
+ prevEllipsisActive: leftBound > 1,
47
+ nextEllipsisActive: rightBound < totalPageCount
48
+ };
49
+ };
50
+ var PaginationContext = React.createContext(void 0);
51
+ var Pagination = ({
52
+ unstyled = false,
53
+ totalPages,
54
+ itemsPerPage,
55
+ children,
56
+ currentPage: propsCurrentPage,
57
+ onChangePage
58
+ }) => {
59
+ const [internalCurrentPage, setInternalCurrentPage] = React.useState(1);
60
+ const isControlled = propsCurrentPage !== void 0;
61
+ const currentPage = isControlled ? propsCurrentPage : internalCurrentPage;
62
+ const paginationRange = usePaginationRange({
63
+ currentPage,
64
+ itemsPerPage,
65
+ totalPages
66
+ });
67
+ const setPage = (page) => {
68
+ if (isControlled && onChangePage) {
69
+ onChangePage(page);
70
+ } else {
71
+ setInternalCurrentPage(page);
72
+ }
73
+ };
74
+ const goToPreviousPage = () => setPage(Math.max(currentPage - 1, 1));
75
+ const goToNextPage = () => setPage(Math.min(currentPage + 1, Math.ceil(totalPages / itemsPerPage)));
76
+ React.useEffect(() => {
77
+ if (!isControlled && propsCurrentPage !== void 0) {
78
+ setInternalCurrentPage(propsCurrentPage);
79
+ }
80
+ }, [propsCurrentPage, isControlled]);
81
+ return /* @__PURE__ */ jsx(
82
+ PaginationContext.Provider,
83
+ {
84
+ value: {
85
+ paginationRange: paginationRange.range,
86
+ currentPage,
87
+ prevEllipsisActive: paginationRange.prevEllipsisActive,
88
+ nextEllipsisActive: paginationRange.nextEllipsisActive,
89
+ setPage,
90
+ goToPreviousPage,
91
+ goToNextPage
92
+ },
93
+ children: /* @__PURE__ */ jsx(UnstyledProvider, { unstyled, children })
94
+ }
95
+ );
96
+ };
97
+ var usePagination = () => {
98
+ const context = React.useContext(PaginationContext);
99
+ if (context === void 0) {
100
+ throw new Error(
101
+ "usePaginationContext must be used within a PaginationProvider"
102
+ );
103
+ }
104
+ return context;
105
+ };
106
+ var PaginationContent = ({
107
+ className,
108
+ unstyled,
109
+ ...props
110
+ }) => {
111
+ const { unstyled: contextUnstyled } = useUnstyled();
112
+ const isUnstyled = unstyled ?? contextUnstyled;
113
+ return /* @__PURE__ */ jsx(
114
+ "nav",
115
+ {
116
+ className: applyUnstyled(
117
+ isUnstyled,
118
+ "flex items-center gap-2",
119
+ className
120
+ ),
121
+ ...props
122
+ }
123
+ );
124
+ };
125
+ var PaginationList = ({
126
+ className,
127
+ unstyled,
128
+ ...props
129
+ }) => {
130
+ const { currentPage, setPage, paginationRange } = usePagination();
131
+ const { unstyled: contextUnstyled } = useUnstyled();
132
+ const isUnstyled = unstyled ?? contextUnstyled;
133
+ return /* @__PURE__ */ jsx(
134
+ "ul",
135
+ {
136
+ className: applyUnstyled(
137
+ isUnstyled,
138
+ "flex flex-row items-center gap-1",
139
+ className
140
+ ),
141
+ ...props,
142
+ children: paginationRange.map((page, index) => /* @__PURE__ */ jsx("li", { onClick: () => setPage(page), children: /* @__PURE__ */ jsx(
143
+ "button",
144
+ {
145
+ className: applyUnstyled(
146
+ isUnstyled,
147
+ buttonStyles({
148
+ variant: page === currentPage ? "outline" : "text",
149
+ color: "accent",
150
+ size: "icon"
151
+ })
152
+ ),
153
+ children: page
154
+ }
155
+ ) }, index))
156
+ }
157
+ );
158
+ };
159
+ var PaginationPreviousButton = ({
160
+ className,
161
+ unstyled,
162
+ ...props
163
+ }) => {
164
+ const { goToPreviousPage } = usePagination();
165
+ const { unstyled: contextUnstyled } = useUnstyled();
166
+ const isUnstyled = unstyled ?? contextUnstyled;
167
+ return /* @__PURE__ */ jsx(
168
+ "button",
169
+ {
170
+ onClick: goToPreviousPage,
171
+ className: applyUnstyled(
172
+ isUnstyled,
173
+ buttonStyles({
174
+ variant: "text",
175
+ color: "accent",
176
+ size: "md",
177
+ className: "gap-1 font-medium"
178
+ }),
179
+ className
180
+ ),
181
+ ...props
182
+ }
183
+ );
184
+ };
185
+ var PaginationNextButton = ({
186
+ className,
187
+ unstyled,
188
+ ...props
189
+ }) => {
190
+ const { goToNextPage } = usePagination();
191
+ const { unstyled: contextUnstyled } = useUnstyled();
192
+ const isUnstyled = unstyled ?? contextUnstyled;
193
+ return /* @__PURE__ */ jsx(
194
+ "button",
195
+ {
196
+ onClick: goToNextPage,
197
+ className: applyUnstyled(
198
+ isUnstyled,
199
+ buttonStyles({
200
+ variant: "text",
201
+ color: "accent",
202
+ size: "md",
203
+ className: "gap-1 pl-2.5 font-medium"
204
+ }),
205
+ className
206
+ ),
207
+ ...props
208
+ }
209
+ );
210
+ };
211
+ var PaginationPreviousEllipsis = ({
212
+ className,
213
+ unstyled,
214
+ ...props
215
+ }) => {
216
+ const { prevEllipsisActive } = usePagination();
217
+ const { unstyled: contextUnstyled } = useUnstyled();
218
+ const isUnstyled = unstyled ?? contextUnstyled;
219
+ if (!prevEllipsisActive) return;
220
+ return /* @__PURE__ */ jsx(
221
+ "span",
222
+ {
223
+ "aria-hidden": true,
224
+ className: applyUnstyled(
225
+ isUnstyled,
226
+ "flex h-9 w-9 items-center justify-center",
227
+ className
228
+ ),
229
+ ...props,
230
+ children: /* @__PURE__ */ jsx(LuMoreHorizontal, { className: "size-4" })
231
+ }
232
+ );
233
+ };
234
+ var PaginationNextEllipsis = ({
235
+ className,
236
+ unstyled,
237
+ ...props
238
+ }) => {
239
+ const { nextEllipsisActive } = usePagination();
240
+ const { unstyled: contextUnstyled } = useUnstyled();
241
+ const isUnstyled = unstyled ?? contextUnstyled;
242
+ if (!nextEllipsisActive) return;
243
+ return /* @__PURE__ */ jsx(
244
+ "span",
245
+ {
246
+ "aria-hidden": true,
247
+ className: applyUnstyled(
248
+ isUnstyled,
249
+ "flex h-9 w-9 items-center justify-center",
250
+ className
251
+ ),
252
+ ...props,
253
+ children: /* @__PURE__ */ jsx(LuMoreHorizontal, { className: "size-4" })
254
+ }
255
+ );
256
+ };
257
+ export {
258
+ Pagination,
259
+ PaginationContent,
260
+ PaginationList,
261
+ PaginationNextButton,
262
+ PaginationNextEllipsis,
263
+ PaginationPreviousButton,
264
+ PaginationPreviousEllipsis,
265
+ usePagination
266
+ };
@@ -0,0 +1 @@
1
+ {"inputs":{"src/pagination.tsx":{"bytes":9915,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@mijn-ui/react-button","kind":"import-statement","external":true},{"path":"@mijn-ui/react-utilities/context","kind":"import-statement","external":true},{"path":"@mijn-ui/react-utilities/shared","kind":"import-statement","external":true},{"path":"react-icons/lu","kind":"import-statement","external":true},{"path":"react/jsx-runtime","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":29,"imports":[{"path":"src/pagination.tsx","kind":"import-statement","original":"./pagination"}],"format":"esm"}},"outputs":{"dist/index.js":{"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@mijn-ui/react-button","kind":"import-statement","external":true},{"path":"@mijn-ui/react-utilities/context","kind":"import-statement","external":true},{"path":"@mijn-ui/react-utilities/shared","kind":"import-statement","external":true},{"path":"react-icons/lu","kind":"import-statement","external":true},{"path":"react/jsx-runtime","kind":"import-statement","external":true}],"exports":["Pagination","PaginationContent","PaginationList","PaginationNextButton","PaginationNextEllipsis","PaginationPreviousButton","PaginationPreviousEllipsis","usePagination"],"entryPoint":"src/index.ts","inputs":{"src/pagination.tsx":{"bytesInOutput":6625},"src/index.ts":{"bytesInOutput":0}},"bytes":6836}}}
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@mijn-ui/react-pagination",
3
3
  "author": "Htet Aung Lin<htetaunglin.coder@gmail.com>",
4
- "version": "0.0.3",
4
+ "version": "0.0.5",
5
5
  "homepage": "https://mijn-ui.vercel.app",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "sideEffects": false,
9
9
  "files": [
10
- "dist/*"
10
+ "dist"
11
11
  ],
12
12
  "repository": {
13
13
  "type": "git",
14
14
  "url": "git+https://github.com/mijn-ui/mijn-ui-react.git",
15
- "directory": "packages/components/src"
15
+ "directory": "packages/components/pagination"
16
16
  },
17
17
  "bugs": {
18
18
  "url": "https://github.com/mijn-ui/mijn-ui-react/issues"
@@ -30,8 +30,8 @@
30
30
  "react": "19.0.0-rc-b01722d5-20241114",
31
31
  "react-dom": "19.0.0-rc-b01722d5-20241114",
32
32
  "react-icons": "^5.3.0",
33
- "@mijn-ui/react-utilities": "0.0.3",
34
- "@mijn-ui/react-button": "0.0.3"
33
+ "@mijn-ui/react-utilities": "0.0.4",
34
+ "@mijn-ui/react-button": "0.0.5"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "react": "19.0.0-rc-b01722d5-20241114",