achery-ui 0.5.7 → 0.5.9

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.cjs CHANGED
@@ -1013,7 +1013,13 @@ function AppBar({
1013
1013
 
1014
1014
  // src/components/Table/Table.css.ts
1015
1015
  var emptyState = "Table_emptyState__1a2tbysb";
1016
+ var pageButton = "Table_pageButton__1a2tbyse";
1017
+ var pageButtonActive = "Table_pageButtonActive__1a2tbysg Table_pageButton__1a2tbyse";
1018
+ var pageNavButton = "Table_pageNavButton__1a2tbysf Table_pageButton__1a2tbyse";
1019
+ var pageSizeSelect = "Table_pageSizeSelect__1a2tbysi";
1016
1020
  var pagination = "Table_pagination__1a2tbysc";
1021
+ var paginationControls = "Table_paginationControls__1a2tbysd";
1022
+ var paginationEllipsis = "Table_paginationEllipsis__1a2tbysh";
1017
1023
  var sortIndicator = "Table_sortIndicator__1a2tbys6";
1018
1024
  var table = "Table_table__1a2tbys2";
1019
1025
  var tableScroll = "Table_tableScroll__1a2tbys1";
@@ -1025,6 +1031,22 @@ var thSortable = "Table_thSortable__1a2tbys5 Table_th__1a2tbys4";
1025
1031
  var thead = "Table_thead__1a2tbys3";
1026
1032
  var toolbar = "Table_toolbar__1a2tbysa";
1027
1033
  var tr = "Table_tr__1a2tbys7";
1034
+ function buildPageWindow(current, total, window2) {
1035
+ const pages = /* @__PURE__ */ new Set();
1036
+ pages.add(0);
1037
+ pages.add(total - 1);
1038
+ for (let i = Math.max(0, current - window2); i <= Math.min(total - 1, current + window2); i++) {
1039
+ pages.add(i);
1040
+ }
1041
+ const sorted = Array.from(pages).sort((a, b) => a - b);
1042
+ const result = [];
1043
+ for (let i = 0; i < sorted.length; i++) {
1044
+ const page = sorted[i];
1045
+ if (i > 0 && page - sorted[i - 1] > 1) result.push(null);
1046
+ result.push(page);
1047
+ }
1048
+ return result;
1049
+ }
1028
1050
  function Table({
1029
1051
  columns,
1030
1052
  data,
@@ -1040,6 +1062,10 @@ function Table({
1040
1062
  pageSize,
1041
1063
  totalRows,
1042
1064
  onPageChange,
1065
+ onPageSizeChange,
1066
+ pageSizeOptions,
1067
+ paginationWindow = 2,
1068
+ height,
1043
1069
  toolbar: toolbar2,
1044
1070
  emptyState: emptyState2,
1045
1071
  className
@@ -1075,78 +1101,88 @@ function Table({
1075
1101
  const totalPages = pageSize && totalRows ? Math.ceil(totalRows / pageSize) : null;
1076
1102
  const isFirstPage = pageIndex === 0;
1077
1103
  const isLastPage = totalPages !== null ? pageIndex >= totalPages - 1 : true;
1078
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: [tableWrapper, className].filter(Boolean).join(" "), children: [
1079
- toolbar2 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: toolbar, children: toolbar2 }),
1080
- /* @__PURE__ */ jsxRuntime.jsx(
1081
- "div",
1082
- {
1083
- className: tableScroll,
1084
- style: pageSize ? { minHeight: 37 + pageSize * 38 } : void 0,
1085
- children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: table, children: [
1086
- /* @__PURE__ */ jsxRuntime.jsx("thead", { className: thead, children: /* @__PURE__ */ jsxRuntime.jsx("tr", { children: columns.map((col) => /* @__PURE__ */ jsxRuntime.jsxs(
1087
- "th",
1104
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1105
+ "div",
1106
+ {
1107
+ className: [tableWrapper, className].filter(Boolean).join(" "),
1108
+ style: height ? { height, display: "flex", flexDirection: "column" } : void 0,
1109
+ children: [
1110
+ toolbar2 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: toolbar, children: toolbar2 }),
1111
+ /* @__PURE__ */ jsxRuntime.jsx(
1112
+ "div",
1113
+ {
1114
+ className: tableScroll,
1115
+ style: height ? { flex: 1, overflowY: "auto", minHeight: 0 } : pageSize ? { minHeight: 37 + pageSize * 38 } : void 0,
1116
+ children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: table, children: [
1117
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { className: thead, children: /* @__PURE__ */ jsxRuntime.jsx("tr", { children: columns.map((col) => /* @__PURE__ */ jsxRuntime.jsxs(
1118
+ "th",
1119
+ {
1120
+ className: col.sortable ? thSortable : th,
1121
+ style: col.width ? { width: col.width } : void 0,
1122
+ onClick: col.sortable ? () => handleSort(col.key) : void 0,
1123
+ "aria-sort": activeSortKey === col.key ? activeSortDir === "asc" ? "ascending" : "descending" : void 0,
1124
+ children: [
1125
+ col.label,
1126
+ col.sortable && activeSortKey === col.key && activeSortDir && /* @__PURE__ */ jsxRuntime.jsx("span", { className: sortIndicator, "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx(Glyph, { name: activeSortDir === "asc" ? "arrow-up" : "arrow-right", size: 10 }) })
1127
+ ]
1128
+ },
1129
+ col.key
1130
+ )) }) }),
1131
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: data.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("tr", { children: /* @__PURE__ */ jsxRuntime.jsx("td", { colSpan: columns.length, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: emptyState, children: emptyState2 ?? "No data." }) }) }) : sortedData.map((row) => {
1132
+ const key = rowKey(row);
1133
+ const isSelected = selectedKeys?.includes(key) ?? false;
1134
+ return /* @__PURE__ */ jsxRuntime.jsx(
1135
+ "tr",
1136
+ {
1137
+ className: tr,
1138
+ "data-selected": isSelected,
1139
+ onClick: onRowClick ? () => onRowClick(key, row) : void 0,
1140
+ style: onRowClick ? { cursor: "pointer" } : void 0,
1141
+ children: columns.map((col) => /* @__PURE__ */ jsxRuntime.jsx("td", { className: col.mono ? tdMono : td, children: col.render ? col.render(row) : String(row[col.key] ?? "") }, col.key))
1142
+ },
1143
+ key
1144
+ );
1145
+ }) })
1146
+ ] })
1147
+ }
1148
+ ),
1149
+ pageSize && totalPages !== null && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: pagination, children: [
1150
+ pageSizeOptions && /* @__PURE__ */ jsxRuntime.jsx(
1151
+ "select",
1088
1152
  {
1089
- className: col.sortable ? thSortable : th,
1090
- style: col.width ? { width: col.width } : void 0,
1091
- onClick: col.sortable ? () => handleSort(col.key) : void 0,
1092
- "aria-sort": activeSortKey === col.key ? activeSortDir === "asc" ? "ascending" : "descending" : void 0,
1093
- children: [
1094
- col.label,
1095
- col.sortable && activeSortKey === col.key && activeSortDir && /* @__PURE__ */ jsxRuntime.jsx("span", { className: sortIndicator, "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx(Glyph, { name: activeSortDir === "asc" ? "arrow-up" : "arrow-right", size: 10 }) })
1096
- ]
1097
- },
1098
- col.key
1099
- )) }) }),
1100
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: data.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("tr", { children: /* @__PURE__ */ jsxRuntime.jsx("td", { colSpan: columns.length, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: emptyState, children: emptyState2 ?? "No data." }) }) }) : sortedData.map((row) => {
1101
- const key = rowKey(row);
1102
- const isSelected = selectedKeys?.includes(key) ?? false;
1103
- return /* @__PURE__ */ jsxRuntime.jsx(
1104
- "tr",
1105
- {
1106
- className: tr,
1107
- "data-selected": isSelected,
1108
- onClick: onRowClick ? () => onRowClick(key, row) : void 0,
1109
- style: onRowClick ? { cursor: "pointer" } : void 0,
1110
- children: columns.map((col) => /* @__PURE__ */ jsxRuntime.jsx("td", { className: col.mono ? tdMono : td, children: col.render ? col.render(row) : String(row[col.key] ?? "") }, col.key))
1111
- },
1112
- key
1113
- );
1114
- }) })
1153
+ className: pageSizeSelect,
1154
+ value: pageSize,
1155
+ onChange: (e) => onPageSizeChange?.(Number(e.target.value)),
1156
+ "aria-label": "Rows per page",
1157
+ children: pageSizeOptions.map((n) => /* @__PURE__ */ jsxRuntime.jsxs("option", { value: n, children: [
1158
+ n,
1159
+ " / page"
1160
+ ] }, n))
1161
+ }
1162
+ ),
1163
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: paginationControls, children: [
1164
+ /* @__PURE__ */ jsxRuntime.jsx("button", { className: pageNavButton, onClick: () => onPageChange?.(0), disabled: isFirstPage, "aria-label": "First page", children: "\xAB" }),
1165
+ /* @__PURE__ */ jsxRuntime.jsx("button", { className: pageNavButton, onClick: () => onPageChange?.(pageIndex - 1), disabled: isFirstPage, "aria-label": "Previous page", children: "\u2039" }),
1166
+ buildPageWindow(pageIndex, totalPages, paginationWindow).map(
1167
+ (entry, i) => entry === null ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: paginationEllipsis, children: "\u2026" }, `ellipsis-${i}`) : /* @__PURE__ */ jsxRuntime.jsx(
1168
+ "button",
1169
+ {
1170
+ className: entry === pageIndex ? pageButtonActive : pageButton,
1171
+ onClick: () => onPageChange?.(entry),
1172
+ "aria-label": `Page ${entry + 1}`,
1173
+ "aria-current": entry === pageIndex ? "page" : void 0,
1174
+ children: entry + 1
1175
+ },
1176
+ entry
1177
+ )
1178
+ ),
1179
+ /* @__PURE__ */ jsxRuntime.jsx("button", { className: pageNavButton, onClick: () => onPageChange?.(pageIndex + 1), disabled: isLastPage, "aria-label": "Next page", children: "\u203A" }),
1180
+ /* @__PURE__ */ jsxRuntime.jsx("button", { className: pageNavButton, onClick: () => onPageChange?.(totalPages - 1), disabled: isLastPage, "aria-label": "Last page", children: "\xBB" })
1181
+ ] })
1115
1182
  ] })
