@algorithm-shift/design-system 1.2.46 → 1.2.48
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/index.css +3 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +24 -9
- package/dist/index.d.ts +24 -9
- package/dist/index.js +84 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +84 -36
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1855,6 +1855,9 @@ var TextInputGroup = ({ className, style, prepend, append, ...props }) => {
|
|
|
1855
1855
|
};
|
|
1856
1856
|
var TextInputGroup_default = TextInputGroup;
|
|
1857
1857
|
|
|
1858
|
+
// src/components/DataDisplay/Table/Table.tsx
|
|
1859
|
+
import { useState as useState3, useEffect as useEffect2 } from "react";
|
|
1860
|
+
|
|
1858
1861
|
// src/components/ui/data-table.tsx
|
|
1859
1862
|
import {
|
|
1860
1863
|
flexRender,
|
|
@@ -2127,7 +2130,8 @@ var CustomPagination = ({
|
|
|
2127
2130
|
totalPages,
|
|
2128
2131
|
currentPage,
|
|
2129
2132
|
onPageChange,
|
|
2130
|
-
maxVisiblePages = 5
|
|
2133
|
+
maxVisiblePages = 5,
|
|
2134
|
+
perPage
|
|
2131
2135
|
}) => {
|
|
2132
2136
|
const getPageNumbers = () => {
|
|
2133
2137
|
const pages = [];
|
|
@@ -2160,40 +2164,65 @@ var CustomPagination = ({
|
|
|
2160
2164
|
};
|
|
2161
2165
|
const handlePageChange = (page) => {
|
|
2162
2166
|
if (page >= 1 && page <= totalPages && page !== currentPage) {
|
|
2163
|
-
onPageChange(
|
|
2167
|
+
onPageChange({
|
|
2168
|
+
page,
|
|
2169
|
+
itemsPerPage: perPage
|
|
2170
|
+
});
|
|
2164
2171
|
}
|
|
2165
2172
|
};
|
|
2166
2173
|
const pageNumbers = getPageNumbers();
|
|
2167
|
-
return /* @__PURE__ */
|
|
2168
|
-
/* @__PURE__ */
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2174
|
+
return /* @__PURE__ */ jsxs26("div", { className: "flex flex-col gap-4 items-center", children: [
|
|
2175
|
+
/* @__PURE__ */ jsxs26("div", { className: "flex items-center gap-2", children: [
|
|
2176
|
+
/* @__PURE__ */ jsx43("span", { className: "text-sm text-muted-foreground", children: "Items per page:" }),
|
|
2177
|
+
/* @__PURE__ */ jsxs26(
|
|
2178
|
+
Select,
|
|
2179
|
+
{
|
|
2180
|
+
value: String(perPage),
|
|
2181
|
+
onValueChange: (value) => {
|
|
2182
|
+
onPageChange({ page: 1, itemsPerPage: Number(value) });
|
|
2183
|
+
},
|
|
2184
|
+
children: [
|
|
2185
|
+
/* @__PURE__ */ jsx43(SelectTrigger, { className: "w-[100px]", children: /* @__PURE__ */ jsx43(SelectValue, { placeholder: "Select" }) }),
|
|
2186
|
+
/* @__PURE__ */ jsxs26(SelectContent, { children: [
|
|
2187
|
+
/* @__PURE__ */ jsx43(SelectItem, { value: "5", children: "5" }),
|
|
2188
|
+
/* @__PURE__ */ jsx43(SelectItem, { value: "10", children: "10" }),
|
|
2189
|
+
/* @__PURE__ */ jsx43(SelectItem, { value: "20", children: "20" }),
|
|
2190
|
+
/* @__PURE__ */ jsx43(SelectItem, { value: "50", children: "50" })
|
|
2191
|
+
] })
|
|
2192
|
+
]
|
|
2193
|
+
}
|
|
2194
|
+
)
|
|
2195
|
+
] }),
|
|
2196
|
+
/* @__PURE__ */ jsx43(Pagination, { children: /* @__PURE__ */ jsxs26(PaginationContent, { children: [
|
|
2197
|
+
/* @__PURE__ */ jsx43(PaginationItem, { children: /* @__PURE__ */ jsx43(
|
|
2198
|
+
PaginationPrevious,
|
|
2199
|
+
{
|
|
2200
|
+
onClick: () => handlePageChange(currentPage - 1),
|
|
2201
|
+
className: currentPage === 1 ? "pointer-events-none opacity-50" : "cursor-pointer"
|
|
2202
|
+
}
|
|
2203
|
+
) }),
|
|
2204
|
+
pageNumbers.map((pageNumber, index) => /* @__PURE__ */ jsx43(PaginationItem, { children: pageNumber === "..." ? /* @__PURE__ */ jsx43(PaginationEllipsis, {}) : /* @__PURE__ */ jsx43(
|
|
2205
|
+
PaginationLink,
|
|
2206
|
+
{
|
|
2207
|
+
onClick: () => handlePageChange(pageNumber),
|
|
2208
|
+
isActive: currentPage === pageNumber,
|
|
2209
|
+
className: "cursor-pointer",
|
|
2210
|
+
children: pageNumber
|
|
2211
|
+
}
|
|
2212
|
+
) }, index)),
|
|
2213
|
+
/* @__PURE__ */ jsx43(PaginationItem, { children: /* @__PURE__ */ jsx43(
|
|
2214
|
+
PaginationNext,
|
|
2215
|
+
{
|
|
2216
|
+
onClick: () => handlePageChange(currentPage + 1),
|
|
2217
|
+
className: currentPage === totalPages ? "pointer-events-none opacity-50" : "cursor-pointer"
|
|
2218
|
+
}
|
|
2219
|
+
) })
|
|
2220
|
+
] }) })
|
|
2221
|
+
] });
|
|
2192
2222
|
};
|
|
2193
2223
|
var Pagination_default = CustomPagination;
|
|
2194
2224
|
|
|
2195
2225
|
// src/components/DataDisplay/Table/Table.tsx
|
|
2196
|
-
import { useState as useState3 } from "react";
|
|
2197
2226
|
import { jsx as jsx44, jsxs as jsxs27 } from "react/jsx-runtime";
|
|
2198
2227
|
var Table2 = ({
|
|
2199
2228
|
columns,
|
|
@@ -2202,23 +2231,41 @@ var Table2 = ({
|
|
|
2202
2231
|
className,
|
|
2203
2232
|
style,
|
|
2204
2233
|
pagination = false,
|
|
2234
|
+
paginationMode = "client",
|
|
2205
2235
|
itemsPerPage = 10,
|
|
2206
2236
|
onPageChange,
|
|
2237
|
+
page,
|
|
2207
2238
|
loading = false,
|
|
2208
2239
|
totalRecords = 0,
|
|
2209
2240
|
...props
|
|
2210
2241
|
}) => {
|
|
2242
|
+
const [perPage, setPerPage] = useState3(itemsPerPage);
|
|
2211
2243
|
const rawColumns = Array.isArray(columns) ? columns : [];
|
|
2212
2244
|
const rawData = Array.isArray(data) ? data : [];
|
|
2213
2245
|
const rawRowActions = Array.isArray(rowActions) ? rowActions : [];
|
|
2214
|
-
const
|
|
2215
|
-
const
|
|
2216
|
-
const
|
|
2217
|
-
|
|
2218
|
-
|
|
2246
|
+
const isControlled = typeof page === "number";
|
|
2247
|
+
const [internalPage, setInternalPage] = useState3(1);
|
|
2248
|
+
const currentPage = isControlled ? page : internalPage;
|
|
2249
|
+
useEffect2(() => {
|
|
2250
|
+
if (isControlled) return;
|
|
2251
|
+
if (currentPage > 1 && !pagination) setInternalPage(1);
|
|
2252
|
+
}, [pagination, isControlled]);
|
|
2253
|
+
const enablePagination = pagination && (paginationMode === "server" ? totalRecords > perPage : rawData.length > perPage);
|
|
2254
|
+
const handlePageChange = ({ page: page2, itemsPerPage: itemsPerPage2 }) => {
|
|
2255
|
+
if (!isControlled) setInternalPage(page2);
|
|
2256
|
+
onPageChange?.({ page: page2, itemsPerPage: itemsPerPage2 });
|
|
2219
2257
|
};
|
|
2220
|
-
const paginatedData = enablePagination ? rawData
|
|
2221
|
-
|
|
2258
|
+
const paginatedData = !enablePagination ? rawData : paginationMode === "server" ? rawData : rawData.slice(
|
|
2259
|
+
(currentPage - 1) * perPage,
|
|
2260
|
+
currentPage * perPage
|
|
2261
|
+
);
|
|
2262
|
+
const totalPages = enablePagination ? Math.max(
|
|
2263
|
+
1,
|
|
2264
|
+
Math.ceil(
|
|
2265
|
+
(paginationMode === "server" ? totalRecords : rawData.length) / perPage
|
|
2266
|
+
)
|
|
2267
|
+
) : 1;
|
|
2268
|
+
return /* @__PURE__ */ jsxs27("div", { className: `${className || ""} space-y-3`, style, children: [
|
|
2222
2269
|
/* @__PURE__ */ jsx44(
|
|
2223
2270
|
DataTable,
|
|
2224
2271
|
{
|
|
@@ -2232,7 +2279,8 @@ var Table2 = ({
|
|
|
2232
2279
|
enablePagination && /* @__PURE__ */ jsx44(
|
|
2233
2280
|
Pagination_default,
|
|
2234
2281
|
{
|
|
2235
|
-
|
|
2282
|
+
perPage,
|
|
2283
|
+
totalPages,
|
|
2236
2284
|
currentPage,
|
|
2237
2285
|
onPageChange: handlePageChange
|
|
2238
2286
|
}
|