mig-schema-table 1.0.6 → 1.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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { uncamel } from "../../../inc/string";
|
|
4
4
|
const Th = ({ columnFilters, config, isSortable, name, schema, setColumnFilters, setSortAsc, setSortColumn, sortAsc, style, }) => {
|
|
5
5
|
const thDivProps = {
|
|
6
6
|
style,
|
|
@@ -39,6 +39,6 @@ const Th = ({ columnFilters, config, isSortable, name, schema, setColumnFilters,
|
|
|
39
39
|
thDivProps.className += ` text-${(config === null || config === void 0 ? void 0 : config.align) || "end"}`;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
return (_jsxs("div", Object.assign({}, thDivProps, { children: [isSortable ? (_jsxs("button", Object.assign({ className: "px-0", disabled: (config === null || config === void 0 ? void 0 : config.sortable) === false, onClick: onSortButtonClick }, { children: [(config === null || config === void 0 ? void 0 : config.title) ||
|
|
42
|
+
return (_jsxs("div", Object.assign({}, thDivProps, { children: [isSortable ? (_jsxs("button", Object.assign({ className: "px-0", disabled: (config === null || config === void 0 ? void 0 : config.sortable) === false, onClick: onSortButtonClick }, { children: [(config === null || config === void 0 ? void 0 : config.title) || uncamel(name), sortAsc === undefined ? null : sortAsc ? "▲" : "▼"] }))) : (_jsx("div", Object.assign({ style: { lineHeight: "44px" } }, { children: (config === null || config === void 0 ? void 0 : config.title) || uncamel(name) }))), (config === null || config === void 0 ? void 0 : config.isFilterable) ? (_jsx("button", Object.assign({ onClick: onFilterButtonClick }, { children: _jsx("svg", Object.assign({ viewBox: "0 0 36 36", xmlns: "http://www.w3.org/2000/svg", height: 16, width: 16, style: { display: "block" } }, { children: _jsx("polygon", { fill: "#231F20", points: "14,30 22,25 22,17 35.999,0 17.988,0 0,0 14,17 " }) })) }))) : null] })));
|
|
43
43
|
};
|
|
44
44
|
export default React.memo(Th);
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { VariableSizeList, VariableSizeGrid } from "react-window";
|
|
4
4
|
import { localeFormat } from "../../inc/date";
|
|
5
|
-
import {
|
|
5
|
+
import { uncamel } from "../../inc/string";
|
|
6
6
|
import Th from "./Th";
|
|
7
7
|
export default function SchemaTableComponent(props) {
|
|
8
8
|
const { config, data, defaultSortColumn, defaultSortAsc = false, Heading = VariableSizeList, isSearchable, isSortable, onRowClick, getRowClassName, getRowSelected, rowHeight = 36, schema, style, customElement, tableTitle, searchPlaceholder } = props;
|
|
@@ -81,7 +81,7 @@ export default function SchemaTableComponent(props) {
|
|
|
81
81
|
return prev;
|
|
82
82
|
}
|
|
83
83
|
if (schema.enum) {
|
|
84
|
-
prev[propName] =
|
|
84
|
+
prev[propName] = uncamel(rawValue);
|
|
85
85
|
return prev;
|
|
86
86
|
}
|
|
87
87
|
// fallthrough
|
|
@@ -260,5 +260,5 @@ export default function SchemaTableComponent(props) {
|
|
|
260
260
|
const totalWidth = React.useMemo(() => columnWidths.reduce((a, b) => {
|
|
261
261
|
return a + b;
|
|
262
262
|
}, 0), [columnWidths]);
|
|
263
|
-
return (_jsxs("div", Object.assign({ className: `schema-table${onRowClick ? " schema-table--clickable-rows" : ""}`, style: Object.assign(Object.assign({}, style), { width: dynamicWidthColumnCount ? gridWidth : fixedWidthColumnsWidth }) }, { children: [_jsx("div", Object.assign({ className: "tableTitle" }, { children: tableTitle })), _jsxs("div", Object.assign({ className: "form-action-container" }, { children: [_jsx("div", Object.assign({ className: "flex-1" }, { children: isSearchable ? (_jsx("input", { id: "input-filter", type: "text", placeholder: searchPlaceholder, value: searchQuery, onChange: onSearchChange, autoFocus: true })) : null })), customElement] })), _jsx(Heading, Object.assign({ height: 50, itemCount: columnCount, itemSize: getColumnWidth, layout: "horizontal", width: width, sortAsc: sortAsc, setSortAsc: setSortAsc, setSortColumn: setSortColumn, sortColumn: sortColumn, sortedRenderData: sortedRenderData }, { children: SchemaTableTh }), `thead_${width}_${sortColumn}_${sortAsc}_${searchQuery}`), _jsx(VariableSizeGrid, Object.assign({ className: "schema-table__tbody", height: props.height - (isSearchable ? 50 : 0), width: totalWidth, columnWidth: getColumnWidth, rowHeight: getRowHeight, columnCount: columnCount, rowCount: sortedRenderData ? sortedRenderData.length : 0 }, { children: Td }), `tbody_${width}_${sortColumn}_${sortAsc}_${searchQuery}_${columnCount}`)] })));
|
|
263
|
+
return (_jsxs("div", Object.assign({ className: `schema-table${onRowClick ? " schema-table--clickable-rows" : ""}`, style: Object.assign(Object.assign({}, style), { width: dynamicWidthColumnCount ? gridWidth : fixedWidthColumnsWidth }) }, { children: [_jsx("div", Object.assign({ className: "tableTitle" }, { children: tableTitle })), _jsxs("div", Object.assign({ className: "form-action-container" }, { children: [_jsx("div", Object.assign({ className: "flex-1" }, { children: isSearchable ? (_jsx("input", { id: "input-filter", type: "text", placeholder: searchPlaceholder, value: searchQuery, onChange: onSearchChange, autoFocus: true })) : null })), customElement] })), _jsx(Heading, Object.assign({ height: 50, itemCount: columnCount, itemSize: getColumnWidth, layout: "horizontal", width: width, sortAsc: sortAsc, setSortAsc: setSortAsc, setSortColumn: setSortColumn, sortColumn: sortColumn, sortedRenderData: sortedRenderData, className: "schema-table__th-row" }, { children: SchemaTableTh }), `thead_${width}_${sortColumn}_${sortAsc}_${searchQuery}`), _jsx(VariableSizeGrid, Object.assign({ className: "schema-table__tbody", height: props.height - (isSearchable ? 50 : 0), width: totalWidth, columnWidth: getColumnWidth, rowHeight: getRowHeight, columnCount: columnCount, rowCount: sortedRenderData ? sortedRenderData.length : 0 }, { children: Td }), `tbody_${width}_${sortColumn}_${sortAsc}_${searchQuery}_${columnCount}`)] })));
|
|
264
264
|
}
|
package/build/inc/string.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare
|
|
1
|
+
export declare function uncamel(camel: string): string;
|
package/build/inc/string.js
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return
|
|
4
|
-
}
|
|
1
|
+
import { upperFirst } from "lodash";
|
|
2
|
+
function isUpperCase(letter) {
|
|
3
|
+
return !!letter.match(/[A-Z]/);
|
|
4
|
+
}
|
|
5
|
+
export function uncamel(camel) {
|
|
6
|
+
return upperFirst(camel.replaceAll(/[A-Z]/g, (letter, position) => {
|
|
7
|
+
const prevLetter = camel[position - 1];
|
|
8
|
+
const prevIsUppercase = prevLetter ? isUpperCase(prevLetter) : false;
|
|
9
|
+
const nextLetter = camel[position + 1];
|
|
10
|
+
const nextIsUppercase = nextLetter ? isUpperCase(nextLetter) : false;
|
|
11
|
+
if (position === 0 ||
|
|
12
|
+
(prevIsUppercase && (!nextLetter || nextIsUppercase))) {
|
|
13
|
+
return letter;
|
|
14
|
+
}
|
|
15
|
+
return ` ${nextIsUppercase ? letter : letter.toLowerCase()}`;
|
|
16
|
+
}));
|
|
17
|
+
}
|