@mijn-ui/react-pagination 0.0.2 → 0.0.4

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