@martinsura/ui 0.1.7 → 0.1.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 +16 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +16 -13
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -1745,10 +1745,13 @@ var Pagination = ({ current, pageSize, total, onChange, showPageNumberChanger, s
|
|
|
1745
1745
|
};
|
|
1746
1746
|
var Grid = (props) => {
|
|
1747
1747
|
const { grid } = props;
|
|
1748
|
+
const items = props.items ?? [];
|
|
1749
|
+
const totalCount = props.totalCount ?? 0;
|
|
1750
|
+
const loading = props.loading ?? false;
|
|
1748
1751
|
const sc = tableSizeConfig[props.size ?? "middle"];
|
|
1749
1752
|
const verticalBorders = props.verticalBorders ?? false;
|
|
1750
|
-
const isInitialLoading =
|
|
1751
|
-
const isEmpty = !
|
|
1753
|
+
const isInitialLoading = loading && items.length === 0;
|
|
1754
|
+
const isEmpty = !loading && items.length === 0;
|
|
1752
1755
|
const handleSort = (col) => {
|
|
1753
1756
|
if (col.sortBy === void 0) return;
|
|
1754
1757
|
const isCurrent = grid.sortBy === col.sortBy;
|
|
@@ -1757,20 +1760,20 @@ var Grid = (props) => {
|
|
|
1757
1760
|
direction: isCurrent && grid.direction === SortDirection.Asc ? SortDirection.Desc : SortDirection.Asc
|
|
1758
1761
|
});
|
|
1759
1762
|
};
|
|
1760
|
-
|
|
1763
|
+
items.map((item) => getKey2(item, items, props.rowKey));
|
|
1761
1764
|
const selectedKeys = new Set(
|
|
1762
|
-
(props.selection?.selectedItems ?? []).map((item) => getKey2(item,
|
|
1765
|
+
(props.selection?.selectedItems ?? []).map((item) => getKey2(item, items, props.rowKey))
|
|
1763
1766
|
);
|
|
1764
|
-
const allSelected =
|
|
1765
|
-
const someSelected = !allSelected &&
|
|
1767
|
+
const allSelected = items.length > 0 && items.every((item) => selectedKeys.has(getKey2(item, items, props.rowKey)));
|
|
1768
|
+
const someSelected = !allSelected && items.some((item) => selectedKeys.has(getKey2(item, items, props.rowKey)));
|
|
1766
1769
|
const toggleAll = () => {
|
|
1767
1770
|
if (!props.selection) return;
|
|
1768
|
-
props.selection.onChange(allSelected ? [] : [...
|
|
1771
|
+
props.selection.onChange(allSelected ? [] : [...items]);
|
|
1769
1772
|
};
|
|
1770
1773
|
const toggleRow = (item) => {
|
|
1771
1774
|
if (!props.selection) return;
|
|
1772
|
-
const key = getKey2(item,
|
|
1773
|
-
const next = selectedKeys.has(key) ? props.selection.selectedItems.filter((s) => getKey2(s,
|
|
1775
|
+
const key = getKey2(item, items, props.rowKey);
|
|
1776
|
+
const next = selectedKeys.has(key) ? props.selection.selectedItems.filter((s) => getKey2(s, items, props.rowKey) !== key) : [...props.selection.selectedItems, item];
|
|
1774
1777
|
props.selection.onChange(next);
|
|
1775
1778
|
};
|
|
1776
1779
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
@@ -1782,7 +1785,7 @@ var Grid = (props) => {
|
|
|
1782
1785
|
props.className
|
|
1783
1786
|
),
|
|
1784
1787
|
children: [
|
|
1785
|
-
|
|
1788
|
+
loading && !isInitialLoading && /* @__PURE__ */ jsxRuntime.jsx("div", { className: tailwindMerge.twMerge("absolute inset-0 z-10 bg-white/60 flex items-center justify-center", props.classNames?.overlay), children: /* @__PURE__ */ jsxRuntime.jsx(Spinner, { size: "large", color: "primary" }) }),
|
|
1786
1789
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-x-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: tailwindMerge.twMerge("w-full border-collapse", props.classNames?.table), children: [
|
|
1787
1790
|
/* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { className: tailwindMerge.twMerge("bg-(--ui-primary) text-(--ui-primary-text)", props.classNames?.headerRow), children: [
|
|
1788
1791
|
props.selection && /* @__PURE__ */ jsxRuntime.jsx("th", { className: tailwindMerge.twMerge(sc.th, "w-9", verticalBorders && tableHeaderVerticalBorderClass, props.classNames?.headerCell), children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -1837,8 +1840,8 @@ var Grid = (props) => {
|
|
|
1837
1840
|
className: tailwindMerge.twMerge("px-3", props.classNames?.emptyCell),
|
|
1838
1841
|
children: /* @__PURE__ */ jsxRuntime.jsx(Empty, { size: "compact", text: props.emptyText ?? "\u017D\xE1dn\xE9 z\xE1znamy", className: sc.emptyPy })
|
|
1839
1842
|
}
|
|
1840
|
-
) }) :
|
|
1841
|
-
const key = getKey2(item,
|
|
1843
|
+
) }) : items.map((item, rowIdx) => {
|
|
1844
|
+
const key = getKey2(item, items, props.rowKey);
|
|
1842
1845
|
const isSelected = selectedKeys.has(key);
|
|
1843
1846
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1844
1847
|
"tr",
|
|
@@ -1912,7 +1915,7 @@ var Grid = (props) => {
|
|
|
1912
1915
|
{
|
|
1913
1916
|
current: grid.pageNumber,
|
|
1914
1917
|
pageSize: grid.pageSize,
|
|
1915
|
-
total:
|
|
1918
|
+
total: totalCount,
|
|
1916
1919
|
showPageNumberChanger: props.showPageNumberChanger ?? false,
|
|
1917
1920
|
showPageSizeChanger: props.showPageSizeChanger ?? false,
|
|
1918
1921
|
onChange: (page, pageSize) => grid.onChange({ pageNumber: page, pageSize }),
|