mig-schema-table 3.0.6 → 3.0.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/SchemaTable/Td/index.d.ts +22 -0
- package/dist/SchemaTable/Td/index.js +64 -0
- package/dist/SchemaTable/index.js +9 -68
- package/dist/index.css +8 -10
- package/package.json +1 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { oas31 } from "openapi3-ts";
|
|
3
|
+
import { IColumnConfig, IRenderData } from "../../types";
|
|
4
|
+
interface ITdProps<T> {
|
|
5
|
+
checkedIndexes?: number[];
|
|
6
|
+
columnIndex: number;
|
|
7
|
+
data: T[];
|
|
8
|
+
getRowClassName?: (rowData: T, dataIndex: number) => string;
|
|
9
|
+
getRowSelected?: (rowData: T) => boolean;
|
|
10
|
+
rowHeight: number;
|
|
11
|
+
rowIndex: number;
|
|
12
|
+
onCheckedIndexesChange?: (dataIndex: number[]) => void;
|
|
13
|
+
onRowClick?: (rowData: T, dataIndex: number, event: React.MouseEvent) => void;
|
|
14
|
+
propConfig?: IColumnConfig<any>;
|
|
15
|
+
propName: string;
|
|
16
|
+
propSchema: oas31.SchemaObject;
|
|
17
|
+
sortedRenderData?: IRenderData[];
|
|
18
|
+
style: React.CSSProperties;
|
|
19
|
+
}
|
|
20
|
+
declare function Td<T>({ checkedIndexes, columnIndex, data, getRowClassName, getRowSelected, onCheckedIndexesChange, onRowClick, propConfig, propName, propSchema, rowHeight, rowIndex, sortedRenderData, style, }: ITdProps<T>): import("react/jsx-runtime").JSX.Element | null;
|
|
21
|
+
declare const _default: typeof Td;
|
|
22
|
+
export default _default;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { SELECT_ALL_COLUMN_NAME } from "../constants";
|
|
4
|
+
function Td({ checkedIndexes, columnIndex, data, getRowClassName, getRowSelected, onCheckedIndexesChange, onRowClick, propConfig, propName, propSchema, rowHeight, rowIndex, sortedRenderData, style, }) {
|
|
5
|
+
const onTdClick = React.useCallback((e) => {
|
|
6
|
+
if (!sortedRenderData || !onRowClick) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const { rowIndex } = e.currentTarget.dataset;
|
|
10
|
+
if (!rowIndex) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const row = sortedRenderData[parseInt(rowIndex, 10)];
|
|
14
|
+
onRowClick(data[row._index], row._index, e);
|
|
15
|
+
}, [data, onRowClick, sortedRenderData]);
|
|
16
|
+
if (!sortedRenderData) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const row = sortedRenderData[rowIndex];
|
|
20
|
+
const tdDivProps = {
|
|
21
|
+
"data-row-index": rowIndex,
|
|
22
|
+
"data-column-index": columnIndex,
|
|
23
|
+
key: propName,
|
|
24
|
+
style: Object.assign(Object.assign({}, style), { lineHeight: `${rowHeight}px` }),
|
|
25
|
+
onClick: !(propConfig === null || propConfig === void 0 ? void 0 : propConfig.renderCell) ? onTdClick : undefined,
|
|
26
|
+
className: `schema-table__td schema-table__td--${rowIndex % 2 ? "odd" : "even"}${row && getRowSelected && getRowSelected(data[row._index])
|
|
27
|
+
? " schema-table__td--selected"
|
|
28
|
+
: ""} ${row && getRowClassName
|
|
29
|
+
? getRowClassName(data[row._index], row._index)
|
|
30
|
+
: ""}`,
|
|
31
|
+
};
|
|
32
|
+
if (propConfig === null || propConfig === void 0 ? void 0 : propConfig.renderCell) {
|
|
33
|
+
return (_jsx("div", Object.assign({}, tdDivProps, { children: propConfig.renderCell(data[row._index], row._index, rowIndex) })));
|
|
34
|
+
}
|
|
35
|
+
if (propName === SELECT_ALL_COLUMN_NAME) {
|
|
36
|
+
const onChecked = () => {
|
|
37
|
+
if (!onCheckedIndexesChange) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
onCheckedIndexesChange([row._index]);
|
|
41
|
+
};
|
|
42
|
+
return (_jsx("div", Object.assign({}, tdDivProps, { children: _jsx("div", Object.assign({ style: { textAlign: "center" } }, { children: _jsx("input", { type: "checkbox", onChange: onChecked, checked: checkedIndexes === null || checkedIndexes === void 0 ? void 0 : checkedIndexes.includes(row._index) }) })) })));
|
|
43
|
+
}
|
|
44
|
+
if (!propSchema) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
switch (propSchema.type) {
|
|
48
|
+
case "boolean":
|
|
49
|
+
tdDivProps.className += ` text-${(propConfig === null || propConfig === void 0 ? void 0 : propConfig.align) || "center"}`;
|
|
50
|
+
break;
|
|
51
|
+
case "number":
|
|
52
|
+
case "integer":
|
|
53
|
+
tdDivProps.className += ` text-${(propConfig === null || propConfig === void 0 ? void 0 : propConfig.align) || "end"}`;
|
|
54
|
+
break;
|
|
55
|
+
case "string":
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
tdDivProps.title = row[propName];
|
|
58
|
+
if (propSchema.format === "date" || propSchema.format === "date-time") {
|
|
59
|
+
tdDivProps.className += ` text-${(propConfig === null || propConfig === void 0 ? void 0 : propConfig.align) || "end"}`;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return _jsx("div", Object.assign({}, tdDivProps, { children: row[propName] }));
|
|
63
|
+
}
|
|
64
|
+
export default React.memo(Td);
|
|
@@ -5,6 +5,7 @@ import { localeFormat } from "../inc/date";
|
|
|
5
5
|
import { uncamel } from "../inc/string";
|
|
6
6
|
import Th from "./Th";
|
|
7
7
|
import { SELECT_ALL_COLUMN_NAME, SELECT_ALL_COLUMN_WIDTH } from "./constants";
|
|
8
|
+
import Td from "./Td";
|
|
8
9
|
export default function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, customElement, data, defaultSortAsc = false, defaultSortColumn, getRowClassName, getRowSelected, maxHeight, isSearchable, isSortable, onCheckedIndexesChange, onRowClick, rowHeight = 36, schema, searchPlaceholder, style, width, }) {
|
|
9
10
|
const [sortColumn, setSortColumn] = React.useState(defaultSortColumn);
|
|
10
11
|
const [sortAsc, setSortAsc] = React.useState(defaultSortAsc);
|
|
@@ -226,80 +227,20 @@ export default function SchemaTable({ Heading = VariableSizeList, checkedIndexes
|
|
|
226
227
|
isAllRowsChecked,
|
|
227
228
|
checkedIndexes === null || checkedIndexes === void 0 ? void 0 : checkedIndexes.length,
|
|
228
229
|
]);
|
|
229
|
-
const
|
|
230
|
-
if (!sortedRenderData || !onRowClick) {
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
const { rowIndex } = e.currentTarget.dataset;
|
|
234
|
-
if (!rowIndex) {
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
const row = sortedRenderData[parseInt(rowIndex, 10)];
|
|
238
|
-
onRowClick(data[row._index], row._index, e);
|
|
239
|
-
}, [data, onRowClick, sortedRenderData]);
|
|
240
|
-
const Td = React.useCallback(({ columnIndex, rowIndex, style }) => {
|
|
241
|
-
if (!sortedRenderData) {
|
|
242
|
-
return null;
|
|
243
|
-
}
|
|
230
|
+
const SchemaTableTd = React.useCallback(({ columnIndex, rowIndex, style }) => {
|
|
244
231
|
const propName = columnNames[columnIndex];
|
|
245
|
-
|
|
246
|
-
const row = sortedRenderData[rowIndex];
|
|
247
|
-
const schema = properties[propName];
|
|
248
|
-
const tdDivProps = {
|
|
249
|
-
"data-row-index": rowIndex,
|
|
250
|
-
"data-column-index": columnIndex,
|
|
251
|
-
key: propName,
|
|
252
|
-
style,
|
|
253
|
-
onClick: !(propConfig === null || propConfig === void 0 ? void 0 : propConfig.renderCell) ? onTdClick : undefined,
|
|
254
|
-
className: `schema-table__td schema-table__td--${rowIndex % 2 ? "odd" : "even"}${row && getRowSelected && getRowSelected(data[row._index])
|
|
255
|
-
? " schema-table__td--selected"
|
|
256
|
-
: ""} ${row && getRowClassName
|
|
257
|
-
? getRowClassName(data[row._index], row._index)
|
|
258
|
-
: ""}`,
|
|
259
|
-
};
|
|
260
|
-
if (propConfig === null || propConfig === void 0 ? void 0 : propConfig.renderCell) {
|
|
261
|
-
return (_jsx("div", Object.assign({}, tdDivProps, { children: propConfig.renderCell(data[row._index], row._index, rowIndex) })));
|
|
262
|
-
}
|
|
263
|
-
if (propName === SELECT_ALL_COLUMN_NAME) {
|
|
264
|
-
const onChecked = () => {
|
|
265
|
-
if (!onCheckedIndexesChange) {
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
onCheckedIndexesChange([row._index]);
|
|
269
|
-
};
|
|
270
|
-
return (_jsx("div", Object.assign({}, tdDivProps, { children: _jsx("div", Object.assign({ style: { textAlign: "center" } }, { children: _jsx("input", { type: "checkbox", onChange: onChecked, checked: checkedIndexes === null || checkedIndexes === void 0 ? void 0 : checkedIndexes.includes(row._index) }) })) })));
|
|
271
|
-
}
|
|
272
|
-
if (!schema) {
|
|
273
|
-
return null;
|
|
274
|
-
}
|
|
275
|
-
// @ts-ignore
|
|
276
|
-
switch (schema.type) {
|
|
277
|
-
case "boolean":
|
|
278
|
-
tdDivProps.className += ` text-${(propConfig === null || propConfig === void 0 ? void 0 : propConfig.align) || "center"}`;
|
|
279
|
-
break;
|
|
280
|
-
case "number":
|
|
281
|
-
case "integer":
|
|
282
|
-
tdDivProps.className += ` text-${(propConfig === null || propConfig === void 0 ? void 0 : propConfig.align) || "end"}`;
|
|
283
|
-
break;
|
|
284
|
-
case "string":
|
|
285
|
-
// @ts-ignore
|
|
286
|
-
tdDivProps.title = row[propName];
|
|
287
|
-
if (schema.format === "date" || schema.format === "date-time") {
|
|
288
|
-
tdDivProps.className += ` text-${(propConfig === null || propConfig === void 0 ? void 0 : propConfig.align) || "end"}`;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
return _jsx("div", Object.assign({}, tdDivProps, { children: row[propName] }));
|
|
232
|
+
return (_jsx(Td, { checkedIndexes: checkedIndexes, columnIndex: columnIndex, data: data, getRowClassName: getRowClassName, getRowSelected: getRowSelected, onCheckedIndexesChange: onCheckedIndexesChange, propConfig: config ? config[propName] : undefined, propName: propName, propSchema: properties[propName], rowHeight: rowHeight, rowIndex: rowIndex, sortedRenderData: sortedRenderData, style: style }));
|
|
292
233
|
}, [
|
|
293
|
-
|
|
234
|
+
checkedIndexes,
|
|
294
235
|
columnNames,
|
|
295
236
|
config,
|
|
296
|
-
properties,
|
|
297
|
-
onTdClick,
|
|
298
|
-
getRowSelected,
|
|
299
237
|
data,
|
|
300
238
|
getRowClassName,
|
|
301
|
-
|
|
239
|
+
getRowSelected,
|
|
302
240
|
onCheckedIndexesChange,
|
|
241
|
+
properties,
|
|
242
|
+
rowHeight,
|
|
243
|
+
sortedRenderData,
|
|
303
244
|
]);
|
|
304
245
|
const onSearchChange = React.useCallback((e) => {
|
|
305
246
|
setSearchQuery(e.currentTarget.value);
|
|
@@ -314,5 +255,5 @@ export default function SchemaTable({ Heading = VariableSizeList, checkedIndexes
|
|
|
314
255
|
? rowsMaxHeight
|
|
315
256
|
: rowsHeight;
|
|
316
257
|
}, [maxHeight, isSearchable, rowCount, rowHeight]);
|
|
317
|
-
return (_jsxs("div", Object.assign({ className: `schema-table${onRowClick ? " schema-table--clickable-rows" : ""}`, style: Object.assign(Object.assign({}, style), { width: rowWidth }) }, { children: [_jsxs("div", Object.assign({ className: "
|
|
258
|
+
return (_jsxs("div", Object.assign({ className: `schema-table${onRowClick ? " schema-table--clickable-rows" : ""}`, style: Object.assign(Object.assign({}, style), { width: rowWidth }) }, { children: [_jsxs("div", Object.assign({ className: "schema-table__action-container" }, { children: [_jsx("div", Object.assign({ style: { flex: 1 } }, { children: isSearchable ? (_jsx("input", { type: "text", placeholder: searchPlaceholder || "Search...", value: searchQuery, onChange: onSearchChange, autoFocus: true })) : null })), customElement] })), _jsx(Heading, Object.assign({ height: 50, itemCount: columnCount, itemSize: getColumnWidth, layout: "horizontal", width: rowWidth, sortAsc: sortAsc, setSortAsc: setSortAsc, setSortColumn: setSortColumn, sortColumn: sortColumn, sortedRenderData: sortedRenderData, className: "schema-table__th-row" }, { children: SchemaTableTh }), `thead_${rowWidth}_${sortColumn}_${sortAsc}_${searchQuery}`), _jsx(VariableSizeGrid, Object.assign({ className: "schema-table__tbody", height: tableBodyHeight, width: rowWidth, columnWidth: getColumnWidth, rowHeight: getRowHeight, columnCount: columnCount, rowCount: rowCount }, { children: SchemaTableTd }), `tbody_${rowWidth}_${sortColumn}_${sortAsc}_${searchQuery}_${columnCount}`)] })));
|
|
318
259
|
}
|
package/dist/index.css
CHANGED
|
@@ -10,11 +10,14 @@
|
|
|
10
10
|
overflow: hidden !important;
|
|
11
11
|
}
|
|
12
12
|
.schema-table__th {
|
|
13
|
-
overflow: hidden;
|
|
14
13
|
background-color: #eee;
|
|
15
|
-
padding-left: 8px;
|
|
16
14
|
align-items: center;
|
|
17
15
|
}
|
|
16
|
+
.schema-table__th div {
|
|
17
|
+
overflow: hidden;
|
|
18
|
+
white-space: nowrap;
|
|
19
|
+
text-overflow: ellipsis;
|
|
20
|
+
}
|
|
18
21
|
.schema-table__th,
|
|
19
22
|
.schema-table__th button {
|
|
20
23
|
font-weight: bold;
|
|
@@ -29,7 +32,6 @@
|
|
|
29
32
|
text-overflow: ellipsis;
|
|
30
33
|
padding-left: 8px;
|
|
31
34
|
align-items: center;
|
|
32
|
-
line-height: 40px;
|
|
33
35
|
}
|
|
34
36
|
.schema-table__td--odd {
|
|
35
37
|
background-color: #ddd;
|
|
@@ -46,7 +48,6 @@
|
|
|
46
48
|
}
|
|
47
49
|
.schema-table__search input {
|
|
48
50
|
width: 100%;
|
|
49
|
-
line-height: 20px;
|
|
50
51
|
}
|
|
51
52
|
.schema-table--clickable-rows .schema-table__td {
|
|
52
53
|
cursor: pointer;
|
|
@@ -54,16 +55,13 @@
|
|
|
54
55
|
.schema-table button {
|
|
55
56
|
border: 1px solid transparent;
|
|
56
57
|
}
|
|
57
|
-
.schema-
|
|
58
|
+
.schema-table__action-container {
|
|
58
59
|
display: flex;
|
|
59
60
|
flex-direction: row;
|
|
61
|
+
padding-bottom: 1rem;
|
|
60
62
|
}
|
|
61
|
-
.schema-
|
|
63
|
+
.schema-table__action-container input {
|
|
62
64
|
width: 30%;
|
|
63
65
|
border-radius: 8px;
|
|
64
66
|
padding: 4px 10px;
|
|
65
67
|
}
|
|
66
|
-
.schema-table .action-container img {
|
|
67
|
-
margin-right: 1.5rem;
|
|
68
|
-
margin-top: 5px;
|
|
69
|
-
}
|