mig-schema-table 3.0.7 → 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.
@@ -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 onTdClick = React.useCallback((e) => {
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
- const propConfig = config ? config[propName] : undefined;
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
- sortedRenderData,
234
+ checkedIndexes,
294
235
  columnNames,
295
236
  config,
296
- properties,
297
- onTdClick,
298
- getRowSelected,
299
237
  data,
300
238
  getRowClassName,
301
- checkedIndexes,
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: "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: Td }), `tbody_${rowWidth}_${sortColumn}_${sortAsc}_${searchQuery}_${columnCount}`)] })));
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
@@ -32,7 +32,6 @@
32
32
  text-overflow: ellipsis;
33
33
  padding-left: 8px;
34
34
  align-items: center;
35
- line-height: 40px;
36
35
  }
37
36
  .schema-table__td--odd {
38
37
  background-color: #ddd;
@@ -49,7 +48,6 @@
49
48
  }
50
49
  .schema-table__search input {
51
50
  width: 100%;
52
- line-height: 20px;
53
51
  }
54
52
  .schema-table--clickable-rows .schema-table__td {
55
53
  cursor: pointer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mig-schema-table",
3
- "version": "3.0.7",
3
+ "version": "3.0.8",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist/"