@classytic/fluid 0.3.4 → 0.4.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/dist/client/core.d.mts +14 -18
- package/dist/client/core.mjs +105 -279
- package/dist/client/hooks.mjs +52 -26
- package/dist/client/table.d.mts +41 -5
- package/dist/client/table.mjs +54 -7
- package/dist/dashboard.d.mts +2 -0
- package/dist/dashboard.mjs +1 -1
- package/dist/dropdown-wrapper-B86u9Fri.mjs +357 -0
- package/dist/forms.mjs +22 -7
- package/package.json +1 -1
- package/dist/api-pagination-DBTE0yk4.mjs +0 -190
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import { t as cn } from "./utils-DQ5SCVoW.mjs";
|
|
2
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useEffect, useState } from "react";
|
|
4
|
-
import { Pagination, PaginationContent, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious } from "@/components/ui/pagination";
|
|
5
|
-
|
|
6
|
-
//#region src/components/custom-pagination.tsx
|
|
7
|
-
function CustomPagination({ page, onPageChange, pages, hasPrev, hasNext }) {
|
|
8
|
-
const [isMobile, setIsMobile] = useState(false);
|
|
9
|
-
const currentPageNum = Number(page);
|
|
10
|
-
useEffect(() => {
|
|
11
|
-
const checkMobile = () => {
|
|
12
|
-
setIsMobile(window.innerWidth < 640);
|
|
13
|
-
};
|
|
14
|
-
checkMobile();
|
|
15
|
-
window.addEventListener("resize", checkMobile);
|
|
16
|
-
return () => window.removeEventListener("resize", checkMobile);
|
|
17
|
-
}, []);
|
|
18
|
-
if (pages <= 1) return null;
|
|
19
|
-
const getPageNumbers = () => {
|
|
20
|
-
const delta = isMobile ? 1 : 2;
|
|
21
|
-
const range = [];
|
|
22
|
-
const rangeWithDots = [];
|
|
23
|
-
for (let i = Math.max(2, currentPageNum - delta); i <= Math.min(pages - 1, currentPageNum + delta); i++) range.push(i);
|
|
24
|
-
if (currentPageNum - delta > 2) rangeWithDots.push(1, "...");
|
|
25
|
-
else rangeWithDots.push(1);
|
|
26
|
-
rangeWithDots.push(...range);
|
|
27
|
-
if (currentPageNum + delta < pages - 1) rangeWithDots.push("...", pages);
|
|
28
|
-
else if (pages > 1) {
|
|
29
|
-
if (!range.includes(pages)) rangeWithDots.push(pages);
|
|
30
|
-
}
|
|
31
|
-
return [...new Set(rangeWithDots)];
|
|
32
|
-
};
|
|
33
|
-
if (isMobile && pages > 5) return /* @__PURE__ */ jsx(Pagination, {
|
|
34
|
-
className: "mx-0 w-auto",
|
|
35
|
-
children: /* @__PURE__ */ jsxs(PaginationContent, {
|
|
36
|
-
className: "gap-1",
|
|
37
|
-
children: [
|
|
38
|
-
/* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationPrevious, {
|
|
39
|
-
onClick: () => hasPrev ? onPageChange(currentPageNum - 1) : void 0,
|
|
40
|
-
className: cn("cursor-pointer transition-colors h-8 px-2 text-xs", !hasPrev && "pointer-events-none opacity-50 cursor-not-allowed", hasPrev && "hover:bg-accent hover:text-accent-foreground"),
|
|
41
|
-
"aria-disabled": !hasPrev
|
|
42
|
-
}) }),
|
|
43
|
-
/* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsxs("div", {
|
|
44
|
-
className: "flex h-8 items-center justify-center px-3 text-xs font-medium bg-primary text-primary-foreground rounded-md",
|
|
45
|
-
children: [
|
|
46
|
-
currentPageNum,
|
|
47
|
-
" / ",
|
|
48
|
-
pages
|
|
49
|
-
]
|
|
50
|
-
}) }),
|
|
51
|
-
/* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationNext, {
|
|
52
|
-
onClick: () => hasNext ? onPageChange(currentPageNum + 1) : void 0,
|
|
53
|
-
className: cn("cursor-pointer transition-colors h-8 px-2 text-xs", !hasNext && "pointer-events-none opacity-50 cursor-not-allowed", hasNext && "hover:bg-accent hover:text-accent-foreground"),
|
|
54
|
-
"aria-disabled": !hasNext
|
|
55
|
-
}) })
|
|
56
|
-
]
|
|
57
|
-
})
|
|
58
|
-
});
|
|
59
|
-
return /* @__PURE__ */ jsx(Pagination, {
|
|
60
|
-
className: "mx-0 w-auto",
|
|
61
|
-
children: /* @__PURE__ */ jsxs(PaginationContent, {
|
|
62
|
-
className: "gap-1 flex-wrap",
|
|
63
|
-
children: [
|
|
64
|
-
/* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationPrevious, {
|
|
65
|
-
onClick: () => hasPrev ? onPageChange(currentPageNum - 1) : void 0,
|
|
66
|
-
className: cn("cursor-pointer transition-colors", isMobile ? "h-8 px-2 text-xs" : "h-9 px-3 text-sm", !hasPrev && "pointer-events-none opacity-50 cursor-not-allowed", hasPrev && "hover:bg-accent hover:text-accent-foreground"),
|
|
67
|
-
"aria-disabled": !hasPrev
|
|
68
|
-
}) }),
|
|
69
|
-
getPageNumbers().map((pageNum, index) => /* @__PURE__ */ jsx(PaginationItem, { children: pageNum === "..." ? /* @__PURE__ */ jsx("span", {
|
|
70
|
-
className: cn("flex items-center justify-center text-muted-foreground", isMobile ? "h-8 w-8 text-xs" : "h-9 w-9 text-sm"),
|
|
71
|
-
children: "..."
|
|
72
|
-
}) : /* @__PURE__ */ jsx(PaginationLink, {
|
|
73
|
-
className: cn("cursor-pointer transition-colors", isMobile ? "h-8 w-8 text-xs p-0" : "h-9 w-9 text-sm p-0", "hover:bg-accent hover:text-accent-foreground", Number(currentPageNum) === Number(pageNum) && "bg-primary text-primary-foreground hover:bg-primary/90"),
|
|
74
|
-
onClick: () => typeof pageNum === "number" ? onPageChange(pageNum) : void 0,
|
|
75
|
-
isActive: Number(currentPageNum) === Number(pageNum),
|
|
76
|
-
"aria-label": `Go to page ${pageNum}`,
|
|
77
|
-
"aria-current": Number(currentPageNum) === Number(pageNum) ? "page" : void 0,
|
|
78
|
-
children: pageNum
|
|
79
|
-
}) }, `pagination-page-${pageNum}-${index}`)),
|
|
80
|
-
/* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationNext, {
|
|
81
|
-
onClick: () => hasNext ? onPageChange(currentPageNum + 1) : void 0,
|
|
82
|
-
className: cn("cursor-pointer transition-colors", isMobile ? "h-8 px-2 text-xs" : "h-9 px-3 text-sm", !hasNext && "pointer-events-none opacity-50 cursor-not-allowed", hasNext && "hover:bg-accent hover:text-accent-foreground"),
|
|
83
|
-
"aria-disabled": !hasNext
|
|
84
|
-
}) })
|
|
85
|
-
]
|
|
86
|
-
})
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
function PaginationInfo({ page, total, limit = 10 }) {
|
|
90
|
-
const [isMobile, setIsMobile] = useState(false);
|
|
91
|
-
useEffect(() => {
|
|
92
|
-
const checkMobile = () => {
|
|
93
|
-
setIsMobile(window.innerWidth < 640);
|
|
94
|
-
};
|
|
95
|
-
checkMobile();
|
|
96
|
-
window.addEventListener("resize", checkMobile);
|
|
97
|
-
return () => window.removeEventListener("resize", checkMobile);
|
|
98
|
-
}, []);
|
|
99
|
-
if (total === 0) return /* @__PURE__ */ jsx("div", {
|
|
100
|
-
className: "flex-1 text-sm text-muted-foreground",
|
|
101
|
-
children: /* @__PURE__ */ jsx("p", { children: "No entries found" })
|
|
102
|
-
});
|
|
103
|
-
const startEntry = (page - 1) * limit + 1;
|
|
104
|
-
const endEntry = Math.min(page * limit, total);
|
|
105
|
-
return /* @__PURE__ */ jsx("div", {
|
|
106
|
-
className: "flex-1 text-sm text-muted-foreground",
|
|
107
|
-
children: /* @__PURE__ */ jsx("p", {
|
|
108
|
-
className: cn("whitespace-nowrap", isMobile && "text-xs"),
|
|
109
|
-
children: isMobile ? /* @__PURE__ */ jsxs("span", { children: [
|
|
110
|
-
startEntry.toLocaleString(),
|
|
111
|
-
"-",
|
|
112
|
-
endEntry.toLocaleString(),
|
|
113
|
-
" of",
|
|
114
|
-
" ",
|
|
115
|
-
total.toLocaleString()
|
|
116
|
-
] }) : /* @__PURE__ */ jsxs("span", { children: [
|
|
117
|
-
"Showing",
|
|
118
|
-
" ",
|
|
119
|
-
/* @__PURE__ */ jsx("span", {
|
|
120
|
-
className: "font-medium text-foreground",
|
|
121
|
-
children: startEntry.toLocaleString()
|
|
122
|
-
}),
|
|
123
|
-
" ",
|
|
124
|
-
"to",
|
|
125
|
-
" ",
|
|
126
|
-
/* @__PURE__ */ jsx("span", {
|
|
127
|
-
className: "font-medium text-foreground",
|
|
128
|
-
children: endEntry.toLocaleString()
|
|
129
|
-
}),
|
|
130
|
-
" ",
|
|
131
|
-
"of",
|
|
132
|
-
" ",
|
|
133
|
-
/* @__PURE__ */ jsx("span", {
|
|
134
|
-
className: "font-medium text-foreground",
|
|
135
|
-
children: total.toLocaleString()
|
|
136
|
-
}),
|
|
137
|
-
" ",
|
|
138
|
-
total === 1 ? "result" : "results"
|
|
139
|
-
] })
|
|
140
|
-
})
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
//#endregion
|
|
145
|
-
//#region src/components/api-pagination.tsx
|
|
146
|
-
/**
|
|
147
|
-
* ApiPagination - A reusable pagination component for API-driven data
|
|
148
|
-
*/
|
|
149
|
-
function ApiPagination({ total = 0, limit = 10, pages = 1, page = 1, hasNext = false, hasPrev = false, onPageChange = () => {}, className, showInfo = true, infoPosition = "left" }) {
|
|
150
|
-
const infoComponent = showInfo && /* @__PURE__ */ jsx("div", {
|
|
151
|
-
className: "shrink-0",
|
|
152
|
-
children: /* @__PURE__ */ jsx(PaginationInfo, {
|
|
153
|
-
total,
|
|
154
|
-
page,
|
|
155
|
-
limit
|
|
156
|
-
})
|
|
157
|
-
});
|
|
158
|
-
const paginationComponent = /* @__PURE__ */ jsx("div", {
|
|
159
|
-
className: "flex justify-center sm:justify-end",
|
|
160
|
-
children: /* @__PURE__ */ jsx(CustomPagination, {
|
|
161
|
-
page,
|
|
162
|
-
pages,
|
|
163
|
-
hasPrev,
|
|
164
|
-
hasNext,
|
|
165
|
-
onPageChange
|
|
166
|
-
})
|
|
167
|
-
});
|
|
168
|
-
return /* @__PURE__ */ jsx("div", {
|
|
169
|
-
className: cn("shrink-0 bg-muted/30 rounded-lg border border-border p-3 mb-2", className),
|
|
170
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
171
|
-
className: "flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4",
|
|
172
|
-
children: infoPosition === "left" ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
|
|
173
|
-
className: "order-2 sm:order-1",
|
|
174
|
-
children: infoComponent
|
|
175
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
176
|
-
className: "order-1 sm:order-2",
|
|
177
|
-
children: paginationComponent
|
|
178
|
-
})] }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
|
|
179
|
-
className: "order-1 sm:order-1",
|
|
180
|
-
children: paginationComponent
|
|
181
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
182
|
-
className: "order-2 sm:order-2",
|
|
183
|
-
children: infoComponent
|
|
184
|
-
})] })
|
|
185
|
-
})
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
//#endregion
|
|
190
|
-
export { CustomPagination as n, PaginationInfo as r, ApiPagination as t };
|