achery-ui 0.5.6 → 0.5.8

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
@@ -1012,18 +1012,41 @@ function AppBar({
1012
1012
  }
1013
1013
 
1014
1014
  // src/components/Table/Table.css.ts
1015
- var emptyState = "Table_emptyState__1a2tbysa";
1016
- var pagination = "Table_pagination__1a2tbysb";
1017
- var sortIndicator = "Table_sortIndicator__1a2tbys5";
1018
- var table = "Table_table__1a2tbys1";
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";
1020
+ var pagination = "Table_pagination__1a2tbysc";
1021
+ var paginationControls = "Table_paginationControls__1a2tbysd";
1022
+ var paginationEllipsis = "Table_paginationEllipsis__1a2tbysh";
1023
+ var sortIndicator = "Table_sortIndicator__1a2tbys6";
1024
+ var table = "Table_table__1a2tbys2";
1025
+ var tableScroll = "Table_tableScroll__1a2tbys1";
1019
1026
  var tableWrapper = "Table_tableWrapper__1a2tbys0";
1020
- var td = "Table_td__1a2tbys7";
1021
- var tdMono = "Table_tdMono__1a2tbys8 Table_td__1a2tbys7";
1022
- var th = "Table_th__1a2tbys3";
1023
- var thSortable = "Table_thSortable__1a2tbys4 Table_th__1a2tbys3";
1024
- var thead = "Table_thead__1a2tbys2";
1025
- var toolbar = "Table_toolbar__1a2tbys9";
1026
- var tr = "Table_tr__1a2tbys6";
1027
+ var td = "Table_td__1a2tbys8";
1028
+ var tdMono = "Table_tdMono__1a2tbys9 Table_td__1a2tbys8";
1029
+ var th = "Table_th__1a2tbys4";
1030
+ var thSortable = "Table_thSortable__1a2tbys5 Table_th__1a2tbys4";
1031
+ var thead = "Table_thead__1a2tbys3";
1032
+ var toolbar = "Table_toolbar__1a2tbysa";
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
+ }
1027
1050
  function Table({
1028
1051
  columns,
1029
1052
  data,
@@ -1039,6 +1062,9 @@ function Table({
1039
1062
  pageSize,
1040
1063
  totalRows,
1041
1064
  onPageChange,
1065
+ onPageSizeChange,
1066
+ pageSizeOptions,
1067
+ paginationWindow = 2,
1042
1068
  toolbar: toolbar2,
1043
1069
  emptyState: emptyState2,
1044
1070
  className
@@ -1076,67 +1102,77 @@ function Table({
1076
1102
  const isLastPage = totalPages !== null ? pageIndex >= totalPages - 1 : true;
1077
1103
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: [tableWrapper, className].filter(Boolean).join(" "), children: [
1078
1104
  toolbar2 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: toolbar, children: toolbar2 }),
1079
- /* @__PURE__ */ jsxRuntime.jsxs("table", { className: table, children: [
1080
- /* @__PURE__ */ jsxRuntime.jsx("thead", { className: thead, children: /* @__PURE__ */ jsxRuntime.jsx("tr", { children: columns.map((col) => /* @__PURE__ */ jsxRuntime.jsxs(
1081
- "th",
1082
- {
1083
- className: col.sortable ? thSortable : th,
1084
- style: col.width ? { width: col.width } : void 0,
1085
- onClick: col.sortable ? () => handleSort(col.key) : void 0,
1086
- "aria-sort": activeSortKey === col.key ? activeSortDir === "asc" ? "ascending" : "descending" : void 0,
1087
- children: [
1088
- col.label,
1089
- 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 }) })
1090
- ]
1091
- },
1092
- col.key
1093
- )) }) }),
1094
- /* @__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) => {
1095
- const key = rowKey(row);
1096
- const isSelected = selectedKeys?.includes(key) ?? false;
1097
- return /* @__PURE__ */ jsxRuntime.jsx(
1098
- "tr",
1099
- {
1100
- className: tr,
1101
- "data-selected": isSelected,
1102
- onClick: onRowClick ? () => onRowClick(key, row) : void 0,
1103
- style: onRowClick ? { cursor: "pointer" } : void 0,
1104
- 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))
1105
- },
1106
- key
1107
- );
1108
- }) })
1109
- ] }),
1105
+ /* @__PURE__ */ jsxRuntime.jsx(
1106
+ "div",
1107
+ {
1108
+ className: tableScroll,
1109
+ style: pageSize ? { minHeight: 37 + pageSize * 38 } : void 0,
1110
+ children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: table, children: [
1111
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { className: thead, children: /* @__PURE__ */ jsxRuntime.jsx("tr", { children: columns.map((col) => /* @__PURE__ */ jsxRuntime.jsxs(
1112
+ "th",
1113
+ {
1114
+ className: col.sortable ? thSortable : th,
1115
+ style: col.width ? { width: col.width } : void 0,
1116
+ onClick: col.sortable ? () => handleSort(col.key) : void 0,
1117
+ "aria-sort": activeSortKey === col.key ? activeSortDir === "asc" ? "ascending" : "descending" : void 0,
1118
+ children: [
1119
+ col.label,
1120
+ 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 }) })
1121
+ ]
1122
+ },
1123
+ col.key
1124
+ )) }) }),
1125
+ /* @__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) => {
1126
+ const key = rowKey(row);
1127
+ const isSelected = selectedKeys?.includes(key) ?? false;
1128
+ return /* @__PURE__ */ jsxRuntime.jsx(
1129
+ "tr",
1130
+ {
1131
+ className: tr,
1132
+ "data-selected": isSelected,
1133
+ onClick: onRowClick ? () => onRowClick(key, row) : void 0,
1134
+ style: onRowClick ? { cursor: "pointer" } : void 0,
1135
+ 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))
1136
+ },
1137
+ key
1138
+ );
1139
+ }) })
1140
+ ] })
1141
+ }
1142
+ ),
1110
1143
  pageSize && totalPages !== null && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: pagination, children: [
1111
- /* @__PURE__ */ jsxRuntime.jsx(
1112
- Button,
1144
+ pageSizeOptions && /* @__PURE__ */ jsxRuntime.jsx(
1145
+ "select",
1113
1146
  {
1114
- variant: "ghost",
1115
- size: "sm",
1116
- glyph: "arrow-right",
1117
- onClick: () => onPageChange?.(pageIndex - 1),
1118
- disabled: isFirstPage,
1119
- "aria-label": "Previous page",
1120
- style: { transform: "rotate(180deg)" }
1147
+ className: pageSizeSelect,
1148
+ value: pageSize,
1149
+ onChange: (e) => onPageSizeChange?.(Number(e.target.value)),
1150
+ "aria-label": "Rows per page",
1151
+ children: pageSizeOptions.map((n) => /* @__PURE__ */ jsxRuntime.jsxs("option", { value: n, children: [
1152
+ n,
1153
+ " / page"
1154
+ ] }, n))
1121
1155
  }
1122
1156
  ),
1123
- /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
1124
- "Page ",
1125
- pageIndex + 1,
1126
- " of ",
1127
- totalPages
1128
- ] }),
1129
- /* @__PURE__ */ jsxRuntime.jsx(
1130
- Button,
1131
- {
1132
- variant: "ghost",
1133
- size: "sm",
1134
- glyph: "arrow-right",
1135
- onClick: () => onPageChange?.(pageIndex + 1),
1136
- disabled: isLastPage,
1137
- "aria-label": "Next page"
1138
- }
1139
- )
1157
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: paginationControls, children: [
1158
+ /* @__PURE__ */ jsxRuntime.jsx("button", { className: pageNavButton, onClick: () => onPageChange?.(0), disabled: isFirstPage, "aria-label": "First page", children: "\xAB" }),
1159
+ /* @__PURE__ */ jsxRuntime.jsx("button", { className: pageNavButton, onClick: () => onPageChange?.(pageIndex - 1), disabled: isFirstPage, "aria-label": "Previous page", children: "\u2039" }),
1160
+ buildPageWindow(pageIndex, totalPages, paginationWindow).map(
1161
+ (entry, i) => entry === null ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: paginationEllipsis, children: "\u2026" }, `ellipsis-${i}`) : /* @__PURE__ */ jsxRuntime.jsx(
1162
+ "button",
1163
+ {
1164
+ className: entry === pageIndex ? pageButtonActive : pageButton,
1165
+ onClick: () => onPageChange?.(entry),
1166
+ "aria-label": `Page ${entry + 1}`,
1167
+ "aria-current": entry === pageIndex ? "page" : void 0,
1168
+ children: entry + 1
1169
+ },
1170
+ entry
1171
+ )
1172
+ ),
1173
+ /* @__PURE__ */ jsxRuntime.jsx("button", { className: pageNavButton, onClick: () => onPageChange?.(pageIndex + 1), disabled: isLastPage, "aria-label": "Next page", children: "\u203A" }),
1174
+ /* @__PURE__ */ jsxRuntime.jsx("button", { className: pageNavButton, onClick: () => onPageChange?.(totalPages - 1), disabled: isLastPage, "aria-label": "Last page", children: "\xBB" })
1175
+ ] })
1140
1176
  ] })
1141
1177
  ] });
1142
1178
  }