mig-schema-table 4.0.4 → 4.0.6

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/style.css ADDED
@@ -0,0 +1 @@
1
+ .mig-schema-table,.mig-schema-table *{box-sizing:border-box}.mig-schema-table button{border:1px solid #e4e4e4;padding:8px}.mig-schema-table button:enabled{background-color:#f6f6f6;color:#404040}.mig-schema-table button:enabled:hover{border-color:#dbdbdb;background-color:#ececec}.mig-schema-table input{padding:8px;border:1px solid #888}.mig-schema-table input:hover{border-color:#add8e6}.mig-schema-table select{height:33px}.mig-schema-table__custom_element_placeholder{flex:1}.mig-schema-table__tbody{overflow-x:hidden!important;border-collapse:collapse;width:100%}.mig-schema-table__th-row{overflow:hidden!important}.mig-schema-table--clickable-rows .mig-schema-table__td{cursor:pointer}.mig-schema-table__action-container{display:flex;flex-direction:row;padding:.5rem;align-items:center}.mig-schema-table__row_counter{margin-left:8px;font-size:.835rem}.mig-schema-table__column_resize_container{position:relative}.mig-schema-table__th{background-color:#fcfcfc;border-right:1px solid #ddd;border-top:1px solid #ddd;border-bottom:1px solid #ddd;color:#666;display:flex;align-items:center;padding-left:8px;padding-right:8px;-webkit-user-select:none;user-select:none}.mig-schema-table__th:first-child{border-left:1px solid #ddd}.mig-schema-table__th div{overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.mig-schema-table__th--sorted{background-color:#eff6fb}.mig-schema-table__th--dragging{opacity:.5}.mig-schema-table__th--dragging .mig-schema-table__th__trigger-el{display:none!important}.mig-schema-table__th--drop-target{border-right:3px dashed green}.mig-schema-table__th--drop-target .mig-schema-table__th__trigger-el{display:none!important}.mig-schema-table__th--filter-ACTIVE .mig-schema-table__th__label-body-text{text-decoration:underline;font-style:italic}.mig-schema-table__th__label-body{display:flex;flex:1;font-size:14px;align-items:center}.mig-schema-table__th__label-body-text{overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.mig-schema-table__th__trigger-el{display:none;position:absolute;border:1px solid #ddd;top:0;right:0;bottom:0;width:24px;cursor:pointer;background-color:#eff6fb;color:#666;font-size:28px;text-align:center;padding:5px 0 0!important}.mig-schema-table__th__sort-icon{font-size:24px;width:32px;display:block;text-align:center}.mig-schema-table__th:hover{background-color:#eff6fb}.mig-schema-table__th:hover .mig-schema-table__th__trigger-el{display:block!important}.mig-schema-table__th svg{vertical-align:baseline}.mig-schema-table__th-menu{background-color:#fff;z-index:99999}.mig-schema-table__th-menu label{flex:1}.mig-schema-table__th-menu .mig-schema-table__th-menu__sub-menu-indicator{padding-left:8px;margin-left:8px}.mig-schema-table__th-menu__icon{display:block;width:24px;overflow:hidden;text-align:center}.mig-schema-table__th-menu__sub-menu{background-color:#fff;border:1px solid #ddd;z-index:99999}.mig-schema-table-menu{font-size:14px;list-style:none outside;padding:0;margin:0}.mig-schema-table-menu li{display:flex;border:1px solid #ddd;align-items:center;cursor:pointer}.mig-schema-table-menu li .react-datepicker{width:20.5rem}.mig-schema-table-menu li:hover{background-color:#eff6fb}.mig-schema-table__td{overflow:hidden;white-space:nowrap;text-overflow:ellipsis;padding-left:8px;padding-right:8px;align-content:center}.mig-schema-table__td--odd{background-color:var(--bs-gray-100, #f8f9fa)}.mig-schema-table__td--even{background-color:var(--bs-white, #fff)}.mig-schema-table__td--selected{background-color:var(--bs-gray-300, #dee2e6)}.mig-schema-table__column_resizer{position:absolute;top:0;-webkit-user-select:none;user-select:none;background-color:transparent;cursor:e-resize;width:3px}.mig-schema-table__column_resizer--dragged,.mig-schema-table__column_resizer:hover{background-color:#bbb;bottom:0!important}
package/package.json CHANGED
@@ -1,83 +1,70 @@
1
1
  {
2
2
  "name": "mig-schema-table",
3
- "version": "4.0.4",
4
- "main": "dist/index.js",
3
+ "version": "4.0.6",
5
4
  "files": [
6
- "dist/"
5
+ "dist"
7
6
  ],
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/mig-schema-table.es.js",
10
+ "require": "./dist/mig-schema-table.umd.js"
11
+ },
12
+ "./dist/style.css": "./dist/style.css"
13
+ },
14
+ "main": "./dist/mig-schema-table.umd.js",
15
+ "module": "./dist/mig-schema-table.es.js",
8
16
  "types": "./dist/index.d.ts",