1116
- }
1117
- ),
1118
- pageSize && totalPages !== null && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: pagination, children: [
1119
- /* @__PURE__ */ jsxRuntime.jsx(
1120
- Button,
1121
- {
1122
- variant: "ghost",
1123
- size: "sm",
1124
- glyph: "arrow-right",
1125
- onClick: () => onPageChange?.(pageIndex - 1),
1126
- disabled: isFirstPage,
1127
- "aria-label": "Previous page",
1128
- style: { transform: "rotate(180deg)" }
1129
- }
1130
- ),
1131
- /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
1132
- "Page ",
1133
- pageIndex + 1,
1134
- " of ",
1135
- totalPages
1136
- ] }),
1137
- /* @__PURE__ */ jsxRuntime.jsx(
1138
- Button,
1139
- {
1140
- variant: "ghost",
1141
- size: "sm",
1142
- glyph: "arrow-right",
1143
- onClick: () => onPageChange?.(pageIndex + 1),
1144
- disabled: isLastPage,
1145
- "aria-label": "Next page"
1146
- }
1147
- )
1148
- ] })
1149
- ] });
1183
+ ]
1184
+ }
1185
+ );
1150
1186
  }
1151
1187
  var body2 = "Modal_body__1kcb5si8";
1152
1188
  var bodyScrollable = "Modal_bodyScrollable__1kcb5sie";