@ceed/ads 0.0.18 → 0.0.19
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.
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
import React, { ComponentProps } from "react";
|
|
2
|
-
import { Table
|
|
2
|
+
import { Table } from "../Table";
|
|
3
3
|
type DataTableProps<T extends Record<string, unknown>> = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
rows: T[];
|
|
5
|
+
checkboxSelection?: boolean;
|
|
6
|
+
columns: {
|
|
7
|
+
type?: "number" | "string";
|
|
8
|
+
field: keyof T;
|
|
9
|
+
headerName?: string;
|
|
10
|
+
width?: string;
|
|
11
|
+
minWidth?: string;
|
|
12
|
+
maxWidth?: string;
|
|
13
|
+
}[];
|
|
7
14
|
/**
|
|
8
15
|
* 체크박스가 있는 경우, 체크박스를 클릭했을 때 선택된 row의 index를 지정한다.
|
|
9
16
|
*/
|
|
10
17
|
selectionModel?: string[];
|
|
11
18
|
onSelectionModelChange?: (newSelectionModel: string[]) => void;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
onPageChange?: (newPage: number) => void;
|
|
18
|
-
rowsPerPage?: number;
|
|
19
|
+
paginationModel?: {
|
|
20
|
+
page: number;
|
|
21
|
+
pageSize: number;
|
|
22
|
+
};
|
|
23
|
+
onPaginationModelChange?: (newPage: number) => void;
|
|
19
24
|
/**
|
|
20
25
|
* Rows의 총 갯수를 직접 지정 할 수 있다.
|
|
21
|
-
*
|
|
22
|
-
* data lazy loading을 위한 prop
|
|
26
|
+
* 기본적으로는 rows.length를 사용하지만, 이 값을 지정하면 rows.length를 사용하지 않는다.
|
|
23
27
|
*/
|
|
24
|
-
|
|
28
|
+
rowCount?: number;
|
|
25
29
|
slots?: {
|
|
26
30
|
checkbox?: React.ElementType;
|
|
27
31
|
toolbar?: React.ElementType;
|
|
@@ -39,7 +43,7 @@ type DataTableProps<T extends Record<string, unknown>> = {
|
|
|
39
43
|
[key: string]: any;
|
|
40
44
|
}>;
|
|
41
45
|
};
|
|
42
|
-
} & ComponentProps<typeof Table
|
|
46
|
+
} & ComponentProps<typeof Table>;
|
|
43
47
|
declare function DataTable<T extends Record<string, unknown>>(props: DataTableProps<T>): React.JSX.Element;
|
|
44
48
|
declare namespace DataTable {
|
|
45
49
|
var displayName: string;
|
|
@@ -31,22 +31,25 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
31
31
|
};
|
|
32
32
|
import React, { useCallback, useEffect, useMemo, useState, } from "react";
|
|
33
33
|
import Sheet from "../Sheet";
|
|
34
|
-
import { Table
|
|
34
|
+
import { Table } from "../Table";
|
|
35
35
|
import Checkbox from "../Checkbox";
|
|
36
36
|
import Box from "../Box";
|
|
37
37
|
import Stack from "../Stack";
|
|
38
38
|
import Typography from "../Typography";
|
|
39
39
|
import Button from "../Button";
|
|
40
|
+
var numberFormatter = function (value) {
|
|
41
|
+
return "Intl" in window ? new Intl.NumberFormat().format(value) : value;
|
|
42
|
+
};
|
|
40
43
|
function TablePagination(props) {
|
|
41
44
|
// prop destruction
|
|
42
|
-
var
|
|
45
|
+
var _a = props.paginationModel, page = _a.page, pageSize = _a.pageSize, rowCount = props.rowCount, onPageChange = props.onPageChange;
|
|
43
46
|
// lib hooks
|
|
44
47
|
// state, ref, querystring hooks
|
|
45
48
|
// form hooks
|
|
46
49
|
// query hooks
|
|
47
50
|
// calculated values
|
|
48
51
|
var firstPage = 1;
|
|
49
|
-
var lastPage = Math.ceil(
|
|
52
|
+
var lastPage = Math.ceil(rowCount / pageSize);
|
|
50
53
|
var beforePages = [page - 2, page - 1].filter(function (p) { return p > 1; });
|
|
51
54
|
var afterPages = [page + 1, page + 2].filter(function (p) { return p <= lastPage - 1; });
|
|
52
55
|
var isMoreAfterPages = lastPage > 1 && page < lastPage - 3;
|
|
@@ -69,39 +72,39 @@ function TablePagination(props) {
|
|
|
69
72
|
React.createElement(Button, { size: "sm", variant: "plain", color: "neutral", onClick: function () { return onPageChange(page + 1); }, disabled: page === lastPage, "aria-label": "Next page" }, ">"))));
|
|
70
73
|
}
|
|
71
74
|
function useDataTableRenderer(_a) {
|
|
72
|
-
var
|
|
73
|
-
var
|
|
75
|
+
var rows = _a.rows, columns = _a.columns, totalRowsProp = _a.rowCount, paginationModel = _a.paginationModel, onPaginationModelChange = _a.onPaginationModelChange, _b = _a.selectionModel, selectionModel = _b === void 0 ? [] : _b, onSelectionModelChange = _a.onSelectionModelChange;
|
|
76
|
+
var _c = useState((paginationModel === null || paginationModel === void 0 ? void 0 : paginationModel.page) || 1), page = _c[0], setPage = _c[1];
|
|
77
|
+
var pageSize = (paginationModel === null || paginationModel === void 0 ? void 0 : paginationModel.pageSize) || 20;
|
|
74
78
|
var selectedModelSet = useMemo(function () { return new Set(selectionModel); }, [selectionModel]);
|
|
75
|
-
var dataInPage = useMemo(function () {
|
|
76
|
-
return data.slice((page - 1) * rowsPerPage, (page - 1) * rowsPerPage + rowsPerPage);
|
|
77
|
-
}, [data, page, rowsPerPage]);
|
|
79
|
+
var dataInPage = useMemo(function () { return rows.slice((page - 1) * pageSize, (page - 1) * pageSize + pageSize); }, [rows, page, pageSize]);
|
|
78
80
|
var isAllSelected = useMemo(function () {
|
|
79
81
|
return dataInPage.length > 0 &&
|
|
80
82
|
dataInPage.every(function (_, i) {
|
|
81
|
-
return selectedModelSet.has("".concat(i + (page - 1) *
|
|
83
|
+
return selectedModelSet.has("".concat(i + (page - 1) * pageSize));
|
|
82
84
|
});
|
|
83
|
-
}, [dataInPage, selectedModelSet, page,
|
|
84
|
-
var
|
|
85
|
-
var isTotalSelected = useMemo(function () { return
|
|
85
|
+
}, [dataInPage, selectedModelSet, page, pageSize]);
|
|
86
|
+
var rowCount = totalRowsProp || rows.length;
|
|
87
|
+
var isTotalSelected = useMemo(function () { return rowCount > 0 && selectionModel.length === rowCount; }, [selectionModel, rowCount]);
|
|
86
88
|
var handlePageChange = useCallback(function (newPage) {
|
|
87
89
|
setPage(newPage);
|
|
88
|
-
|
|
89
|
-
}, [
|
|
90
|
+
onPaginationModelChange === null || onPaginationModelChange === void 0 ? void 0 : onPaginationModelChange(newPage);
|
|
91
|
+
}, [onPaginationModelChange]);
|
|
90
92
|
useEffect(function () {
|
|
91
93
|
handlePageChange(1);
|
|
92
|
-
}, [
|
|
94
|
+
}, [rowCount]);
|
|
93
95
|
useEffect(function () {
|
|
94
|
-
if (page > Math.ceil(
|
|
95
|
-
handlePageChange(Math.ceil(
|
|
96
|
+
if (page > Math.ceil(rowCount / pageSize)) {
|
|
97
|
+
handlePageChange(Math.ceil(rowCount / pageSize));
|
|
96
98
|
}
|
|
97
|
-
}, [
|
|
99
|
+
}, [rowCount, pageSize]);
|
|
98
100
|
useEffect(function () {
|
|
99
101
|
onSelectionModelChange === null || onSelectionModelChange === void 0 ? void 0 : onSelectionModelChange([]);
|
|
100
102
|
}, [page]);
|
|
101
103
|
return {
|
|
102
|
-
|
|
104
|
+
rowCount: rowCount,
|
|
103
105
|
page: page,
|
|
104
|
-
|
|
106
|
+
pageSize: pageSize,
|
|
107
|
+
onPaginationModelChange: handlePageChange,
|
|
105
108
|
dataInPage: dataInPage,
|
|
106
109
|
isAllSelected: isAllSelected, // all rows are selected on this page
|
|
107
110
|
isTotalSelected: isTotalSelected,
|
|
@@ -109,45 +112,36 @@ function useDataTableRenderer(_a) {
|
|
|
109
112
|
onAllCheckboxChange: useCallback(function () {
|
|
110
113
|
onSelectionModelChange === null || onSelectionModelChange === void 0 ? void 0 : onSelectionModelChange(isAllSelected
|
|
111
114
|
? []
|
|
112
|
-
: dataInPage.map(function (_, i) { return "".concat(i + (page - 1) *
|
|
113
|
-
onCheckboxChange === null || onCheckboxChange === void 0 ? void 0 : onCheckboxChange(null, '');
|
|
115
|
+
: dataInPage.map(function (_, i) { return "".concat(i + (page - 1) * pageSize); }));
|
|
114
116
|
}, [isAllSelected, dataInPage, onSelectionModelChange]),
|
|
115
117
|
onCheckboxChange: useCallback(function (event, selectedModel) {
|
|
116
118
|
if (selectedModelSet.has(selectedModel)) {
|
|
117
119
|
var newSelectionModel = selectionModel.filter(function (model) { return model !== selectedModel; });
|
|
118
120
|
onSelectionModelChange === null || onSelectionModelChange === void 0 ? void 0 : onSelectionModelChange(newSelectionModel);
|
|
119
|
-
onCheckboxChange === null || onCheckboxChange === void 0 ? void 0 : onCheckboxChange(event, selectedModel);
|
|
120
121
|
}
|
|
121
122
|
else {
|
|
122
123
|
var newSelectionModel = __spreadArray(__spreadArray([], selectionModel, true), [selectedModel], false);
|
|
123
124
|
onSelectionModelChange === null || onSelectionModelChange === void 0 ? void 0 : onSelectionModelChange(newSelectionModel);
|
|
124
|
-
onCheckboxChange === null || onCheckboxChange === void 0 ? void 0 : onCheckboxChange(event, selectedModel);
|
|
125
125
|
}
|
|
126
126
|
}, [selectionModel, onSelectionModelChange]),
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return headCells ||
|
|
127
|
+
columns: useMemo(function () {
|
|
128
|
+
return columns ||
|
|
130
129
|
// fallback
|
|
131
|
-
Object.keys(
|
|
132
|
-
|
|
130
|
+
Object.keys(rows[0] || {}).map(function (key) { return ({
|
|
131
|
+
field: key,
|
|
133
132
|
}); });
|
|
134
|
-
}, [
|
|
133
|
+
}, [rows, columns]),
|
|
135
134
|
onTotalSelect: useCallback(function () {
|
|
136
|
-
onSelectionModelChange === null || onSelectionModelChange === void 0 ? void 0 : onSelectionModelChange(isTotalSelected ? [] :
|
|
137
|
-
}, [isTotalSelected,
|
|
135
|
+
onSelectionModelChange === null || onSelectionModelChange === void 0 ? void 0 : onSelectionModelChange(isTotalSelected ? [] : rows.map(function (_, i) { return "".concat(i); }));
|
|
136
|
+
}, [isTotalSelected, rows, onSelectionModelChange]),
|
|
138
137
|
};
|
|
139
138
|
}
|
|
140
139
|
function DataTable(props) {
|
|
141
140
|
// prop destruction
|
|
142
|
-
var
|
|
143
|
-
_a = props.
|
|
144
|
-
rowsPerPage = _a === void 0 ? 20 : _a, _page = props.page, // page is used in useDataTableRenderer
|
|
145
|
-
_onPageChange = props.onPageChange, // onPageChange is used in useDataTableRenderer
|
|
146
|
-
_onCheckboxChange = props.onCheckboxChange, // onCheckboxChange is used in useDataTableRenderer
|
|
147
|
-
_b = props.slots, // onCheckboxChange is used in useDataTableRenderer
|
|
148
|
-
_c = _b === void 0 ? {} : _b, _d = _c.checkbox, RenderCheckbox = _d === void 0 ? Checkbox : _d, Toolbar = _c.toolbar, Footer = _c.footer, _e = props.slotProps, _f = _e === void 0 ? {} : _e, _g = _f.checkbox, checkboxProps = _g === void 0 ? {} : _g, toolbarProps = _f.toolbar, _h = _f.background, backgroundProps = _h === void 0 ? {} : _h, innerProps = __rest(props, ["data", "showCheckbox", "headCells", "cellOrder", "selectionModel", "onSelectionModelChange", "totalRows", "rowsPerPage", "page", "onPageChange", "onCheckboxChange", "slots", "slotProps"]);
|
|
141
|
+
var rows = props.rows, checkboxSelection = props.checkboxSelection, selectionModel = props.selectionModel, onSelectionModelChange = props.onSelectionModelChange, _ = props.rowCount, // rowCount is used in useDataTableRenderer
|
|
142
|
+
paginationModel = props.paginationModel, _a = props.slots, _b = _a === void 0 ? {} : _a, _c = _b.checkbox, RenderCheckbox = _c === void 0 ? Checkbox : _c, Toolbar = _b.toolbar, Footer = _b.footer, _d = props.slotProps, _e = _d === void 0 ? {} : _d, _f = _e.checkbox, checkboxProps = _f === void 0 ? {} : _f, toolbarProps = _e.toolbar, _g = _e.background, backgroundProps = _g === void 0 ? {} : _g, innerProps = __rest(props, ["rows", "checkboxSelection", "selectionModel", "onSelectionModelChange", "rowCount", "paginationModel", "slots", "slotProps"]);
|
|
149
143
|
// lib hooks
|
|
150
|
-
var
|
|
144
|
+
var _h = useDataTableRenderer(props), columns = _h.columns, isAllSelected = _h.isAllSelected, isSelectedRow = _h.isSelectedRow, onAllCheckboxChange = _h.onAllCheckboxChange, onCheckboxChange = _h.onCheckboxChange, rowCount = _h.rowCount, page = _h.page, pageSize = _h.pageSize, onPaginationModelChange = _h.onPaginationModelChange, dataInPage = _h.dataInPage, isTotalSelected = _h.isTotalSelected, onTotalSelect = _h.onTotalSelect;
|
|
151
145
|
// state, ref, querystring hooks
|
|
152
146
|
// form hooks
|
|
153
147
|
// query hooks
|
|
@@ -161,21 +155,21 @@ function DataTable(props) {
|
|
|
161
155
|
}, justifyContent: "space-between", alignItems: "center" },
|
|
162
156
|
React.createElement(Stack, { direction: "row", spacing: 1 },
|
|
163
157
|
!isAllSelected && (React.createElement(Typography, { level: "body-xs" },
|
|
164
|
-
(selectionModel === null || selectionModel === void 0 ? void 0 : selectionModel.length) || 0,
|
|
158
|
+
numberFormatter((selectionModel === null || selectionModel === void 0 ? void 0 : selectionModel.length) || 0),
|
|
165
159
|
" items selected")),
|
|
166
160
|
isAllSelected && !isTotalSelected && (React.createElement(Stack, { direction: "row", spacing: 1, alignItems: "center" },
|
|
167
161
|
React.createElement(Typography, { level: "body-xs" },
|
|
168
|
-
"All ",
|
|
169
|
-
selectionModel.length,
|
|
162
|
+
"All ",
|
|
163
|
+
numberFormatter((selectionModel === null || selectionModel === void 0 ? void 0 : selectionModel.length) || 0),
|
|
170
164
|
" items on this page are selected."),
|
|
171
165
|
React.createElement(Button, { size: "sm", variant: "plain", onClick: onTotalSelect },
|
|
172
166
|
"Select all ",
|
|
173
|
-
|
|
167
|
+
numberFormatter(rows.length),
|
|
174
168
|
" items"))),
|
|
175
169
|
isTotalSelected && (React.createElement(Stack, { direction: "row", spacing: 1, alignItems: "center" },
|
|
176
170
|
React.createElement(Typography, { level: "body-xs" },
|
|
177
171
|
"All ",
|
|
178
|
-
|
|
172
|
+
numberFormatter(rows.length),
|
|
179
173
|
" items are selected."),
|
|
180
174
|
React.createElement(Button, { size: "sm", variant: "plain", color: "danger", onClick: onTotalSelect }, "Cancel")))),
|
|
181
175
|
Toolbar && React.createElement(Toolbar, __assign({}, (toolbarProps || {})))),
|
|
@@ -193,14 +187,27 @@ function DataTable(props) {
|
|
|
193
187
|
},
|
|
194
188
|
},
|
|
195
189
|
] }, innerProps),
|
|
196
|
-
React.createElement(
|
|
197
|
-
|
|
198
|
-
|
|
190
|
+
React.createElement("thead", null,
|
|
191
|
+
React.createElement("tr", null,
|
|
192
|
+
checkboxSelection && (React.createElement("th", { style: {
|
|
193
|
+
width: "40px",
|
|
194
|
+
textAlign: "center",
|
|
195
|
+
} },
|
|
196
|
+
React.createElement(RenderCheckbox, __assign({ onChange: onAllCheckboxChange, checked: isAllSelected, indeterminate: (selectionModel || []).length > 0 && !isAllSelected }, checkboxProps)))),
|
|
197
|
+
columns.map(function (column) {
|
|
198
|
+
var _a;
|
|
199
|
+
return (React.createElement("th", { key: column.field, style: {
|
|
200
|
+
width: column.width,
|
|
201
|
+
minWidth: column.minWidth,
|
|
202
|
+
maxWidth: column.maxWidth,
|
|
203
|
+
textAlign: column.type === "number" ? "end" : "start",
|
|
204
|
+
} }, (_a = column.headerName) !== null && _a !== void 0 ? _a : column.field));
|
|
205
|
+
}))),
|
|
199
206
|
React.createElement("tbody", null, dataInPage.map(function (row, rowIndex) {
|
|
200
|
-
var rowId = "".concat(rowIndex + (page - 1) *
|
|
201
|
-
return (React.createElement("tr", { key: rowId, role:
|
|
207
|
+
var rowId = "".concat(rowIndex + (page - 1) * pageSize);
|
|
208
|
+
return (React.createElement("tr", { key: rowId, role: checkboxSelection ? "checkbox" : undefined, tabIndex: checkboxSelection ? -1 : undefined, onClick: checkboxSelection
|
|
202
209
|
? function (e) { return onCheckboxChange(e, rowId); }
|
|
203
|
-
: undefined, "aria-checked":
|
|
210
|
+
: undefined, "aria-checked": checkboxSelection ? isSelectedRow(rowId) : undefined, style: checkboxSelection && isSelectedRow(rowId)
|
|
204
211
|
? {
|
|
205
212
|
"--TableCell-dataBackground": "var(--TableCell-selectedBackground)",
|
|
206
213
|
"--TableCell-headBackground": "var(--TableCell-selectedBackground)",
|
|
@@ -208,14 +215,16 @@ function DataTable(props) {
|
|
|
208
215
|
: {
|
|
209
216
|
"--TableCell-headBackground": "transparent",
|
|
210
217
|
} },
|
|
211
|
-
|
|
218
|
+
checkboxSelection && (React.createElement("th", { scope: "row", style: {
|
|
212
219
|
textAlign: "center",
|
|
213
220
|
} },
|
|
214
221
|
React.createElement(RenderCheckbox, __assign({ onChange: function (e) { return onCheckboxChange(e, rowId); }, checked: isSelectedRow(rowId) }, checkboxProps)))),
|
|
215
|
-
|
|
222
|
+
columns.map(function (column) { return (React.createElement("td", { key: column.field, style: {
|
|
223
|
+
textAlign: column.type === "number" ? "end" : "start",
|
|
224
|
+
} }, row[column.field])); })));
|
|
216
225
|
})),
|
|
217
226
|
Footer && React.createElement(Footer, null))),
|
|
218
|
-
React.createElement(TablePagination, { page: page,
|
|
227
|
+
React.createElement(TablePagination, { paginationModel: { page: page, pageSize: pageSize }, rowCount: rowCount, onPageChange: onPaginationModelChange, onRowsPerPageChange: function () { } })));
|
|
219
228
|
}
|
|
220
229
|
export { DataTable };
|
|
221
230
|
DataTable.displayName = "DataTable";
|
package/framer/index.js
CHANGED
|
@@ -32095,10 +32095,15 @@ Typography3.displayName = "Typography";
|
|
|
32095
32095
|
var Typography_default2 = Typography3;
|
|
32096
32096
|
|
|
32097
32097
|
// src/components/DataTable/DataTable.tsx
|
|
32098
|
+
var numberFormatter = (value) => "Intl" in window ? new Intl.NumberFormat().format(value) : value;
|
|
32098
32099
|
function TablePagination(props) {
|
|
32099
|
-
const {
|
|
32100
|
+
const {
|
|
32101
|
+
paginationModel: { page, pageSize },
|
|
32102
|
+
rowCount,
|
|
32103
|
+
onPageChange
|
|
32104
|
+
} = props;
|
|
32100
32105
|
const firstPage = 1;
|
|
32101
|
-
const lastPage = Math.ceil(
|
|
32106
|
+
const lastPage = Math.ceil(rowCount / pageSize);
|
|
32102
32107
|
const beforePages = [page - 2, page - 1].filter((p) => p > 1);
|
|
32103
32108
|
const afterPages = [page + 1, page + 2].filter((p) => p <= lastPage - 1);
|
|
32104
32109
|
const isMoreAfterPages = lastPage > 1 && page < lastPage - 3;
|
|
@@ -32207,62 +32212,58 @@ function TablePagination(props) {
|
|
|
32207
32212
|
);
|
|
32208
32213
|
}
|
|
32209
32214
|
function useDataTableRenderer({
|
|
32210
|
-
|
|
32211
|
-
|
|
32212
|
-
|
|
32213
|
-
|
|
32214
|
-
|
|
32215
|
-
onPageChange,
|
|
32216
|
-
rowsPerPage,
|
|
32215
|
+
rows,
|
|
32216
|
+
columns,
|
|
32217
|
+
rowCount: totalRowsProp,
|
|
32218
|
+
paginationModel,
|
|
32219
|
+
onPaginationModelChange,
|
|
32217
32220
|
selectionModel = [],
|
|
32218
|
-
onSelectionModelChange
|
|
32219
|
-
onCheckboxChange
|
|
32221
|
+
onSelectionModelChange
|
|
32220
32222
|
}) {
|
|
32221
|
-
const [page, setPage] = useState21(
|
|
32223
|
+
const [page, setPage] = useState21(paginationModel?.page || 1);
|
|
32224
|
+
const pageSize = paginationModel?.pageSize || 20;
|
|
32222
32225
|
const selectedModelSet = useMemo32(
|
|
32223
32226
|
() => new Set(selectionModel),
|
|
32224
32227
|
[selectionModel]
|
|
32225
32228
|
);
|
|
32226
32229
|
const dataInPage = useMemo32(
|
|
32227
|
-
() =>
|
|
32228
|
-
|
|
32229
|
-
(page - 1) * rowsPerPage + rowsPerPage
|
|
32230
|
-
),
|
|
32231
|
-
[data, page, rowsPerPage]
|
|
32230
|
+
() => rows.slice((page - 1) * pageSize, (page - 1) * pageSize + pageSize),
|
|
32231
|
+
[rows, page, pageSize]
|
|
32232
32232
|
);
|
|
32233
32233
|
const isAllSelected = useMemo32(
|
|
32234
32234
|
() => dataInPage.length > 0 && dataInPage.every(
|
|
32235
|
-
(_4, i) => selectedModelSet.has(`${i + (page - 1) *
|
|
32235
|
+
(_4, i) => selectedModelSet.has(`${i + (page - 1) * pageSize}`)
|
|
32236
32236
|
),
|
|
32237
|
-
[dataInPage, selectedModelSet, page,
|
|
32237
|
+
[dataInPage, selectedModelSet, page, pageSize]
|
|
32238
32238
|
);
|
|
32239
|
-
const
|
|
32239
|
+
const rowCount = totalRowsProp || rows.length;
|
|
32240
32240
|
const isTotalSelected = useMemo32(
|
|
32241
|
-
() =>
|
|
32242
|
-
[selectionModel,
|
|
32241
|
+
() => rowCount > 0 && selectionModel.length === rowCount,
|
|
32242
|
+
[selectionModel, rowCount]
|
|
32243
32243
|
);
|
|
32244
32244
|
const handlePageChange = useCallback23(
|
|
32245
32245
|
(newPage) => {
|
|
32246
32246
|
setPage(newPage);
|
|
32247
|
-
|
|
32247
|
+
onPaginationModelChange?.(newPage);
|
|
32248
32248
|
},
|
|
32249
|
-
[
|
|
32249
|
+
[onPaginationModelChange]
|
|
32250
32250
|
);
|
|
32251
32251
|
useEffect33(() => {
|
|
32252
32252
|
handlePageChange(1);
|
|
32253
|
-
}, [
|
|
32253
|
+
}, [rowCount]);
|
|
32254
32254
|
useEffect33(() => {
|
|
32255
|
-
if (page > Math.ceil(
|
|
32256
|
-
handlePageChange(Math.ceil(
|
|
32255
|
+
if (page > Math.ceil(rowCount / pageSize)) {
|
|
32256
|
+
handlePageChange(Math.ceil(rowCount / pageSize));
|
|
32257
32257
|
}
|
|
32258
|
-
}, [
|
|
32258
|
+
}, [rowCount, pageSize]);
|
|
32259
32259
|
useEffect33(() => {
|
|
32260
32260
|
onSelectionModelChange?.([]);
|
|
32261
32261
|
}, [page]);
|
|
32262
32262
|
return {
|
|
32263
|
-
|
|
32263
|
+
rowCount,
|
|
32264
32264
|
page,
|
|
32265
|
-
|
|
32265
|
+
pageSize,
|
|
32266
|
+
onPaginationModelChange: handlePageChange,
|
|
32266
32267
|
dataInPage,
|
|
32267
32268
|
isAllSelected,
|
|
32268
32269
|
// all rows are selected on this page
|
|
@@ -32273,9 +32274,8 @@ function useDataTableRenderer({
|
|
|
32273
32274
|
),
|
|
32274
32275
|
onAllCheckboxChange: useCallback23(() => {
|
|
32275
32276
|
onSelectionModelChange?.(
|
|
32276
|
-
isAllSelected ? [] : dataInPage.map((_4, i) => `${i + (page - 1) *
|
|
32277
|
+
isAllSelected ? [] : dataInPage.map((_4, i) => `${i + (page - 1) * pageSize}`)
|
|
32277
32278
|
);
|
|
32278
|
-
onCheckboxChange?.(null, "");
|
|
32279
32279
|
}, [isAllSelected, dataInPage, onSelectionModelChange]),
|
|
32280
32280
|
onCheckboxChange: useCallback23(
|
|
32281
32281
|
(event, selectedModel) => {
|
|
@@ -32284,50 +32284,36 @@ function useDataTableRenderer({
|
|
|
32284
32284
|
(model) => model !== selectedModel
|
|
32285
32285
|
);
|
|
32286
32286
|
onSelectionModelChange?.(newSelectionModel);
|
|
32287
|
-
onCheckboxChange?.(event, selectedModel);
|
|
32288
32287
|
} else {
|
|
32289
32288
|
const newSelectionModel = [...selectionModel, selectedModel];
|
|
32290
32289
|
onSelectionModelChange?.(newSelectionModel);
|
|
32291
|
-
onCheckboxChange?.(event, selectedModel);
|
|
32292
32290
|
}
|
|
32293
32291
|
},
|
|
32294
32292
|
[selectionModel, onSelectionModelChange]
|
|
32295
32293
|
),
|
|
32296
|
-
|
|
32297
|
-
() =>
|
|
32298
|
-
[
|
|
32299
|
-
|
|
32300
|
-
renderHeadCells: useMemo32(
|
|
32301
|
-
() => headCells || // fallback
|
|
32302
|
-
Object.keys(data[0] || {}).map((key) => ({
|
|
32303
|
-
label: key
|
|
32294
|
+
columns: useMemo32(
|
|
32295
|
+
() => columns || // fallback
|
|
32296
|
+
Object.keys(rows[0] || {}).map((key) => ({
|
|
32297
|
+
field: key
|
|
32304
32298
|
})),
|
|
32305
|
-
[
|
|
32299
|
+
[rows, columns]
|
|
32306
32300
|
),
|
|
32307
32301
|
onTotalSelect: useCallback23(() => {
|
|
32308
32302
|
onSelectionModelChange?.(
|
|
32309
|
-
isTotalSelected ? [] :
|
|
32303
|
+
isTotalSelected ? [] : rows.map((_4, i) => `${i}`)
|
|
32310
32304
|
);
|
|
32311
|
-
}, [isTotalSelected,
|
|
32305
|
+
}, [isTotalSelected, rows, onSelectionModelChange])
|
|
32312
32306
|
};
|
|
32313
32307
|
}
|
|
32314
32308
|
function DataTable(props) {
|
|
32315
32309
|
const {
|
|
32316
|
-
|
|
32317
|
-
|
|
32318
|
-
headCells,
|
|
32319
|
-
cellOrder,
|
|
32310
|
+
rows,
|
|
32311
|
+
checkboxSelection,
|
|
32320
32312
|
selectionModel,
|
|
32321
32313
|
onSelectionModelChange,
|
|
32322
|
-
|
|
32323
|
-
//
|
|
32324
|
-
|
|
32325
|
-
page: _page,
|
|
32326
|
-
// page is used in useDataTableRenderer
|
|
32327
|
-
onPageChange: _onPageChange,
|
|
32328
|
-
// onPageChange is used in useDataTableRenderer
|
|
32329
|
-
onCheckboxChange: _onCheckboxChange,
|
|
32330
|
-
// onCheckboxChange is used in useDataTableRenderer
|
|
32314
|
+
rowCount: _4,
|
|
32315
|
+
// rowCount is used in useDataTableRenderer
|
|
32316
|
+
paginationModel,
|
|
32331
32317
|
slots: {
|
|
32332
32318
|
checkbox: RenderCheckbox = Checkbox_default2,
|
|
32333
32319
|
toolbar: Toolbar,
|
|
@@ -32341,19 +32327,19 @@ function DataTable(props) {
|
|
|
32341
32327
|
...innerProps
|
|
32342
32328
|
} = props;
|
|
32343
32329
|
const {
|
|
32344
|
-
|
|
32345
|
-
renderHeadCells,
|
|
32330
|
+
columns,
|
|
32346
32331
|
isAllSelected,
|
|
32347
32332
|
isSelectedRow,
|
|
32348
32333
|
onAllCheckboxChange,
|
|
32349
32334
|
onCheckboxChange,
|
|
32350
|
-
|
|
32335
|
+
rowCount,
|
|
32351
32336
|
page,
|
|
32352
|
-
|
|
32337
|
+
pageSize,
|
|
32338
|
+
onPaginationModelChange,
|
|
32353
32339
|
dataInPage,
|
|
32354
32340
|
isTotalSelected,
|
|
32355
32341
|
onTotalSelect
|
|
32356
|
-
} = useDataTableRenderer(
|
|
32342
|
+
} = useDataTableRenderer(props);
|
|
32357
32343
|
return /* @__PURE__ */ jsxs2(Box_default2, { children: [
|
|
32358
32344
|
/* @__PURE__ */ jsxs2(
|
|
32359
32345
|
Stack_default2,
|
|
@@ -32368,25 +32354,25 @@ function DataTable(props) {
|
|
|
32368
32354
|
children: [
|
|
32369
32355
|
/* @__PURE__ */ jsxs2(Stack_default2, { direction: "row", spacing: 1, children: [
|
|
32370
32356
|
!isAllSelected && /* @__PURE__ */ jsxs2(Typography_default2, { level: "body-xs", children: [
|
|
32371
|
-
selectionModel?.length || 0,
|
|
32357
|
+
numberFormatter(selectionModel?.length || 0),
|
|
32372
32358
|
" items selected"
|
|
32373
32359
|
] }),
|
|
32374
32360
|
isAllSelected && !isTotalSelected && /* @__PURE__ */ jsxs2(Stack_default2, { direction: "row", spacing: 1, alignItems: "center", children: [
|
|
32375
32361
|
/* @__PURE__ */ jsxs2(Typography_default2, { level: "body-xs", children: [
|
|
32376
32362
|
"All ",
|
|
32377
|
-
selectionModel?.length,
|
|
32363
|
+
numberFormatter(selectionModel?.length || 0),
|
|
32378
32364
|
" items on this page are selected."
|
|
32379
32365
|
] }),
|
|
32380
32366
|
/* @__PURE__ */ jsxs2(Button_default2, { size: "sm", variant: "plain", onClick: onTotalSelect, children: [
|
|
32381
32367
|
"Select all ",
|
|
32382
|
-
|
|
32368
|
+
numberFormatter(rows.length),
|
|
32383
32369
|
" items"
|
|
32384
32370
|
] })
|
|
32385
32371
|
] }),
|
|
32386
32372
|
isTotalSelected && /* @__PURE__ */ jsxs2(Stack_default2, { direction: "row", spacing: 1, alignItems: "center", children: [
|
|
32387
32373
|
/* @__PURE__ */ jsxs2(Typography_default2, { level: "body-xs", children: [
|
|
32388
32374
|
"All ",
|
|
32389
|
-
|
|
32375
|
+
numberFormatter(rows.length),
|
|
32390
32376
|
" items are selected."
|
|
32391
32377
|
] }),
|
|
32392
32378
|
/* @__PURE__ */ jsx2(
|
|
@@ -32427,38 +32413,56 @@ function DataTable(props) {
|
|
|
32427
32413
|
],
|
|
32428
32414
|
...innerProps,
|
|
32429
32415
|
children: [
|
|
32430
|
-
/* @__PURE__ */ jsx2(
|
|
32431
|
-
|
|
32432
|
-
|
|
32433
|
-
|
|
32434
|
-
|
|
32435
|
-
|
|
32436
|
-
|
|
32437
|
-
|
|
32438
|
-
|
|
32439
|
-
|
|
32440
|
-
|
|
32441
|
-
|
|
32416
|
+
/* @__PURE__ */ jsx2("thead", { children: /* @__PURE__ */ jsxs2("tr", { children: [
|
|
32417
|
+
checkboxSelection && /* @__PURE__ */ jsx2(
|
|
32418
|
+
"th",
|
|
32419
|
+
{
|
|
32420
|
+
style: {
|
|
32421
|
+
width: "40px",
|
|
32422
|
+
textAlign: "center"
|
|
32423
|
+
},
|
|
32424
|
+
children: /* @__PURE__ */ jsx2(
|
|
32425
|
+
RenderCheckbox,
|
|
32426
|
+
{
|
|
32427
|
+
onChange: onAllCheckboxChange,
|
|
32428
|
+
checked: isAllSelected,
|
|
32429
|
+
indeterminate: (selectionModel || []).length > 0 && !isAllSelected,
|
|
32430
|
+
...checkboxProps
|
|
32431
|
+
}
|
|
32432
|
+
)
|
|
32442
32433
|
}
|
|
32443
|
-
|
|
32444
|
-
|
|
32434
|
+
),
|
|
32435
|
+
columns.map((column2) => /* @__PURE__ */ jsx2(
|
|
32436
|
+
"th",
|
|
32437
|
+
{
|
|
32438
|
+
style: {
|
|
32439
|
+
width: column2.width,
|
|
32440
|
+
minWidth: column2.minWidth,
|
|
32441
|
+
maxWidth: column2.maxWidth,
|
|
32442
|
+
textAlign: column2.type === "number" ? "end" : "start"
|
|
32443
|
+
},
|
|
32444
|
+
children: column2.headerName ?? column2.field
|
|
32445
|
+
},
|
|
32446
|
+
column2.field
|
|
32447
|
+
))
|
|
32448
|
+
] }) }),
|
|
32445
32449
|
/* @__PURE__ */ jsx2("tbody", { children: dataInPage.map((row, rowIndex) => {
|
|
32446
|
-
const rowId = `${rowIndex + (page - 1) *
|
|
32450
|
+
const rowId = `${rowIndex + (page - 1) * pageSize}`;
|
|
32447
32451
|
return /* @__PURE__ */ jsxs2(
|
|
32448
32452
|
"tr",
|
|
32449
32453
|
{
|
|
32450
|
-
role:
|
|
32451
|
-
tabIndex:
|
|
32452
|
-
onClick:
|
|
32453
|
-
"aria-checked":
|
|
32454
|
-
style:
|
|
32454
|
+
role: checkboxSelection ? "checkbox" : void 0,
|
|
32455
|
+
tabIndex: checkboxSelection ? -1 : void 0,
|
|
32456
|
+
onClick: checkboxSelection ? (e) => onCheckboxChange(e, rowId) : void 0,
|
|
32457
|
+
"aria-checked": checkboxSelection ? isSelectedRow(rowId) : void 0,
|
|
32458
|
+
style: checkboxSelection && isSelectedRow(rowId) ? {
|
|
32455
32459
|
"--TableCell-dataBackground": "var(--TableCell-selectedBackground)",
|
|
32456
32460
|
"--TableCell-headBackground": "var(--TableCell-selectedBackground)"
|
|
32457
32461
|
} : {
|
|
32458
32462
|
"--TableCell-headBackground": "transparent"
|
|
32459
32463
|
},
|
|
32460
32464
|
children: [
|
|
32461
|
-
|
|
32465
|
+
checkboxSelection && /* @__PURE__ */ jsx2(
|
|
32462
32466
|
"th",
|
|
32463
32467
|
{
|
|
32464
32468
|
scope: "row",
|
|
@@ -32475,7 +32479,16 @@ function DataTable(props) {
|
|
|
32475
32479
|
)
|
|
32476
32480
|
}
|
|
32477
32481
|
),
|
|
32478
|
-
|
|
32482
|
+
columns.map((column2) => /* @__PURE__ */ jsx2(
|
|
32483
|
+
"td",
|
|
32484
|
+
{
|
|
32485
|
+
style: {
|
|
32486
|
+
textAlign: column2.type === "number" ? "end" : "start"
|
|
32487
|
+
},
|
|
32488
|
+
children: row[column2.field]
|
|
32489
|
+
},
|
|
32490
|
+
column2.field
|
|
32491
|
+
))
|
|
32479
32492
|
]
|
|
32480
32493
|
},
|
|
32481
32494
|
rowId
|
|
@@ -32490,10 +32503,9 @@ function DataTable(props) {
|
|
|
32490
32503
|
/* @__PURE__ */ jsx2(
|
|
32491
32504
|
TablePagination,
|
|
32492
32505
|
{
|
|
32493
|
-
page,
|
|
32494
|
-
|
|
32495
|
-
|
|
32496
|
-
onPageChange,
|
|
32506
|
+
paginationModel: { page, pageSize },
|
|
32507
|
+
rowCount,
|
|
32508
|
+
onPageChange: onPaginationModelChange,
|
|
32497
32509
|
onRowsPerPageChange: () => {
|
|
32498
32510
|
}
|
|
32499
32511
|
}
|
|
@@ -32762,6 +32774,12 @@ var defaultTheme4 = extendTheme({
|
|
|
32762
32774
|
}
|
|
32763
32775
|
})
|
|
32764
32776
|
}
|
|
32777
|
+
},
|
|
32778
|
+
JoyTooltip: {
|
|
32779
|
+
defaultProps: {
|
|
32780
|
+
size: "sm",
|
|
32781
|
+
placement: "top"
|
|
32782
|
+
}
|
|
32765
32783
|
}
|
|
32766
32784
|
}
|
|
32767
32785
|
});
|
|
@@ -33025,7 +33043,8 @@ var dataTablePropertyControls = {
|
|
|
33025
33043
|
// defaultValue:
|
|
33026
33044
|
// "https://sharadcodes.github.io/noob-cms/data/MOCK_DATA.csv",
|
|
33027
33045
|
},
|
|
33028
|
-
|
|
33046
|
+
checkboxSelection: {
|
|
33047
|
+
title: "Show Checkbox",
|
|
33029
33048
|
type: ControlType7.Boolean,
|
|
33030
33049
|
defaultValue: true
|
|
33031
33050
|
},
|
|
@@ -33043,13 +33062,15 @@ var dataTablePropertyControls = {
|
|
|
33043
33062
|
optionTitles: ["None", "Odd", "Even"],
|
|
33044
33063
|
defaultValue: void 0
|
|
33045
33064
|
},
|
|
33046
|
-
|
|
33065
|
+
columns: {
|
|
33047
33066
|
type: ControlType7.Array,
|
|
33067
|
+
description: "Column\uC758 \uC0C1\uC138 \uC124\uC815\uC774 \uD544\uC694\uD55C \uACBD\uC6B0 \uC0AC\uC6A9",
|
|
33048
33068
|
control: {
|
|
33049
33069
|
type: ControlType7.Object,
|
|
33050
33070
|
controls: {
|
|
33051
|
-
|
|
33052
|
-
type: ControlType7.String
|
|
33071
|
+
field: {
|
|
33072
|
+
type: ControlType7.String,
|
|
33073
|
+
description: "Column Name. CSV\uC5D0 \uC788\uB294 \uAC12\uC744 \uADF8\uB300\uB85C \uB123\uC5B4\uC57C \uD55C\uB2E4."
|
|
33053
33074
|
},
|
|
33054
33075
|
width: {
|
|
33055
33076
|
type: ControlType7.String
|
|
@@ -33062,7 +33083,7 @@ var dataTablePropertyControls = {
|
|
|
33062
33083
|
},
|
|
33063
33084
|
defaultValue: []
|
|
33064
33085
|
},
|
|
33065
|
-
|
|
33086
|
+
pageSize: {
|
|
33066
33087
|
type: ControlType7.Number,
|
|
33067
33088
|
defaultValue: 20
|
|
33068
33089
|
},
|
|
@@ -33074,10 +33095,10 @@ var dataTablePropertyControls = {
|
|
|
33074
33095
|
type: ControlType7.Boolean,
|
|
33075
33096
|
defaultValue: false
|
|
33076
33097
|
},
|
|
33077
|
-
|
|
33098
|
+
onPaginationModelChange: {
|
|
33078
33099
|
type: ControlType7.EventHandler
|
|
33079
33100
|
},
|
|
33080
|
-
|
|
33101
|
+
onSelectionModelChange: {
|
|
33081
33102
|
type: ControlType7.EventHandler
|
|
33082
33103
|
},
|
|
33083
33104
|
toolbar: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ceed/ads",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "UI tool for Ecube Labs front-end developers",
|
|
@@ -53,6 +53,5 @@
|
|
|
53
53
|
"type": "git",
|
|
54
54
|
"url": "git+ssh://git@github.com/Ecube-Labs/hds.git"
|
|
55
55
|
},
|
|
56
|
-
"packageManager": "yarn@4.1.0"
|
|
57
|
-
"stableVersion": "0.0.17"
|
|
56
|
+
"packageManager": "yarn@4.1.0"
|
|
58
57
|
}
|