9
17
  "private": false,
18
+ "scripts": {
19
+ "dev": "vite",
20
+ "build": "tsc && vite build",
21
+ "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
22
+ "preview": "vite preview"
23
+ },
10
24
  "dependencies": {
11
- "@types/file-saver": "^2.0.7",
12
- "@types/jest": "^27.5.2",
13
- "@types/react": "^18.2.6",
14
- "@types/react-datepicker": "^4.11.2",
15
- "@types/react-dom": "^18.2.4",
16
- "date-fns": "^2.30.0",
17
- "date-fns-tz": "^2.0.0",
25
+ "date-fns": "^3.6.0",
26
+ "date-fns-tz": "^3.1.3",
18
27
  "exceljs": "^4.4.0",
19
28
  "file-saver": "^2.0.5",
20
29
  "lodash": "^4.17.21",
21
- "openapi3-ts": "^4.1.2",
22
- "react": "^18.2.0",
23
- "react-datepicker": "^6.2.0",
24
- "react-dom": "^18.2.0",
30
+ "react-datepicker": "^6.9.0",
25
31
  "react-popper": "^2.3.0",
26
- "react-scripts": "5.0.1",
27
- "react-window": "^1.8.9"
28
- },
29
- "scripts": {
30
- "build": "rm -rf dist; tsc -p tsconfig.json; sass --no-source-map src/component/index.scss dist/index.css",
31
- "prepublishOnly": "npm run build",
32
- "start": "react-scripts start",
33
- "test": "react-scripts test",
34
- "storybook": "storybook dev -p 6006",
35
- "build-storybook": "storybook build"
36
- },
37
- "eslintConfig": {
38
- "extends": [
39
- "react-app",
40
- "react-app/jest",
41
- "plugin:storybook/recommended"
42
- ]
43
- },
44
- "browserslist": {
45
- "production": [
46
- ">0.2%",
47
- "not dead",
48
- "not op_mini all"
49
- ],
50
- "development": [
51
- "last 1 chrome version",
52
- "last 1 firefox version",
53
- "last 1 safari version"
54
- ]
32
+ "react-window": "^1.8.10"
55
33
  },
