@yamada-ui/pagination 0.1.0

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,115 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/use-pagination.ts
21
+ var use_pagination_exports = {};
22
+ __export(use_pagination_exports, {
23
+ PaginationProvider: () => PaginationProvider,
24
+ computedRange: () => computedRange,
25
+ usePagination: () => usePagination,
26
+ usePaginationContext: () => usePaginationContext
27
+ });
28
+ module.exports = __toCommonJS(use_pagination_exports);
29
+ var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
30
+ var import_use_value = require("@yamada-ui/use-value");
31
+ var import_utils = require("@yamada-ui/utils");
32
+ var import_react = require("react");
33
+ var [PaginationProvider, usePaginationContext] = (0, import_utils.createContext)({
34
+ strict: false,
35
+ name: "PaginationContext"
36
+ });
37
+ var computedRange = (start, end) => Array.from({ length: end - start + 1 }, (_, index) => index + start);
38
+ var usePagination = ({
39
+ page,
40
+ defaultPage = 1,
41
+ total,
42
+ siblings = 1,
43
+ boundaries = 1,
44
+ isDisabled = false,
45
+ ...rest
46
+ }) => {
47
+ const computedSiblings = (0, import_use_value.useValue)(siblings);
48
+ const computedBoundaries = (0, import_use_value.useValue)(boundaries);
49
+ const [currentPage, setCurrentPage] = (0, import_use_controllable_state.useControllableState)({
50
+ value: page,
51
+ defaultValue: defaultPage,
52
+ onChange: rest.onChange
53
+ });
54
+ const onFirst = (0, import_react.useCallback)(() => setCurrentPage(1), [setCurrentPage]);
55
+ const onLast = (0, import_react.useCallback)(() => setCurrentPage(total), [setCurrentPage, total]);
56
+ const onPrev = (0, import_react.useCallback)(
57
+ () => setCurrentPage((prev) => prev === 1 ? prev : prev - 1),
58
+ [setCurrentPage]
59
+ );
60
+ const onNext = (0, import_react.useCallback)(
61
+ () => setCurrentPage((prev) => prev === total ? prev : prev + 1),
62
+ [setCurrentPage, total]
63
+ );
64
+ const onChange = (0, import_react.useCallback)((page2) => setCurrentPage(page2), [setCurrentPage]);
65
+ const range = (0, import_react.useMemo)(() => {
66
+ const minimumTotal = computedSiblings * 2 + 3 + computedBoundaries * 2;
67
+ if (minimumTotal >= total)
68
+ return computedRange(1, total);
69
+ const prevSiblings = Math.max(currentPage - computedSiblings, computedBoundaries);
70
+ const nextSiblings = Math.min(currentPage + computedSiblings, total - computedBoundaries);
71
+ const prevDots = prevSiblings > computedBoundaries + 2;
72
+ const nextDots = nextSiblings < total - (computedBoundaries + 1);
73
+ if (!prevDots && nextDots) {
74
+ const prevPages = computedSiblings * 2 + computedBoundaries + 2;
75
+ return [
76
+ ...computedRange(1, prevPages),
77
+ "dots",
78
+ ...computedRange(total - (computedBoundaries - 1), total)
79
+ ];
80
+ }
81
+ if (prevDots && !nextDots) {
82
+ const nextPages = computedBoundaries + 1 + 2 * computedSiblings;
83
+ return [
84
+ ...computedRange(1, computedBoundaries),
85
+ "dots",
86
+ ...computedRange(total - nextPages, total)
87
+ ];
88
+ }
89
+ return [
90
+ ...computedRange(1, computedBoundaries),
91
+ "dots",
92
+ ...computedRange(prevSiblings, nextSiblings),
93
+ "dots",
94
+ ...computedRange(total - computedBoundaries + 1, total)
95
+ ];
96
+ }, [computedBoundaries, computedSiblings, currentPage, total]);
97
+ return {
98
+ currentPage,
99
+ total,
100
+ isDisabled,
101
+ onFirst,
102
+ onLast,
103
+ onPrev,
104
+ onNext,
105
+ onChange,
106
+ range
107
+ };
108
+ };
109
+ // Annotate the CommonJS export names for ESM import in node:
110
+ 0 && (module.exports = {
111
+ PaginationProvider,
112
+ computedRange,
113
+ usePagination,
114
+ usePaginationContext
115
+ });
@@ -0,0 +1,12 @@
1
+ import {
2
+ PaginationProvider,
3
+ computedRange,
4
+ usePagination,
5
+ usePaginationContext
6
+ } from "./chunk-3KNXDAHV.mjs";
7
+ export {
8
+ PaginationProvider,
9
+ computedRange,
10
+ usePagination,
11
+ usePaginationContext
12
+ };
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@yamada-ui/pagination",
3
+ "version": "0.1.0",
4
+ "description": "Yamada UI pagination component",
5
+ "keywords": [
6
+ "yamada",
7
+ "yamada ui",
8
+ "react",
9
+ "emotion",
10
+ "component",
11
+ "pagination",
12
+ "ui",
13
+ "uikit",
14
+ "styled",
15
+ "style-props",
16
+ "styled-component",
17
+ "css-in-js"
18
+ ],
19
+ "author": "Hirotomo Yamada <hirotomo.yamada@avap.co.jp>",
20
+ "license": "MIT",
21
+ "main": "dist/index.js",
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "sideEffects": false,
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/hirotomoyamada/yamada-ui",
32
+ "directory": "packages/components/pagination"
33
+ },
34
+ "bugs": {
35
+ "url": "https://github.com/hirotomoyamada/yamada-ui/issues"
36
+ },
37
+ "dependencies": {
38
+ "@yamada-ui/core": "0.1.0",
39
+ "@yamada-ui/utils": "0.1.0",
40
+ "@yamada-ui/icon": "0.1.0",
41
+ "@yamada-ui/use-controllable-state": "0.1.0",
42
+ "@yamada-ui/use-value": "0.1.0"
43
+ },
44
+ "devDependencies": {
45
+ "react": "^18.0.0",
46
+ "clean-package": "2.2.0"
47
+ },
48
+ "peerDependencies": {
49
+ "react": ">=18"
50
+ },
51
+ "clean-package": "../../../clean-package.config.json",
52
+ "tsup": {
53
+ "clean": true,
54
+ "target": "es2019",
55
+ "format": [
56
+ "cjs",
57
+ "esm"
58
+ ]
59
+ },
60
+ "module": "dist/index.mjs",
61
+ "types": "dist/index.d.ts",
62
+ "exports": {
63
+ ".": {
64
+ "types": "./dist/index.d.ts",
65
+ "import": "./dist/index.mjs",
66
+ "require": "./dist/index.js"
67
+ },
68
+ "./package.json": "./package.json"
69
+ },
70
+ "scripts": {
71
+ "dev": "pnpm build:fast -- --watch",
72
+ "build": "tsup src --dts",
73
+ "build:fast": "tsup src",
74
+ "clean": "rimraf dist .turbo",
75
+ "typecheck": "tsc --noEmit",
76
+ "gen:docs": "tsx ../../../scripts/generate-docs"
77
+ }
78
+ }