@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.
- package/LICENSE +21 -0
- package/README.md +28 -0
- package/dist/chunk-3JXQPHJH.mjs +59 -0
- package/dist/chunk-3KNXDAHV.mjs +88 -0
- package/dist/chunk-IXTXZCRI.mjs +56 -0
- package/dist/chunk-OQAHPAGR.mjs +119 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +312 -0
- package/dist/index.mjs +9 -0
- package/dist/pagination-icon.d.ts +10 -0
- package/dist/pagination-icon.js +84 -0
- package/dist/pagination-icon.mjs +14 -0
- package/dist/pagination-item.d.ts +12 -0
- package/dist/pagination-item.js +133 -0
- package/dist/pagination-item.mjs +8 -0
- package/dist/pagination.d.ts +22 -0
- package/dist/pagination.js +310 -0
- package/dist/pagination.mjs +9 -0
- package/dist/use-pagination.d.ts +30 -0
- package/dist/use-pagination.js +115 -0
- package/dist/use-pagination.mjs +12 -0
- package/package.json +78 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IconProps } from '@yamada-ui/icon';
|
|
2
|
+
import { FC } from 'react';
|
|
3
|
+
|
|
4
|
+
declare const DotsIcon: FC<IconProps>;
|
|
5
|
+
declare const FirstIcon: FC<IconProps>;
|
|
6
|
+
declare const LastIcon: FC<IconProps>;
|
|
7
|
+
declare const PrevIcon: FC<IconProps>;
|
|
8
|
+
declare const NextIcon: FC<IconProps>;
|
|
9
|
+
|
|
10
|
+
export { DotsIcon, FirstIcon, LastIcon, NextIcon, PrevIcon };
|
|
@@ -0,0 +1,84 @@
|
|
|
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/pagination-icon.tsx
|
|
21
|
+
var pagination_icon_exports = {};
|
|
22
|
+
__export(pagination_icon_exports, {
|
|
23
|
+
DotsIcon: () => DotsIcon,
|
|
24
|
+
FirstIcon: () => FirstIcon,
|
|
25
|
+
LastIcon: () => LastIcon,
|
|
26
|
+
NextIcon: () => NextIcon,
|
|
27
|
+
PrevIcon: () => PrevIcon
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(pagination_icon_exports);
|
|
30
|
+
var import_icon = require("@yamada-ui/icon");
|
|
31
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
32
|
+
var DotsIcon = (props) => {
|
|
33
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
34
|
+
"path",
|
|
35
|
+
{
|
|
36
|
+
fill: "currentColor",
|
|
37
|
+
d: "M2 8c0-.733.6-1.333 1.333-1.333.734 0 1.334.6 1.334 1.333s-.6 1.333-1.334 1.333C2.6 9.333 2 8.733 2 8zm9.333 0c0-.733.6-1.333 1.334-1.333C13.4 6.667 14 7.267 14 8s-.6 1.333-1.333 1.333c-.734 0-1.334-.6-1.334-1.333zM6.667 8c0-.733.6-1.333 1.333-1.333s1.333.6 1.333 1.333S8.733 9.333 8 9.333 6.667 8.733 6.667 8z"
|
|
38
|
+
}
|
|
39
|
+
) });
|
|
40
|
+
};
|
|
41
|
+
var FirstIcon = (props) => {
|
|
42
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
43
|
+
"path",
|
|
44
|
+
{
|
|
45
|
+
fill: "currentColor",
|
|
46
|
+
d: "M6.85355 3.85355C7.04882 3.65829 7.04882 3.34171 6.85355 3.14645C6.65829 2.95118 6.34171 2.95118 6.14645 3.14645L2.14645 7.14645C1.95118 7.34171 1.95118 7.65829 2.14645 7.85355L6.14645 11.8536C6.34171 12.0488 6.65829 12.0488 6.85355 11.8536C7.04882 11.6583 7.04882 11.3417 6.85355 11.1464L3.20711 7.5L6.85355 3.85355ZM12.8536 3.85355C13.0488 3.65829 13.0488 3.34171 12.8536 3.14645C12.6583 2.95118 12.3417 2.95118 12.1464 3.14645L8.14645 7.14645C7.95118 7.34171 7.95118 7.65829 8.14645 7.85355L12.1464 11.8536C12.3417 12.0488 12.6583 12.0488 12.8536 11.8536C13.0488 11.6583 13.0488 11.3417 12.8536 11.1464L9.20711 7.5L12.8536 3.85355Z"
|
|
47
|
+
}
|
|
48
|
+
) });
|
|
49
|
+
};
|
|
50
|
+
var LastIcon = (props) => {
|
|
51
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
52
|
+
"path",
|
|
53
|
+
{
|
|
54
|
+
fill: "currentColor",
|
|
55
|
+
d: "M2.14645 11.1464C1.95118 11.3417 1.95118 11.6583 2.14645 11.8536C2.34171 12.0488 2.65829 12.0488 2.85355 11.8536L6.85355 7.85355C7.04882 7.65829 7.04882 7.34171 6.85355 7.14645L2.85355 3.14645C2.65829 2.95118 2.34171 2.95118 2.14645 3.14645C1.95118 3.34171 1.95118 3.65829 2.14645 3.85355L5.79289 7.5L2.14645 11.1464ZM8.14645 11.1464C7.95118 11.3417 7.95118 11.6583 8.14645 11.8536C8.34171 12.0488 8.65829 12.0488 8.85355 11.8536L12.8536 7.85355C13.0488 7.65829 13.0488 7.34171 12.8536 7.14645L8.85355 3.14645C8.65829 2.95118 8.34171 2.95118 8.14645 3.14645C7.95118 3.34171 7.95118 3.65829 8.14645 3.85355L11.7929 7.5L8.14645 11.1464Z"
|
|
56
|
+
}
|
|
57
|
+
) });
|
|
58
|
+
};
|
|
59
|
+
var PrevIcon = (props) => {
|
|
60
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
61
|
+
"path",
|
|
62
|
+
{
|
|
63
|
+
fill: "currentColor",
|
|
64
|
+
d: "M7.219 8l3.3 3.3-.943.943L5.333 8l4.243-4.243.943.943-3.3 3.3z"
|
|
65
|
+
}
|
|
66
|
+
) });
|
|
67
|
+
};
|
|
68
|
+
var NextIcon = (props) => {
|
|
69
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
70
|
+
"path",
|
|
71
|
+
{
|
|
72
|
+
fill: "currentColor",
|
|
73
|
+
d: "M8.781 8l-3.3-3.3.943-.943L10.667 8l-4.243 4.243-.943-.943 3.3-3.3z"
|
|
74
|
+
}
|
|
75
|
+
) });
|
|
76
|
+
};
|
|
77
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
+
0 && (module.exports = {
|
|
79
|
+
DotsIcon,
|
|
80
|
+
FirstIcon,
|
|
81
|
+
LastIcon,
|
|
82
|
+
NextIcon,
|
|
83
|
+
PrevIcon
|
|
84
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef, FC } from 'react';
|
|
2
|
+
|
|
3
|
+
type Page = number | 'dots' | 'prev' | 'next' | 'first' | 'last';
|
|
4
|
+
type PaginationItemOptions = {
|
|
5
|
+
page: Page;
|
|
6
|
+
isActive?: boolean;
|
|
7
|
+
isDisabled?: boolean;
|
|
8
|
+
};
|
|
9
|
+
type PaginationItemProps = ComponentPropsWithoutRef<'button'> & PaginationItemOptions;
|
|
10
|
+
declare const PaginationItem: FC<PaginationItemProps>;
|
|
11
|
+
|
|
12
|
+
export { PaginationItem, PaginationItemProps };
|
|
@@ -0,0 +1,133 @@
|
|
|
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/pagination-item.tsx
|
|
21
|
+
var pagination_item_exports = {};
|
|
22
|
+
__export(pagination_item_exports, {
|
|
23
|
+
PaginationItem: () => PaginationItem
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(pagination_item_exports);
|
|
26
|
+
var import_core = require("@yamada-ui/core");
|
|
27
|
+
var import_utils2 = require("@yamada-ui/utils");
|
|
28
|
+
|
|
29
|
+
// src/pagination-icon.tsx
|
|
30
|
+
var import_icon = require("@yamada-ui/icon");
|
|
31
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
32
|
+
var DotsIcon = (props) => {
|
|
33
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
34
|
+
"path",
|
|
35
|
+
{
|
|
36
|
+
fill: "currentColor",
|
|
37
|
+
d: "M2 8c0-.733.6-1.333 1.333-1.333.734 0 1.334.6 1.334 1.333s-.6 1.333-1.334 1.333C2.6 9.333 2 8.733 2 8zm9.333 0c0-.733.6-1.333 1.334-1.333C13.4 6.667 14 7.267 14 8s-.6 1.333-1.333 1.333c-.734 0-1.334-.6-1.334-1.333zM6.667 8c0-.733.6-1.333 1.333-1.333s1.333.6 1.333 1.333S8.733 9.333 8 9.333 6.667 8.733 6.667 8z"
|
|
38
|
+
}
|
|
39
|
+
) });
|
|
40
|
+
};
|
|
41
|
+
var FirstIcon = (props) => {
|
|
42
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
43
|
+
"path",
|
|
44
|
+
{
|
|
45
|
+
fill: "currentColor",
|
|
46
|
+
d: "M6.85355 3.85355C7.04882 3.65829 7.04882 3.34171 6.85355 3.14645C6.65829 2.95118 6.34171 2.95118 6.14645 3.14645L2.14645 7.14645C1.95118 7.34171 1.95118 7.65829 2.14645 7.85355L6.14645 11.8536C6.34171 12.0488 6.65829 12.0488 6.85355 11.8536C7.04882 11.6583 7.04882 11.3417 6.85355 11.1464L3.20711 7.5L6.85355 3.85355ZM12.8536 3.85355C13.0488 3.65829 13.0488 3.34171 12.8536 3.14645C12.6583 2.95118 12.3417 2.95118 12.1464 3.14645L8.14645 7.14645C7.95118 7.34171 7.95118 7.65829 8.14645 7.85355L12.1464 11.8536C12.3417 12.0488 12.6583 12.0488 12.8536 11.8536C13.0488 11.6583 13.0488 11.3417 12.8536 11.1464L9.20711 7.5L12.8536 3.85355Z"
|
|
47
|
+
}
|
|
48
|
+
) });
|
|
49
|
+
};
|
|
50
|
+
var LastIcon = (props) => {
|
|
51
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
52
|
+
"path",
|
|
53
|
+
{
|
|
54
|
+
fill: "currentColor",
|
|
55
|
+
d: "M2.14645 11.1464C1.95118 11.3417 1.95118 11.6583 2.14645 11.8536C2.34171 12.0488 2.65829 12.0488 2.85355 11.8536L6.85355 7.85355C7.04882 7.65829 7.04882 7.34171 6.85355 7.14645L2.85355 3.14645C2.65829 2.95118 2.34171 2.95118 2.14645 3.14645C1.95118 3.34171 1.95118 3.65829 2.14645 3.85355L5.79289 7.5L2.14645 11.1464ZM8.14645 11.1464C7.95118 11.3417 7.95118 11.6583 8.14645 11.8536C8.34171 12.0488 8.65829 12.0488 8.85355 11.8536L12.8536 7.85355C13.0488 7.65829 13.0488 7.34171 12.8536 7.14645L8.85355 3.14645C8.65829 2.95118 8.34171 2.95118 8.14645 3.14645C7.95118 3.34171 7.95118 3.65829 8.14645 3.85355L11.7929 7.5L8.14645 11.1464Z"
|
|
56
|
+
}
|
|
57
|
+
) });
|
|
58
|
+
};
|
|
59
|
+
var PrevIcon = (props) => {
|
|
60
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
61
|
+
"path",
|
|
62
|
+
{
|
|
63
|
+
fill: "currentColor",
|
|
64
|
+
d: "M7.219 8l3.3 3.3-.943.943L5.333 8l4.243-4.243.943.943-3.3 3.3z"
|
|
65
|
+
}
|
|
66
|
+
) });
|
|
67
|
+
};
|
|
68
|
+
var NextIcon = (props) => {
|
|
69
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
70
|
+
"path",
|
|
71
|
+
{
|
|
72
|
+
fill: "currentColor",
|
|
73
|
+
d: "M8.781 8l-3.3-3.3.943-.943L10.667 8l-4.243 4.243-.943-.943 3.3-3.3z"
|
|
74
|
+
}
|
|
75
|
+
) });
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// src/use-pagination.ts
|
|
79
|
+
var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
|
|
80
|
+
var import_use_value = require("@yamada-ui/use-value");
|
|
81
|
+
var import_utils = require("@yamada-ui/utils");
|
|
82
|
+
var import_react = require("react");
|
|
83
|
+
var [PaginationProvider, usePaginationContext] = (0, import_utils.createContext)({
|
|
84
|
+
strict: false,
|
|
85
|
+
name: "PaginationContext"
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// src/pagination-item.tsx
|
|
89
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
90
|
+
var iconMap = {
|
|
91
|
+
dots: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(DotsIcon, {}),
|
|
92
|
+
next: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NextIcon, {}),
|
|
93
|
+
prev: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PrevIcon, {}),
|
|
94
|
+
first: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(FirstIcon, {}),
|
|
95
|
+
last: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(LastIcon, {})
|
|
96
|
+
};
|
|
97
|
+
var PaginationItem = ({
|
|
98
|
+
className,
|
|
99
|
+
isActive,
|
|
100
|
+
page,
|
|
101
|
+
isDisabled,
|
|
102
|
+
children,
|
|
103
|
+
...rest
|
|
104
|
+
}) => {
|
|
105
|
+
var _a;
|
|
106
|
+
const styles = usePaginationContext();
|
|
107
|
+
children != null ? children : children = (_a = iconMap[page]) != null ? _a : page;
|
|
108
|
+
const css = {
|
|
109
|
+
display: "flex",
|
|
110
|
+
justifyContent: "center",
|
|
111
|
+
alignItems: "center",
|
|
112
|
+
...styles.item,
|
|
113
|
+
...styles[page]
|
|
114
|
+
};
|
|
115
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
116
|
+
import_core.ui.button,
|
|
117
|
+
{
|
|
118
|
+
className: (0, import_utils2.cx)("ui-pagination-item", className),
|
|
119
|
+
type: "button",
|
|
120
|
+
tabIndex: page !== "dots" ? 0 : -1,
|
|
121
|
+
disabled: isDisabled,
|
|
122
|
+
"data-selected": (0, import_utils2.dataAttr)(isActive),
|
|
123
|
+
"data-disabled": (0, import_utils2.dataAttr)(isDisabled),
|
|
124
|
+
__css: css,
|
|
125
|
+
...rest,
|
|
126
|
+
children
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
};
|
|
130
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
131
|
+
0 && (module.exports = {
|
|
132
|
+
PaginationItem
|
|
133
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as _yamada_ui_core from '@yamada-ui/core';
|
|
2
|
+
import { HTMLUIProps, ThemeProps, Token } from '@yamada-ui/core';
|
|
3
|
+
import { FC } from 'react';
|
|
4
|
+
import { PaginationItemProps } from './pagination-item.js';
|
|
5
|
+
import { UsePaginationProps } from './use-pagination.js';
|
|
6
|
+
|
|
7
|
+
type PaginationOptions = {
|
|
8
|
+
component?: FC<PaginationItemProps>;
|
|
9
|
+
itemProps?: HTMLUIProps<'button'>;
|
|
10
|
+
withControls?: Token<boolean>;
|
|
11
|
+
controlProps?: HTMLUIProps<'button'>;
|
|
12
|
+
controlPrevProps?: HTMLUIProps<'button'>;
|
|
13
|
+
controlNextProps?: HTMLUIProps<'button'>;
|
|
14
|
+
withEdges?: Token<boolean>;
|
|
15
|
+
edgeProps?: HTMLUIProps<'button'>;
|
|
16
|
+
edgeFirstProps?: HTMLUIProps<'button'>;
|
|
17
|
+
edgeLastProps?: HTMLUIProps<'button'>;
|
|
18
|
+
};
|
|
19
|
+
type PaginationProps = Omit<HTMLUIProps<'div'>, 'onChange' | 'children'> & ThemeProps<'Pagination'> & UsePaginationProps & PaginationOptions;
|
|
20
|
+
declare const Pagination: _yamada_ui_core.Component<"div", PaginationProps>;
|
|
21
|
+
|
|
22
|
+
export { Pagination, PaginationProps };
|
|
@@ -0,0 +1,310 @@
|
|
|
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/pagination.tsx
|
|
21
|
+
var pagination_exports = {};
|
|
22
|
+
__export(pagination_exports, {
|
|
23
|
+
Pagination: () => Pagination
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(pagination_exports);
|
|
26
|
+
var import_core2 = require("@yamada-ui/core");
|
|
27
|
+
var import_use_value2 = require("@yamada-ui/use-value");
|
|
28
|
+
var import_utils3 = require("@yamada-ui/utils");
|
|
29
|
+
var import_react2 = require("react");
|
|
30
|
+
|
|
31
|
+
// src/pagination-item.tsx
|
|
32
|
+
var import_core = require("@yamada-ui/core");
|
|
33
|
+
var import_utils2 = require("@yamada-ui/utils");
|
|
34
|
+
|
|
35
|
+
// src/pagination-icon.tsx
|
|
36
|
+
var import_icon = require("@yamada-ui/icon");
|
|
37
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
38
|
+
var DotsIcon = (props) => {
|
|
39
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
40
|
+
"path",
|
|
41
|
+
{
|
|
42
|
+
fill: "currentColor",
|
|
43
|
+
d: "M2 8c0-.733.6-1.333 1.333-1.333.734 0 1.334.6 1.334 1.333s-.6 1.333-1.334 1.333C2.6 9.333 2 8.733 2 8zm9.333 0c0-.733.6-1.333 1.334-1.333C13.4 6.667 14 7.267 14 8s-.6 1.333-1.333 1.333c-.734 0-1.334-.6-1.334-1.333zM6.667 8c0-.733.6-1.333 1.333-1.333s1.333.6 1.333 1.333S8.733 9.333 8 9.333 6.667 8.733 6.667 8z"
|
|
44
|
+
}
|
|
45
|
+
) });
|
|
46
|
+
};
|
|
47
|
+
var FirstIcon = (props) => {
|
|
48
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
49
|
+
"path",
|
|
50
|
+
{
|
|
51
|
+
fill: "currentColor",
|
|
52
|
+
d: "M6.85355 3.85355C7.04882 3.65829 7.04882 3.34171 6.85355 3.14645C6.65829 2.95118 6.34171 2.95118 6.14645 3.14645L2.14645 7.14645C1.95118 7.34171 1.95118 7.65829 2.14645 7.85355L6.14645 11.8536C6.34171 12.0488 6.65829 12.0488 6.85355 11.8536C7.04882 11.6583 7.04882 11.3417 6.85355 11.1464L3.20711 7.5L6.85355 3.85355ZM12.8536 3.85355C13.0488 3.65829 13.0488 3.34171 12.8536 3.14645C12.6583 2.95118 12.3417 2.95118 12.1464 3.14645L8.14645 7.14645C7.95118 7.34171 7.95118 7.65829 8.14645 7.85355L12.1464 11.8536C12.3417 12.0488 12.6583 12.0488 12.8536 11.8536C13.0488 11.6583 13.0488 11.3417 12.8536 11.1464L9.20711 7.5L12.8536 3.85355Z"
|
|
53
|
+
}
|
|
54
|
+
) });
|
|
55
|
+
};
|
|
56
|
+
var LastIcon = (props) => {
|
|
57
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
58
|
+
"path",
|
|
59
|
+
{
|
|
60
|
+
fill: "currentColor",
|
|
61
|
+
d: "M2.14645 11.1464C1.95118 11.3417 1.95118 11.6583 2.14645 11.8536C2.34171 12.0488 2.65829 12.0488 2.85355 11.8536L6.85355 7.85355C7.04882 7.65829 7.04882 7.34171 6.85355 7.14645L2.85355 3.14645C2.65829 2.95118 2.34171 2.95118 2.14645 3.14645C1.95118 3.34171 1.95118 3.65829 2.14645 3.85355L5.79289 7.5L2.14645 11.1464ZM8.14645 11.1464C7.95118 11.3417 7.95118 11.6583 8.14645 11.8536C8.34171 12.0488 8.65829 12.0488 8.85355 11.8536L12.8536 7.85355C13.0488 7.65829 13.0488 7.34171 12.8536 7.14645L8.85355 3.14645C8.65829 2.95118 8.34171 2.95118 8.14645 3.14645C7.95118 3.34171 7.95118 3.65829 8.14645 3.85355L11.7929 7.5L8.14645 11.1464Z"
|
|
62
|
+
}
|
|
63
|
+
) });
|
|
64
|
+
};
|
|
65
|
+
var PrevIcon = (props) => {
|
|
66
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
67
|
+
"path",
|
|
68
|
+
{
|
|
69
|
+
fill: "currentColor",
|
|
70
|
+
d: "M7.219 8l3.3 3.3-.943.943L5.333 8l4.243-4.243.943.943-3.3 3.3z"
|
|
71
|
+
}
|
|
72
|
+
) });
|
|
73
|
+
};
|
|
74
|
+
var NextIcon = (props) => {
|
|
75
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
76
|
+
"path",
|
|
77
|
+
{
|
|
78
|
+
fill: "currentColor",
|
|
79
|
+
d: "M8.781 8l-3.3-3.3.943-.943L10.667 8l-4.243 4.243-.943-.943 3.3-3.3z"
|
|
80
|
+
}
|
|
81
|
+
) });
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// src/use-pagination.ts
|
|
85
|
+
var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
|
|
86
|
+
var import_use_value = require("@yamada-ui/use-value");
|
|
87
|
+
var import_utils = require("@yamada-ui/utils");
|
|
88
|
+
var import_react = require("react");
|
|
89
|
+
var [PaginationProvider, usePaginationContext] = (0, import_utils.createContext)({
|
|
90
|
+
strict: false,
|
|
91
|
+
name: "PaginationContext"
|
|
92
|
+
});
|
|
93
|
+
var computedRange = (start, end) => Array.from({ length: end - start + 1 }, (_, index) => index + start);
|
|
94
|
+
var usePagination = ({
|
|
95
|
+
page,
|
|
96
|
+
defaultPage = 1,
|
|
97
|
+
total,
|
|
98
|
+
siblings = 1,
|
|
99
|
+
boundaries = 1,
|
|
100
|
+
isDisabled = false,
|
|
101
|
+
...rest
|
|
102
|
+
}) => {
|
|
103
|
+
const computedSiblings = (0, import_use_value.useValue)(siblings);
|
|
104
|
+
const computedBoundaries = (0, import_use_value.useValue)(boundaries);
|
|
105
|
+
const [currentPage, setCurrentPage] = (0, import_use_controllable_state.useControllableState)({
|
|
106
|
+
value: page,
|
|
107
|
+
defaultValue: defaultPage,
|
|
108
|
+
onChange: rest.onChange
|
|
109
|
+
});
|
|
110
|
+
const onFirst = (0, import_react.useCallback)(() => setCurrentPage(1), [setCurrentPage]);
|
|
111
|
+
const onLast = (0, import_react.useCallback)(() => setCurrentPage(total), [setCurrentPage, total]);
|
|
112
|
+
const onPrev = (0, import_react.useCallback)(
|
|
113
|
+
() => setCurrentPage((prev) => prev === 1 ? prev : prev - 1),
|
|
114
|
+
[setCurrentPage]
|
|
115
|
+
);
|
|
116
|
+
const onNext = (0, import_react.useCallback)(
|
|
117
|
+
() => setCurrentPage((prev) => prev === total ? prev : prev + 1),
|
|
118
|
+
[setCurrentPage, total]
|
|
119
|
+
);
|
|
120
|
+
const onChange = (0, import_react.useCallback)((page2) => setCurrentPage(page2), [setCurrentPage]);
|
|
121
|
+
const range = (0, import_react.useMemo)(() => {
|
|
122
|
+
const minimumTotal = computedSiblings * 2 + 3 + computedBoundaries * 2;
|
|
123
|
+
if (minimumTotal >= total)
|
|
124
|
+
return computedRange(1, total);
|
|
125
|
+
const prevSiblings = Math.max(currentPage - computedSiblings, computedBoundaries);
|
|
126
|
+
const nextSiblings = Math.min(currentPage + computedSiblings, total - computedBoundaries);
|
|
127
|
+
const prevDots = prevSiblings > computedBoundaries + 2;
|
|
128
|
+
const nextDots = nextSiblings < total - (computedBoundaries + 1);
|
|
129
|
+
if (!prevDots && nextDots) {
|
|
130
|
+
const prevPages = computedSiblings * 2 + computedBoundaries + 2;
|
|
131
|
+
return [
|
|
132
|
+
...computedRange(1, prevPages),
|
|
133
|
+
"dots",
|
|
134
|
+
...computedRange(total - (computedBoundaries - 1), total)
|
|
135
|
+
];
|
|
136
|
+
}
|
|
137
|
+
if (prevDots && !nextDots) {
|
|
138
|
+
const nextPages = computedBoundaries + 1 + 2 * computedSiblings;
|
|
139
|
+
return [
|
|
140
|
+
...computedRange(1, computedBoundaries),
|
|
141
|
+
"dots",
|
|
142
|
+
...computedRange(total - nextPages, total)
|
|
143
|
+
];
|
|
144
|
+
}
|
|
145
|
+
return [
|
|
146
|
+
...computedRange(1, computedBoundaries),
|
|
147
|
+
"dots",
|
|
148
|
+
...computedRange(prevSiblings, nextSiblings),
|
|
149
|
+
"dots",
|
|
150
|
+
...computedRange(total - computedBoundaries + 1, total)
|
|
151
|
+
];
|
|
152
|
+
}, [computedBoundaries, computedSiblings, currentPage, total]);
|
|
153
|
+
return {
|
|
154
|
+
currentPage,
|
|
155
|
+
total,
|
|
156
|
+
isDisabled,
|
|
157
|
+
onFirst,
|
|
158
|
+
onLast,
|
|
159
|
+
onPrev,
|
|
160
|
+
onNext,
|
|
161
|
+
onChange,
|
|
162
|
+
range
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// src/pagination-item.tsx
|
|
167
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
168
|
+
var iconMap = {
|
|
169
|
+
dots: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(DotsIcon, {}),
|
|
170
|
+
next: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NextIcon, {}),
|
|
171
|
+
prev: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PrevIcon, {}),
|
|
172
|
+
first: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(FirstIcon, {}),
|
|
173
|
+
last: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(LastIcon, {})
|
|
174
|
+
};
|
|
175
|
+
var PaginationItem = ({
|
|
176
|
+
className,
|
|
177
|
+
isActive,
|
|
178
|
+
page,
|
|
179
|
+
isDisabled,
|
|
180
|
+
children,
|
|
181
|
+
...rest
|
|
182
|
+
}) => {
|
|
183
|
+
var _a;
|
|
184
|
+
const styles = usePaginationContext();
|
|
185
|
+
children != null ? children : children = (_a = iconMap[page]) != null ? _a : page;
|
|
186
|
+
const css = {
|
|
187
|
+
display: "flex",
|
|
188
|
+
justifyContent: "center",
|
|
189
|
+
alignItems: "center",
|
|
190
|
+
...styles.item,
|
|
191
|
+
...styles[page]
|
|
192
|
+
};
|
|
193
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
194
|
+
import_core.ui.button,
|
|
195
|
+
{
|
|
196
|
+
className: (0, import_utils2.cx)("ui-pagination-item", className),
|
|
197
|
+
type: "button",
|
|
198
|
+
tabIndex: page !== "dots" ? 0 : -1,
|
|
199
|
+
disabled: isDisabled,
|
|
200
|
+
"data-selected": (0, import_utils2.dataAttr)(isActive),
|
|
201
|
+
"data-disabled": (0, import_utils2.dataAttr)(isDisabled),
|
|
202
|
+
__css: css,
|
|
203
|
+
...rest,
|
|
204
|
+
children
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// src/pagination.tsx
|
|
210
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
211
|
+
var Pagination = (0, import_core2.forwardRef)((props, ref) => {
|
|
212
|
+
const [styles, mergedProps] = (0, import_core2.useMultiComponentStyle)("Pagination", props);
|
|
213
|
+
const {
|
|
214
|
+
className,
|
|
215
|
+
component: Component = PaginationItem,
|
|
216
|
+
itemProps,
|
|
217
|
+
withControls = true,
|
|
218
|
+
withEdges = false,
|
|
219
|
+
controlProps,
|
|
220
|
+
controlPrevProps,
|
|
221
|
+
controlNextProps,
|
|
222
|
+
edgeProps,
|
|
223
|
+
edgeFirstProps,
|
|
224
|
+
edgeLastProps,
|
|
225
|
+
...rest
|
|
226
|
+
} = (0, import_core2.omitThemeProps)(mergedProps);
|
|
227
|
+
const computedWithControls = (0, import_use_value2.useValue)(withControls);
|
|
228
|
+
const computedWithEdges = (0, import_use_value2.useValue)(withEdges);
|
|
229
|
+
const { currentPage, total, isDisabled, onFirst, onLast, onPrev, onNext, onChange, range } = usePagination(rest);
|
|
230
|
+
const children = (0, import_react2.useMemo)(
|
|
231
|
+
() => range.map((page, key) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
232
|
+
Component,
|
|
233
|
+
{
|
|
234
|
+
page,
|
|
235
|
+
isActive: currentPage === page,
|
|
236
|
+
isDisabled,
|
|
237
|
+
...itemProps,
|
|
238
|
+
onClick: (0, import_utils3.handlerAll)(
|
|
239
|
+
itemProps == null ? void 0 : itemProps.onClick,
|
|
240
|
+
page !== "dots" ? () => onChange(page) : void 0
|
|
241
|
+
)
|
|
242
|
+
},
|
|
243
|
+
key
|
|
244
|
+
)),
|
|
245
|
+
[Component, currentPage, isDisabled, onChange, range, itemProps]
|
|
246
|
+
);
|
|
247
|
+
const css = { display: "flex", alignItems: "center", ...styles.container };
|
|
248
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(PaginationProvider, { value: styles, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
249
|
+
import_core2.ui.div,
|
|
250
|
+
{
|
|
251
|
+
ref,
|
|
252
|
+
className: (0, import_utils3.cx)("ui-pagination", className),
|
|
253
|
+
role: "navigation",
|
|
254
|
+
__css: css,
|
|
255
|
+
...(0, import_utils3.omitObject)(rest, ["onChange"]),
|
|
256
|
+
"data-disabled": (0, import_utils3.dataAttr)(isDisabled),
|
|
257
|
+
children: [
|
|
258
|
+
computedWithEdges ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
259
|
+
Component,
|
|
260
|
+
{
|
|
261
|
+
page: "first",
|
|
262
|
+
className: "ui-pagination-item-first",
|
|
263
|
+
isDisabled: isDisabled || currentPage === 1,
|
|
264
|
+
...edgeProps,
|
|
265
|
+
...edgeFirstProps,
|
|
266
|
+
onClick: (0, import_utils3.handlerAll)(edgeProps == null ? void 0 : edgeProps.onClick, edgeFirstProps == null ? void 0 : edgeFirstProps.onClick, onFirst)
|
|
267
|
+
}
|
|
268
|
+
) : null,
|
|
269
|
+
computedWithControls ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
270
|
+
Component,
|
|
271
|
+
{
|
|
272
|
+
page: "prev",
|
|
273
|
+
className: "ui-pagination-item-prev",
|
|
274
|
+
isDisabled: isDisabled || currentPage === 1,
|
|
275
|
+
...controlProps,
|
|
276
|
+
...controlPrevProps,
|
|
277
|
+
onClick: (0, import_utils3.handlerAll)(controlProps == null ? void 0 : controlProps.onClick, controlPrevProps == null ? void 0 : controlPrevProps.onClick, onPrev)
|
|
278
|
+
}
|
|
279
|
+
) : null,
|
|
280
|
+
children,
|
|
281
|
+
computedWithControls ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
282
|
+
Component,
|
|
283
|
+
{
|
|
284
|
+
page: "next",
|
|
285
|
+
className: "ui-pagination-item-next",
|
|
286
|
+
isDisabled: isDisabled || currentPage === total,
|
|
287
|
+
...controlProps,
|
|
288
|
+
...controlNextProps,
|
|
289
|
+
onClick: (0, import_utils3.handlerAll)(controlProps == null ? void 0 : controlProps.onClick, controlNextProps == null ? void 0 : controlNextProps.onClick, onNext)
|
|
290
|
+
}
|
|
291
|
+
) : null,
|
|
292
|
+
computedWithEdges ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
293
|
+
Component,
|
|
294
|
+
{
|
|
295
|
+
page: "last",
|
|
296
|
+
className: "ui-pagination-item-last",
|
|
297
|
+
isDisabled: isDisabled || currentPage === total,
|
|
298
|
+
...edgeProps,
|
|
299
|
+
...edgeLastProps,
|
|
300
|
+
onClick: (0, import_utils3.handlerAll)(edgeProps == null ? void 0 : edgeProps.onClick, edgeLastProps == null ? void 0 : edgeLastProps.onClick, onLast)
|
|
301
|
+
}
|
|
302
|
+
) : null
|
|
303
|
+
]
|
|
304
|
+
}
|
|
305
|
+
) });
|
|
306
|
+
});
|
|
307
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
308
|
+
0 && (module.exports = {
|
|
309
|
+
Pagination
|
|
310
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { Token, CSSUIObject } from '@yamada-ui/core';
|
|
3
|
+
|
|
4
|
+
type PaginationContext = Record<string, CSSUIObject>;
|
|
5
|
+
declare const PaginationProvider: react.Provider<PaginationContext>;
|
|
6
|
+
declare const usePaginationContext: () => PaginationContext;
|
|
7
|
+
type UsePaginationProps = {
|
|
8
|
+
page?: number;
|
|
9
|
+
defaultPage?: number;
|
|
10
|
+
total: number;
|
|
11
|
+
siblings?: Token<number>;
|
|
12
|
+
boundaries?: Token<number>;
|
|
13
|
+
isDisabled?: boolean;
|
|
14
|
+
onChange?: (page: number) => void;
|
|
15
|
+
};
|
|
16
|
+
declare const computedRange: (start: number, end: number) => number[];
|
|
17
|
+
declare const usePagination: ({ page, defaultPage, total, siblings, boundaries, isDisabled, ...rest }: UsePaginationProps) => {
|
|
18
|
+
currentPage: number;
|
|
19
|
+
total: number;
|
|
20
|
+
isDisabled: boolean;
|
|
21
|
+
onFirst: () => void;
|
|
22
|
+
onLast: () => void;
|
|
23
|
+
onPrev: () => void;
|
|
24
|
+
onNext: () => void;
|
|
25
|
+
onChange: (page: number) => void;
|
|
26
|
+
range: (number | "dots")[];
|
|
27
|
+
};
|
|
28
|
+
type UsePaginationReturn = ReturnType<typeof usePagination>;
|
|
29
|
+
|
|
30
|
+
export { PaginationProvider, UsePaginationProps, UsePaginationReturn, computedRange, usePagination, usePaginationContext };
|