56
34
  "devDependencies": {
57
- "@chromatic-com/storybook": "^1.3.3",
58
- "@storybook/addon-essentials": "^8.0.8",
59
- "@storybook/addon-interactions": "^8.0.8",
60
- "@storybook/addon-links": "^8.0.8",
61
- "@storybook/addon-onboarding": "^8.0.8",
62
- "@storybook/blocks": "^8.0.8",
63
- "@storybook/preset-create-react-app": "^8.0.8",
64
- "@storybook/react": "^8.0.8",
65
- "@storybook/react-webpack5": "^8.0.8",
66
- "@storybook/test": "^8.0.8",
67
- "@testing-library/jest-dom": "^5.16.5",
68
- "@testing-library/react": "^13.4.0",
35
+ "@chromatic-com/storybook": "^1.4.0",
36
+ "@storybook/addon-essentials": "^8.1.2",
37
+ "@storybook/addon-interactions": "^8.1.2",
38
+ "@storybook/addon-links": "^8.1.2",
39
+ "@storybook/addon-onboarding": "^8.1.2",
40
+ "@storybook/blocks": "^8.1.2",
41
+ "@storybook/react": "^8.1.2",
42
+ "@storybook/test": "^8.1.2",
43
+ "@testing-library/jest-dom": "^6.4.5",
44
+ "@testing-library/react": "^15.0.7",
69
45
  "@types/date-fns": "^2.6.0",
70
- "@types/lodash": "^4.14.194",
71
- "@types/node": "^20.12.5",
72
- "@types/react-window": "^1.8.5",
73
- "axios": "^1.4.0",
74
- "eslint-plugin-storybook": "^0.8.0",
75
- "prettier": "^2.8.8",
76
- "prop-types": "^15.8.1",
77
- "react-router-dom": "^6.11.2",
78
- "sass": "^1.62.1",
79
- "storybook": "^8.0.8",
80
- "typescript": "^4.9.5",
81
- "webpack": "^5.91.0"
46
+ "@types/file-saver": "^2.0.7",
47
+ "@types/jest": "^29.5.12",
48
+ "@types/lodash": "^4.17.4",
49
+ "@types/react": "^18.2.66",
50
+ "@types/react-datepicker": "^6.2.0",
51
+ "@types/react-dom": "^18.2.22",
52
+ "@types/react-window": "^1.8.8",
53
+ "@typescript-eslint/eslint-plugin": "^7.2.0",
54
+ "@typescript-eslint/parser": "^7.2.0",
55
+ "@vitejs/plugin-react-swc": "^3.5.0",
56
+ "eslint": "^8.57.0",
57
+ "eslint-plugin-react-hooks": "^4.6.0",
58
+ "eslint-plugin-react-refresh": "^0.4.6",
59
+ "openapi3-ts": "^4.3.1",
60
+ "prettier": "^3.2.5",
61
+ "sass": "^1.77.2",
62
+ "typescript": "^5.2.2",
63
+ "vite": "^5.2.0",
64
+ "vite-plugin-dts": "^3.9.1"
65
+ },
66
+ "peerDependencies": {
67
+ "react": "^18.2.0",
68
+ "react-dom": "^18.2.0"
82
69
  }
83
70
  }
