@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.d.cts
CHANGED
|
@@ -400,9 +400,9 @@ type GridSelection<T> = {
|
|
|
400
400
|
onChange: (items: T[]) => void;
|
|
401
401
|
};
|
|
402
402
|
type GridProps<T, TSortField = never, TFilter extends object = Record<string, never>> = {
|
|
403
|
-
items
|
|
404
|
-
totalCount
|
|
405
|
-
loading
|
|
403
|
+
items?: T[] | null;
|
|
404
|
+
totalCount?: number | null;
|
|
405
|
+
loading?: boolean;
|
|
406
406
|
columns: GridColumn<T, TSortField>[];
|
|
407
407
|
grid: GridHandle<TSortField, TFilter>;
|
|
408
408
|
rowKey?: keyof T;
|
package/dist/index.d.ts
CHANGED
|
@@ -400,9 +400,9 @@ type GridSelection<T> = {
|
|
|
400
400
|
onChange: (items: T[]) => void;
|
|
401
401
|
};
|
|
402
402
|
type GridProps<T, TSortField = never, TFilter extends object = Record<string, never>> = {
|
|
403
|
-
items
|
|
404
|
-
totalCount
|
|
405
|
-
loading
|
|
403
|
+
items?: T[] | null;
|
|
404
|
+
totalCount?: number | null;
|
|
405
|
+
loading?: boolean;
|
|
406
406
|
columns: GridColumn<T, TSortField>[];
|
|
407
407
|
grid: GridHandle<TSortField, TFilter>;
|
|
408
408
|
rowKey?: keyof T;
|
package/dist/index.js
CHANGED
|
@@ -1739,10 +1739,13 @@ var Pagination = ({ current, pageSize, total, onChange, showPageNumberChanger, s
|
|
|
1739
1739
|
};
|
|
1740
1740
|
var Grid = (props) => {
|
|
1741
1741
|
const { grid } = props;
|
|
1742
|
+
const items = props.items ?? [];
|
|
1743
|
+
const totalCount = props.totalCount ?? 0;
|
|
1744
|
+
const loading = props.loading ?? false;
|
|
1742
1745
|
const sc = tableSizeConfig[props.size ?? "middle"];
|
|
1743
1746
|
const verticalBorders = props.verticalBorders ?? false;
|
|
1744
|
-
const isInitialLoading =
|
|
1745
|
-
const isEmpty = !
|
|
1747
|
+
const isInitialLoading = loading && items.length === 0;
|
|
1748
|
+
const isEmpty = !loading && items.length === 0;
|
|
1746
1749
|
const handleSort = (col) => {
|
|
1747
1750
|
if (col.sortBy === void 0) return;
|
|
1748
1751
|
const isCurrent = grid.sortBy === col.sortBy;
|
|
@@ -1751,20 +1754,20 @@ var Grid = (props) => {
|
|
|
1751
1754
|
direction: isCurrent && grid.direction === SortDirection.Asc ? SortDirection.Desc : SortDirection.Asc
|
|
1752
1755
|
});
|
|
1753
1756
|
};
|
|
1754
|
-
|
|
1757
|
+
items.map((item) => getKey2(item, items, props.rowKey));
|
|
1755
1758
|
const selectedKeys = new Set(
|
|
1756
|
-
(props.selection?.selectedItems ?? []).map((item) => getKey2(item,
|
|
1759
|
+
(props.selection?.selectedItems ?? []).map((item) => getKey2(item, items, props.rowKey))
|
|
1757
1760
|
);
|
|
1758
|
-
const allSelected =
|
|
1759
|
-
const someSelected = !allSelected &&
|
|
1761
|
+
const allSelected = items.length > 0 && items.every((item) => selectedKeys.has(getKey2(item, items, props.rowKey)));
|
|
1762
|
+
const someSelected = !allSelected && items.some((item) => selectedKeys.has(getKey2(item, items, props.rowKey)));
|
|
1760
1763
|
const toggleAll = () => {
|
|
1761
1764
|
if (!props.selection) return;
|
|
1762
|
-
props.selection.onChange(allSelected ? [] : [...
|
|
1765
|
+
props.selection.onChange(allSelected ? [] : [...items]);
|
|
1763
1766
|
};
|
|
1764
1767
|
const toggleRow = (item) => {
|
|
1765
1768
|
if (!props.selection) return;
|
|
1766
|
-
const key = getKey2(item,
|
|
1767
|
-
const next = selectedKeys.has(key) ? props.selection.selectedItems.filter((s) => getKey2(s,
|
|
1769
|
+
const key = getKey2(item, items, props.rowKey);
|
|
1770
|
+
const next = selectedKeys.has(key) ? props.selection.selectedItems.filter((s) => getKey2(s, items, props.rowKey) !== key) : [...props.selection.selectedItems, item];
|
|
1768
1771
|
props.selection.onChange(next);
|
|
1769
1772
|
};
|
|
1770
1773
|
return /* @__PURE__ */ jsxs(
|
|
@@ -1776,7 +1779,7 @@ var Grid = (props) => {
|
|
|
1776
1779
|
props.className
|
|
1777
1780
|
),
|
|
1778
1781
|
children: [
|
|
1779
|
-
|
|
1782
|
+
loading && !isInitialLoading && /* @__PURE__ */ jsx("div", { className: twMerge("absolute inset-0 z-10 bg-white/60 flex items-center justify-center", props.classNames?.overlay), children: /* @__PURE__ */ jsx(Spinner, { size: "large", color: "primary" }) }),
|
|
1780
1783
|
/* @__PURE__ */ jsx("div", { className: "overflow-x-auto", children: /* @__PURE__ */ jsxs("table", { className: twMerge("w-full border-collapse", props.classNames?.table), children: [
|
|
1781
1784
|
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { className: twMerge("bg-(--ui-primary) text-(--ui-primary-text)", props.classNames?.headerRow), children: [
|
|
1782
1785
|
props.selection && /* @__PURE__ */ jsx("th", { className: twMerge(sc.th, "w-9", verticalBorders && tableHeaderVerticalBorderClass, props.classNames?.headerCell), children: /* @__PURE__ */ jsx(
|
|
@@ -1831,8 +1834,8 @@ var Grid = (props) => {
|
|
|
1831
1834
|
className: twMerge("px-3", props.classNames?.emptyCell),
|
|
1832
1835
|
children: /* @__PURE__ */ jsx(Empty, { size: "compact", text: props.emptyText ?? "\u017D\xE1dn\xE9 z\xE1znamy", className: sc.emptyPy })
|
|
1833
1836
|
}
|
|
1834
|
-
) }) :
|
|
1835
|
-
const key = getKey2(item,
|
|
1837
|
+
) }) : items.map((item, rowIdx) => {
|
|
1838
|
+
const key = getKey2(item, items, props.rowKey);
|
|
1836
1839
|
const isSelected = selectedKeys.has(key);
|
|
1837
1840
|
return /* @__PURE__ */ jsxs(
|
|
1838
1841
|
"tr",
|
|
@@ -1906,7 +1909,7 @@ var Grid = (props) => {
|
|
|
1906
1909
|
{
|
|
1907
1910
|
current: grid.pageNumber,
|
|
1908
1911
|
pageSize: grid.pageSize,
|
|
1909
|
-
total:
|
|
1912
|
+
total: totalCount,
|
|
1910
1913
|
showPageNumberChanger: props.showPageNumberChanger ?? false,
|
|
1911
1914
|
showPageSizeChanger: props.showPageSizeChanger ?? false,
|
|
1912
1915
|
onChange: (page, pageSize) => grid.onChange({ pageNumber: page, pageSize }),
|