@@ -1,9 +0,0 @@
1
- interface IColumnResizersProps {
2
- columnWidths: number[];
3
- onColumnWidthsChange: (newColumnWidths: number[]) => void;
4
- resizeColumnIndex: number;
5
- setResizeColumnIndex: (newResizeColumnIndex: number) => void;
6
- tableBodyHeight: number;
7
- }
8
- declare const ColumnResizers: ({ columnWidths, onColumnWidthsChange, resizeColumnIndex, setResizeColumnIndex, tableBodyHeight, }: IColumnResizersProps) => import("react/jsx-runtime").JSX.Element;
9
- export default ColumnResizers;
@@ -1,34 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import React from "react";
3
- import { COLUMN_WIDTH, MINIMUM_COLUMN_WIDTH } from "../../inc/constant";
4
- const ColumnResizers = ({ columnWidths, onColumnWidthsChange, resizeColumnIndex, setResizeColumnIndex, tableBodyHeight, }) => {
5
- const [dragStartX, setDragStartX] = React.useState(0);
6
- const setColumnDelta = React.useCallback((columnDelta) => {
7
- const newColumnWidths = columnWidths.map((columnWidth, columnWidthIndex) => {
8
- if (columnWidthIndex === resizeColumnIndex) {
9
- return Math.max(columnWidth + columnDelta, MINIMUM_COLUMN_WIDTH);
10
- }
11
- return columnWidth;
12
- });
13
- onColumnWidthsChange(newColumnWidths);
14
- }, [columnWidths, resizeColumnIndex, onColumnWidthsChange]);
15
- let pointer = 0;
16
- const onDragStart = React.useCallback((e) => {
17
- setResizeColumnIndex(parseInt(e.currentTarget.dataset.columnIndex));
18
- setDragStartX(e.clientX);
19
- }, [setResizeColumnIndex]);
20
- const onDragEnd = React.useCallback((e) => {
21
- setColumnDelta(e.clientX - dragStartX);
22
- setDragStartX(0);
23
- setResizeColumnIndex(-1);
24
- }, [dragStartX, setColumnDelta, setResizeColumnIndex]);
25
- return (_jsx("div", { children: columnWidths.map((columnWidth, columnIndex) => {
26
- pointer += columnWidth;
27
- const classNames = ["mig-schema-table__column_resizer"];
28
- if (columnIndex === resizeColumnIndex) {
29
- classNames.push("mig-schema-table__column_resizer--dragged");
30
- }
31
- return (_jsx("div", { style: { left: pointer - COLUMN_WIDTH, bottom: tableBodyHeight }, className: classNames.join(" "), draggable: "true", "data-column-index": columnIndex, onDragStart: onDragStart, onDragEnd: onDragEnd }, columnIndex));
32
- }) }));
33
- };
34
- export default ColumnResizers;
@@ -1,24 +0,0 @@
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
- disabledCheckedIndexes?: number[];
7
- columnIndex: number;
8
- data: T[];
9
- getRowClassName?: (rowData: T, dataIndex: number, filteredSortedData: IRenderData[]) => string;
10
- getRowSelected?: (rowData: T, dataIndex: number) => boolean;
11
- rowIndex: number;
12
- onCheckedIndexesChange?: (dataIndex: number[]) => void;
13
- onRowClick?: (rowData: T, dataIndex: number, event: React.MouseEvent) => void;
14
- onRowDoubleClick?: (rowData: T, dataIndex: number, event: React.MouseEvent) => void;
15
- propConfig?: IColumnConfig<any>;
16
- propName: string;
17
- propSchema?: oas31.SchemaObject;
18
- sortedRenderData?: IRenderData[];
19
- style: React.CSSProperties;
20
- translate: (key: string, ...args: Array<string | number>) => string;
21
- }
22
- declare function Td<T>({ checkedIndexes, disabledCheckedIndexes, columnIndex, data, getRowClassName, getRowSelected, onCheckedIndexesChange, onRowClick, onRowDoubleClick, propConfig, propName, propSchema, rowIndex, sortedRenderData, style, translate, }: ITdProps<T>): import("react/jsx-runtime").JSX.Element | null;
23
- declare const _default: typeof Td;
24
- export default _default;
@@ -1,121 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import React from "react";
3
- import { SELECT_ALL_COLUMN_NAME } from "../constants";
4
- import { localeFormatInTimeZone, timeZone } from "../../inc/date";
5
- import { DEFAULT_DATE_TIME_FORMAT } from "../../inc/constant";
6
- function Td({ checkedIndexes, disabledCheckedIndexes, columnIndex, data, getRowClassName, getRowSelected, onCheckedIndexesChange, onRowClick, onRowDoubleClick, propConfig, propName, propSchema, rowIndex, sortedRenderData, style, translate, }) {
7
- const onTdClick = React.useCallback((e) => {
8
- if (!sortedRenderData || !onRowClick) {
9
- return;
10
- }
11
- const { rowIndex } = e.currentTarget.dataset;
12
- if (!rowIndex) {
13
- return;
14
- }
15
- const row = sortedRenderData[parseInt(rowIndex, 10)];
16
- onRowClick(data[row._index], row._index, e);
17
- }, [data, onRowClick, sortedRenderData]);
18
- const onTdDoubleClick = React.useCallback((e) => {
19
- if (!sortedRenderData || !onRowDoubleClick) {
20
- return;
21
- }
22
- const { rowIndex } = e.currentTarget.dataset;
23
- if (!rowIndex) {
24
- return;
25
- }
26
- const row = sortedRenderData[parseInt(rowIndex, 10)];
27
- onRowDoubleClick(data[row._index], row._index, e);
28
- }, [data, onRowDoubleClick, sortedRenderData]);
29
- const row = sortedRenderData ? sortedRenderData[rowIndex] : undefined;
30
- const { showTimezones, TdBody } = propConfig || {};
31
- const tdDivProps = React.useMemo(() => {
32
- if (!row || !sortedRenderData) {
33
- return undefined;
34
- }
35
- let title = propName === SELECT_ALL_COLUMN_NAME ? null : row[propName];
36
- if ((propSchema === null || propSchema === void 0 ? void 0 : propSchema.format) &&
37
- propSchema.format === "date-time" &&
38
- showTimezones !== false) {
39
- // @ts-ignore
40
- const dateString = data[row._index][propName];
41
- const date = dateString ? new Date(dateString) : undefined;
42
- const alternativeTimeZone = timeZone.startsWith("Europe/")
43
- ? "Asia/Jakarta"
44
- : "Europe/Amsterdam";
45
- if (date) {
46
- title = `${localeFormatInTimeZone(date, alternativeTimeZone, DEFAULT_DATE_TIME_FORMAT)} (${translate(alternativeTimeZone)})`;
47
- }
48
- }
49
- const classNames = [
50
- "mig-schema-table__td",
51
- `mig-schema-table__td--${rowIndex % 2 ? "odd" : "even"}`,
52
- `mig-schema-table__td--prop-${propName}`,
53
- ];
54
- if (getRowSelected && getRowSelected(data[row._index], row._index)) {
55
- classNames.push("mig-schema-table__td--selected");
56
- }
57
- if (getRowClassName) {
58
- classNames.push(getRowClassName(data[row._index], row._index, sortedRenderData));
59
- }
60
- return {
61
- "data-row-index": rowIndex,
62
- "data-column-index": columnIndex,
63
- style,
64
- onClick: onTdClick,
65
- onDoubleClick: onTdDoubleClick,
66
- className: classNames.join(" "),
67
- title,
68
- };
69
- }, [
70
- columnIndex,
71
- data,
72
- getRowClassName,
73
- getRowSelected,
74
- onTdClick,
75
- onTdDoubleClick,
76
- showTimezones,
77
- propName,
78
- propSchema === null || propSchema === void 0 ? void 0 : propSchema.format,
79
- row,
80
- rowIndex,
81
- sortedRenderData,
82
- style,
83
- translate,
84
- ]);
85
- if (!row || !tdDivProps) {
86
- return null;
87
- }
88
- if (TdBody) {
89
- return (_jsx("div", Object.assign({}, tdDivProps, { children: _jsx(TdBody, { dataIndex: row._index, rowData: data[row._index], rowIndex: rowIndex }) })));
90
- }
91
- if (propName === SELECT_ALL_COLUMN_NAME) {
92
- const onChecked = () => {
93
- if (!onCheckedIndexesChange) {
94
- return;
95
- }
96
- onCheckedIndexesChange([row._index]);
97
- };
98
- return (_jsx("div", Object.assign({}, tdDivProps, { children: _jsx("div", Object.assign({ style: { textAlign: "center" } }, { children: _jsx("input", { "data-key": "row-checkbox", type: "checkbox", onChange: onChecked, checked: checkedIndexes === null || checkedIndexes === void 0 ? void 0 : checkedIndexes.includes(row._index), disabled: disabledCheckedIndexes === null || disabledCheckedIndexes === void 0 ? void 0 : disabledCheckedIndexes.includes(row._index) }) })) })));
99
- }
100
- const propValue = row[propName];
101
- switch (propSchema === null || propSchema === void 0 ? void 0 : propSchema.type) {
102
- case "boolean":
103
- tdDivProps.className += ` text-${(propConfig === null || propConfig === void 0 ? void 0 : propConfig.align) || "center"}`;
104
- break;
105
- case "number":
106
- case "integer":
107
- tdDivProps.className += ` text-${(propConfig === null || propConfig === void 0 ? void 0 : propConfig.align) || "end"}`;
108
- break;
109
- default:
110
- if (propConfig === null || propConfig === void 0 ? void 0 : propConfig.align) {
111
- tdDivProps.className += ` text-${propConfig.align}`;
112
- }
113
- if ((propSchema === null || propSchema === void 0 ? void 0 : propSchema.format) === "url" && propValue) {
114
- return (
115
- // @ts-ignore
116
- _jsx("a", Object.assign({ href: propValue, target: "_blank", rel: "noopener noreferrer" }, tdDivProps, { children: propValue })));
117
- }
118
- }
119
- return _jsx("div", Object.assign({}, tdDivProps, { children: propValue }));
120
- }
121
- export default React.memo(Td);
@@ -1,29 +0,0 @@
1
- import { oas31 } from "openapi3-ts";
2
- import React, { CSSProperties, Dispatch, SetStateAction } from "react";
3
- import { IColumnConfig } from "../../types";
4
- import { IThMenuConfig } from "../ThMenu";
5
- export declare enum EColumnFilterStatus {
6
- UNAVAILABLE = "UNAVAILABLE",
7
- AVAILABLE = "AVAILABLE",
8
- ACTIVE = "ACTIVE"
9
- }
10
- interface IThProps {
11
- columnFilterStatus: EColumnFilterStatus;
12
- isAllChecked?: boolean;
13
- isSortable: boolean;
14
- numberOfSelectedRows?: number;
15
- onColumnPositionChange?: (sourceColumnName: string, destinationColumnName: string) => void;
16
- onSelectAllIndexesHandler?: (e: React.ChangeEvent<HTMLInputElement>) => void;
17
- propConfig?: IColumnConfig<any>;
18
- propIsRequired: boolean;
19
- propName: string;
20
- schema?: oas31.SchemaObject;
21
- setMenuConfig: Dispatch<SetStateAction<IThMenuConfig | undefined>>;
22
- setSortAsc: Dispatch<SetStateAction<boolean>>;
23
- setSortColumn: Dispatch<SetStateAction<string>>;
24
- sortAsc?: boolean;
25
- style: CSSProperties;
26
- translate: (key: string, ...args: Array<string | number>) => string;
27
- }
28
- declare const _default: ({ columnFilterStatus, isAllChecked, isSortable, numberOfSelectedRows, onColumnPositionChange, onSelectAllIndexesHandler, propConfig, propIsRequired, propName, schema, setMenuConfig, setSortAsc, setSortColumn, sortAsc, style, translate, }: IThProps) => import("react/jsx-runtime").JSX.Element;
29
- export default _default;
@@ -1,133 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import React from "react";
3
- import { SELECT_ALL_COLUMN_NAME } from "../constants";
4
- import { timeZone } from "../../inc/date";
5
- export var EColumnFilterStatus;
6
- (function (EColumnFilterStatus) {
7
- EColumnFilterStatus["UNAVAILABLE"] = "UNAVAILABLE";
8
- EColumnFilterStatus["AVAILABLE"] = "AVAILABLE";
9
- EColumnFilterStatus["ACTIVE"] = "ACTIVE";
10
- })(EColumnFilterStatus || (EColumnFilterStatus = {}));
11
- const Th = ({ columnFilterStatus, isAllChecked, isSortable, numberOfSelectedRows, onColumnPositionChange, onSelectAllIndexesHandler, propConfig, propIsRequired, propName, schema, setMenuConfig, setSortAsc, setSortColumn, sortAsc, style, translate, }) => {
12
- const [isDragging, setIsDragging] = React.useState(false);
13
- const [isDropTarget, setIsDropTarget] = React.useState(false);
14
- const classNames = [
15
- `mig-schema-table__th`,
16
- `mig-schema-table__th--filter-${columnFilterStatus}`,
17
- `mig-schema-table__th--prop-${propName}`,
18
- ];
19
- classNames.push(isSortable
20
- ? "mig-schema-table__th--sortable"
21
- : "mig-schema-table__th--unsortable");
22
- if (sortAsc !== undefined) {
23
- classNames.push("mig-schema-table__th--sorted");
24
- }
25
- if (isDragging) {
26
- classNames.push(`mig-schema-table__th--dragging`);
27
- }
28
- if (isDropTarget) {
29
- classNames.push(`mig-schema-table__th--drop-target`);
30
- }
31
- const { format } = schema || {};
32
- const { align, defaultSortDesc, renderData, showTimezones, TdBody, title } = propConfig || {};
33
- const onLabelClick = React.useCallback(() => {
34
- if (!isSortable) {
35
- return;
36
- }
37
- if (sortAsc === undefined) {
38
- setSortColumn(propName);
39
- setSortAsc(!defaultSortDesc);
40
- return;
41
- }
42
- setSortAsc((sortAsc) => !sortAsc);
43
- }, [
44
- isSortable,
45
- defaultSortDesc,
46
- propName,
47
- setSortAsc,
48
- setSortColumn,
49
- sortAsc,
50
- ]);
51
- const onTriggerClick = React.useCallback((e) => {
52
- const referenceElement = e.currentTarget;
53
- setMenuConfig((menuConfig) => {
54
- if ((menuConfig === null || menuConfig === void 0 ? void 0 : menuConfig.propName) === propName) {
55
- return undefined;
56
- }
57
- return {
58
- propConfig,
59
- propIsRequired,
60
- propName,
61
- referenceElement,
62
- };
63
- });
64
- }, [propConfig, propIsRequired, propName, setMenuConfig]);
65
- const labelBody = React.useMemo(() => {
66
- if (title !== undefined) {
67
- return title;
68
- }
69
- if (format === "date-time" && showTimezones !== false) {
70
- return `${translate(propName)} (${translate(timeZone)})`;
71
- }
72
- return translate(propName);
73
- }, [title, format, showTimezones, translate, propName]);
74
- const onDragStart = React.useCallback((e) => {
75
- if (!onColumnPositionChange) {
76
- return;
77
- }
78
- setIsDragging(true);
79
- e.dataTransfer.effectAllowed = "move";
80
- e.dataTransfer.dropEffect = "move";
81
- e.dataTransfer.setData("text/plain", propName);
82
- }, [onColumnPositionChange, propName]);
83
- const onDragEnd = React.useCallback(() => {
84
- if (!onColumnPositionChange) {
85
- return;
86
- }
87
- setIsDragging(false);
88
- }, [onColumnPositionChange]);
89
- const onDragOver = React.useCallback((e) => {
90
- if (!onColumnPositionChange) {
91
- return;
92
- }
93
- e.preventDefault();
94
- setIsDropTarget(true);
95
- }, [onColumnPositionChange]);
96
- const onDragLeave = React.useCallback(() => {
97
- if (!onColumnPositionChange) {
98
- return;
99
- }
100
- setIsDropTarget(false);
101
- }, [onColumnPositionChange]);
102
- const onDrop = React.useCallback((e) => {
103
- if (!onColumnPositionChange || !propName) {
104
- return;
105
- }
106
- const sourcePropName = e.dataTransfer.getData("text/plain");
107
- if (!sourcePropName || sourcePropName === propName) {
108
- return;
109
- }
110
- onColumnPositionChange(sourcePropName, propName);
111
- }, [onColumnPositionChange, propName]);
112
- if (propName === SELECT_ALL_COLUMN_NAME) {
113
- return (_jsx("div", Object.assign({ style: style, className: classNames.join(" ") }, { children: _jsx("div", Object.assign({ style: {
114
- width: "100%",
115
- textAlign: "center",
116
- }, title: `${numberOfSelectedRows || 0} selected` }, { children: _jsx("input", { type: "checkbox", name: "selectAll", checked: isAllChecked, onChange: onSelectAllIndexesHandler }) })) })));
117
- }
118
- switch (schema === null || schema === void 0 ? void 0 : schema.type) {
119
- case "boolean":
120
- classNames.push(`text-${align || "center"}`, `justify-content-${align || "center"}`);
121
- break;
122
- case "integer":
123
- case "number":
124
- classNames.push(`text-${align || "end"}`, `justify-content-${align || "end"}`);
125
- break;
126
- default:
127
- if (align) {
128
- classNames.push(`text-${align}`);
129
- }
130
- }
131
- return (_jsxs("div", Object.assign({ className: classNames.join(" "), style: style, title: typeof labelBody === "string" ? labelBody : undefined, draggable: true, onDragStart: onDragStart, onDragEnd: onDragEnd, onDragOver: onDragOver, onDragLeave: onDragLeave, onDrop: onDrop }, { children: [_jsxs("div", Object.assign({ className: "mig-schema-table__th__label-body", style: { lineHeight: "44px" }, onClick: onLabelClick }, { children: [_jsx("span", Object.assign({ className: "mig-schema-table__th__label-body-text" }, { children: labelBody })), sortAsc === undefined ? null : (_jsx("span", Object.assign({ className: "mig-schema-table__th__sort-icon" }, { children: sortAsc ? "↓" : "↑" })))] })), isSortable || columnFilterStatus !== EColumnFilterStatus.UNAVAILABLE ? (_jsx("button", Object.assign({ className: "mig-schema-table__th__trigger-el", onClick: onTriggerClick }, { children: _jsx("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "#404040", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }, { children: _jsx("polyline", { points: "6 9 12 15 18 9" }) })) }))) : null] })));
132
- };
133
- export default React.memo(Th);
@@ -1,14 +0,0 @@
1
- import React from "react";
2
- import { oas31 } from "openapi3-ts";
3
- import { TColumnFilterValue } from "../../index";
4
- export interface IFilterMenuComponentProps {
5
- columnFilterValue: TColumnFilterValue;
6
- onChange: (newValue: TColumnFilterValue | undefined, persistState?: boolean) => void;
7
- onInputKeyDown: (e: React.KeyboardEvent<HTMLElement>) => void;
8
- propIsRequired: boolean;
9
- propName: string;
10
- propSchema?: oas31.SchemaObject;
11
- translate: (key: string, ...args: Array<string | number>) => string;
12
- }
13
- declare const _default: React.MemoExoticComponent<({ columnFilterValue, onChange, onInputKeyDown, propIsRequired, propName, propSchema, translate, }: IFilterMenuComponentProps) => import("react/jsx-runtime").JSX.Element>;
14
- export default _default;