@uxf/data-grid 11.13.0 → 11.15.0
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/_generator/cli.js +3 -2
- package/_generator/index.js +38 -10
- package/_store/reducer.js +9 -2
- package/components.d.ts +5 -0
- package/components.js +5 -0
- package/package.json +4 -2
- package/styles.css +1 -0
- package/table-v2/hooks/use-resizable-columns.d.ts +9 -0
- package/table-v2/hooks/use-resizable-columns.js +68 -0
- package/table-v2/index.d.ts +1 -0
- package/table-v2/index.js +17 -0
- package/table-v2/no-rows-fallback.d.ts +7 -0
- package/table-v2/no-rows-fallback.js +15 -0
- package/table-v2/styles.css +62 -0
- package/table-v2/table-v2.d.ts +3 -0
- package/table-v2/table-v2.js +46 -0
- package/table-v2/table-v2.stories.d.ts +2 -0
- package/table-v2/table-v2.stories.js +22 -0
- package/table-v2/types.d.ts +24 -0
- package/table-v2/types.js +2 -0
- package/table-v2/utils/get-grid-template-rows.d.ts +2 -0
- package/table-v2/utils/get-grid-template-rows.js +15 -0
- package/use-data-grid-control/actions-factory.d.ts +2 -0
- package/use-data-grid-control/actions-factory.js +1 -0
- package/use-data-grid-control/use-data-grid-control.d.ts +1 -0
package/_generator/cli.js
CHANGED
|
@@ -12,17 +12,18 @@ Usage:
|
|
|
12
12
|
.option("o", { alias: "outputDirectory", type: "string" })
|
|
13
13
|
.option("l", { alias: "requiredLoader", type: "boolean" })
|
|
14
14
|
.option("h", { alias: "help", group: "Options" })
|
|
15
|
+
.option("t", { alias: "columnTypes", type: "string" })
|
|
15
16
|
.strict(false)
|
|
16
17
|
.exitProcess(false);
|
|
17
18
|
|
|
18
19
|
try {
|
|
19
|
-
const { help, schemaDirectory, outputDirectory, requiredLoader } = cli.parse(argv.slice(2));
|
|
20
|
+
const { help, schemaDirectory, outputDirectory, requiredLoader, columnTypes } = cli.parse(argv.slice(2));
|
|
20
21
|
|
|
21
22
|
if (Boolean(help)) {
|
|
22
23
|
return 0;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
await require("./index")(schemaDirectory, outputDirectory, requiredLoader);
|
|
26
|
+
await require("./index")(schemaDirectory, outputDirectory, requiredLoader, columnTypes);
|
|
26
27
|
} catch (e) {
|
|
27
28
|
console.error(e);
|
|
28
29
|
return 1;
|
package/_generator/index.js
CHANGED
|
@@ -14,23 +14,51 @@ function writeFile(filename, value) {
|
|
|
14
14
|
writeFileSync(filename, value);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
function
|
|
18
|
-
return `
|
|
19
|
-
import json from "${schemaRelativeImport}";
|
|
20
|
-
|
|
21
|
-
type DataGrid_${camelize(gridName)} = {
|
|
17
|
+
function generateGridType(gridName, schema) {
|
|
18
|
+
return `type DataGrid_${camelize(gridName)} = {
|
|
22
19
|
columns: {
|
|
23
20
|
${schema.columns.map((column) => `"${column.name}": "${column.type}",`).join("\n ")}
|
|
24
21
|
},
|
|
25
22
|
filters: {
|
|
26
23
|
${schema.filters.map((filter) => `"${filter.name}": "${filter.type}",`).join("\n ")}
|
|
27
24
|
}
|
|
25
|
+
}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function generateRowType(gridName, schema, columnTypes) {
|
|
29
|
+
if (!columnTypes) {
|
|
30
|
+
return "";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return `export type DataGridRow_${camelize(gridName)} = {
|
|
34
|
+
${schema.columns.map((column) => `"${column.name}": ColumnTypes["${column.type}"]`).join("\n ")}
|
|
35
|
+
}`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function generateGridSchema(gridName) {
|
|
39
|
+
return `export const dataGridSchema_${camelize(gridName)}: Schema<DataGrid_${camelize(gridName)}> = json as any;`;
|
|
28
40
|
}
|
|
29
41
|
|
|
30
|
-
|
|
42
|
+
function generateSchemaFile(gridName, schema, schemaRelativeImport, columnTypes) {
|
|
43
|
+
const imports = [
|
|
44
|
+
'import { Schema } from "@uxf/data-grid";',
|
|
45
|
+
`import json from "${schemaRelativeImport}";`,
|
|
46
|
+
!!columnTypes && `import { ColumnTypes } from "${columnTypes}";`,
|
|
47
|
+
]
|
|
48
|
+
.filter(Boolean)
|
|
49
|
+
.join("\n");
|
|
50
|
+
|
|
51
|
+
return [
|
|
52
|
+
imports,
|
|
53
|
+
!!columnTypes && generateRowType(gridName, schema, columnTypes),
|
|
54
|
+
generateGridType(gridName, schema),
|
|
55
|
+
generateGridSchema(gridName),
|
|
56
|
+
]
|
|
57
|
+
.filter(Boolean)
|
|
58
|
+
.join("\n\n");
|
|
31
59
|
}
|
|
32
60
|
|
|
33
|
-
function generate(schema, filename, outputDirectory) {
|
|
61
|
+
function generate(schema, filename, outputDirectory, columnTypes) {
|
|
34
62
|
const gridName = parse(filename).name;
|
|
35
63
|
const generatedPath = join(process.cwd(), outputDirectory, gridName);
|
|
36
64
|
|
|
@@ -38,12 +66,12 @@ function generate(schema, filename, outputDirectory) {
|
|
|
38
66
|
|
|
39
67
|
writeFile(
|
|
40
68
|
generatedSchemaFilename,
|
|
41
|
-
generateSchemaFile(gridName, schema, relative(dirname(generatedSchemaFilename), filename)),
|
|
69
|
+
generateSchemaFile(gridName, schema, relative(dirname(generatedSchemaFilename), filename), columnTypes),
|
|
42
70
|
);
|
|
43
71
|
}
|
|
44
72
|
|
|
45
|
-
module.exports = (schemaDirectory, outputDirectory, requiredLoader) => {
|
|
73
|
+
module.exports = (schemaDirectory, outputDirectory, requiredLoader, columnTypes) => {
|
|
46
74
|
globSync(schemaDirectory + "/*.json")
|
|
47
75
|
.map((path) => process.cwd() + "/" + path)
|
|
48
|
-
.forEach((filename) => generate(JSON.parse(readFileSync(filename)), filename, outputDirectory,
|
|
76
|
+
.forEach((filename) => generate(JSON.parse(readFileSync(filename)), filename, outputDirectory, columnTypes));
|
|
49
77
|
};
|
package/_store/reducer.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.debugReducer = exports.reducer = exports.getInitialState = void 0;
|
|
4
7
|
const is_nil_1 = require("@uxf/core/utils/is-nil");
|
|
8
|
+
const deepmerge_1 = __importDefault(require("deepmerge"));
|
|
5
9
|
const utils_1 = require("../utils");
|
|
6
10
|
function getInitialState(schema, init, initialUserConfig) {
|
|
7
11
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
@@ -144,7 +148,6 @@ const reducer = (state, action) => {
|
|
|
144
148
|
columns: {
|
|
145
149
|
...state.userConfig.columns,
|
|
146
150
|
[action.name]: {
|
|
147
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
148
151
|
...((_k = (_j = state.userConfig.columns) === null || _j === void 0 ? void 0 : _j[action.name]) !== null && _k !== void 0 ? _k : {}),
|
|
149
152
|
isHidden: true,
|
|
150
153
|
},
|
|
@@ -159,13 +162,17 @@ const reducer = (state, action) => {
|
|
|
159
162
|
columns: {
|
|
160
163
|
...state.userConfig.columns,
|
|
161
164
|
[action.name]: {
|
|
162
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
163
165
|
...((_m = (_l = state.userConfig.columns) === null || _l === void 0 ? void 0 : _l[action.name]) !== null && _m !== void 0 ? _m : {}),
|
|
164
166
|
isHidden: false,
|
|
165
167
|
},
|
|
166
168
|
},
|
|
167
169
|
},
|
|
168
170
|
};
|
|
171
|
+
case "UPDATE_USER_CONFIG":
|
|
172
|
+
return {
|
|
173
|
+
...state,
|
|
174
|
+
userConfig: (0, deepmerge_1.default)(state.userConfig, action.userConfig),
|
|
175
|
+
};
|
|
169
176
|
default:
|
|
170
177
|
// eslint-disable-next-line no-console
|
|
171
178
|
console.warn("Unknown datagrid action.", action);
|
package/components.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import * as rowCountsStories from "./row-counts/row-counts.stories";
|
|
|
11
11
|
import * as rowsPerPageSelectStories from "./rows-per-page-select/rows-per-page-select.stories";
|
|
12
12
|
import * as selectedRowsToolbarStories from "./selected-rows-toolbar/selected-rows-toolbar.stories";
|
|
13
13
|
import * as tableStories from "./table/table.stories";
|
|
14
|
+
import * as tableV2Stories from "./table-v2/table-v2.stories";
|
|
14
15
|
import * as toolbarControlStories from "./toolbar-control/toolbar-control.stories";
|
|
15
16
|
import * as toolbarCustomsStories from "./toolbar-customs/toolbar-customs.stories";
|
|
16
17
|
import * as toolbarTabsStories from "./toolbar-tabs/toolbar-tabs.stories";
|
|
@@ -67,6 +68,10 @@ export declare const components: {
|
|
|
67
68
|
readonly title: "Table";
|
|
68
69
|
readonly stories: typeof tableStories;
|
|
69
70
|
};
|
|
71
|
+
readonly "table-v2": {
|
|
72
|
+
readonly title: "TableV2";
|
|
73
|
+
readonly stories: typeof tableV2Stories;
|
|
74
|
+
};
|
|
70
75
|
readonly "toolbar-control": {
|
|
71
76
|
readonly title: "ToolbarControl";
|
|
72
77
|
readonly stories: typeof toolbarControlStories;
|
package/components.js
CHANGED
|
@@ -38,6 +38,7 @@ const rowCountsStories = __importStar(require("./row-counts/row-counts.stories")
|
|
|
38
38
|
const rowsPerPageSelectStories = __importStar(require("./rows-per-page-select/rows-per-page-select.stories"));
|
|
39
39
|
const selectedRowsToolbarStories = __importStar(require("./selected-rows-toolbar/selected-rows-toolbar.stories"));
|
|
40
40
|
const tableStories = __importStar(require("./table/table.stories"));
|
|
41
|
+
const tableV2Stories = __importStar(require("./table-v2/table-v2.stories"));
|
|
41
42
|
const toolbarControlStories = __importStar(require("./toolbar-control/toolbar-control.stories"));
|
|
42
43
|
const toolbarCustomsStories = __importStar(require("./toolbar-customs/toolbar-customs.stories"));
|
|
43
44
|
const toolbarTabsStories = __importStar(require("./toolbar-tabs/toolbar-tabs.stories"));
|
|
@@ -94,6 +95,10 @@ exports.components = {
|
|
|
94
95
|
title: "Table",
|
|
95
96
|
stories: tableStories
|
|
96
97
|
},
|
|
98
|
+
"table-v2": {
|
|
99
|
+
title: "TableV2",
|
|
100
|
+
stories: tableV2Stories
|
|
101
|
+
},
|
|
97
102
|
"toolbar-control": {
|
|
98
103
|
title: "ToolbarControl",
|
|
99
104
|
stories: toolbarControlStories
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxf/data-grid",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.15.0",
|
|
4
4
|
"description": "UXF DataGrid",
|
|
5
5
|
"homepage": "https://gitlab.com/uxf-npm/data-grid#readme",
|
|
6
6
|
"main": "index.js",
|
|
@@ -31,8 +31,10 @@
|
|
|
31
31
|
"typecheck": "tsc --noEmit --skipLibCheck"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@uxf/
|
|
34
|
+
"@uxf/core": "11.11.3",
|
|
35
|
+
"@uxf/ui": "11.15.0",
|
|
35
36
|
"dayjs": "1.11.10",
|
|
37
|
+
"deepmerge": "4.3.1",
|
|
36
38
|
"fast-glob": "3.3.2",
|
|
37
39
|
"qs": "6.11.2",
|
|
38
40
|
"react-data-grid": "7.0.0-beta.39",
|
package/styles.css
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Column } from "../../types";
|
|
3
|
+
import { DataGridControl } from "../../use-data-grid-control";
|
|
4
|
+
import { TableProps } from "../types";
|
|
5
|
+
export declare function useResizableColumns(columns: Column<any, any>[], actionCell: TableProps<any>["actionCell"], actions: DataGridControl["actions"]): {
|
|
6
|
+
tableRef: import("react").RefObject<HTMLDivElement>;
|
|
7
|
+
columnRefs: import("react").MutableRefObject<(HTMLDivElement | null)[]>;
|
|
8
|
+
onResizeStart(index: number): void;
|
|
9
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useResizableColumns = void 0;
|
|
4
|
+
const is_empty_1 = require("@uxf/core/utils/is-empty");
|
|
5
|
+
const is_nil_1 = require("@uxf/core/utils/is-nil");
|
|
6
|
+
const is_not_nil_1 = require("@uxf/core/utils/is-not-nil");
|
|
7
|
+
const rem_1 = require("@uxf/styles/units/rem");
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
function mapColumnSizesToGridTemplateColumns(columnSizes, actionCellWidth) {
|
|
10
|
+
const normalizedColumnSizes = columnSizes.map((size) => ((0, is_not_nil_1.isNotNil)(size) ? (0, rem_1.rem)(size) : "1fr"));
|
|
11
|
+
return (0, is_nil_1.isNil)(actionCellWidth)
|
|
12
|
+
? `${normalizedColumnSizes.join(" ")}`
|
|
13
|
+
: `${normalizedColumnSizes.join(" ")} ${(0, rem_1.rem)(actionCellWidth)}`;
|
|
14
|
+
}
|
|
15
|
+
function useResizableColumns(columns, actionCell, actions) {
|
|
16
|
+
const [activeIndex, setActiveIndex] = (0, react_1.useState)(null);
|
|
17
|
+
const tableRef = (0, react_1.useRef)(null);
|
|
18
|
+
const columnRefs = (0, react_1.useRef)([]);
|
|
19
|
+
const actionCellWidth = actionCell === null || actionCell === void 0 ? void 0 : actionCell.width;
|
|
20
|
+
(0, react_1.useEffect)(() => {
|
|
21
|
+
let tempColumnSizes = [];
|
|
22
|
+
const onMouseMove = (e) => {
|
|
23
|
+
const gridColumns = columns.map((_, i) => {
|
|
24
|
+
var _a, _b, _c, _d;
|
|
25
|
+
const columnRef = columnRefs.current[i];
|
|
26
|
+
if (i === activeIndex) {
|
|
27
|
+
const tableScrollLeft = (_b = (_a = tableRef.current) === null || _a === void 0 ? void 0 : _a.scrollLeft) !== null && _b !== void 0 ? _b : 0;
|
|
28
|
+
const columnOffsetLeft = (_c = columnRef === null || columnRef === void 0 ? void 0 : columnRef.offsetLeft) !== null && _c !== void 0 ? _c : 0;
|
|
29
|
+
const clickPositionX = e.clientX + tableScrollLeft;
|
|
30
|
+
const width = clickPositionX - columnOffsetLeft;
|
|
31
|
+
return width >= 50 ? width : 50;
|
|
32
|
+
}
|
|
33
|
+
return (_d = columnRef === null || columnRef === void 0 ? void 0 : columnRef.offsetWidth) !== null && _d !== void 0 ? _d : 50;
|
|
34
|
+
});
|
|
35
|
+
// TODO @vejvis - jak tohle udělat lépe??
|
|
36
|
+
tempColumnSizes = gridColumns;
|
|
37
|
+
if (tableRef.current) {
|
|
38
|
+
tableRef.current.style.gridTemplateColumns = mapColumnSizesToGridTemplateColumns(gridColumns, actionCellWidth);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const onMouseUp = () => {
|
|
42
|
+
setActiveIndex(null);
|
|
43
|
+
if (!(0, is_empty_1.isEmpty)(tempColumnSizes)) {
|
|
44
|
+
const userConfigColumns = {};
|
|
45
|
+
columns.forEach((column, index) => {
|
|
46
|
+
userConfigColumns[column.name] = { width: tempColumnSizes[index] };
|
|
47
|
+
});
|
|
48
|
+
actions.updateUserConfig({ columns: userConfigColumns });
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
if (activeIndex !== null) {
|
|
52
|
+
window.addEventListener("mousemove", onMouseMove);
|
|
53
|
+
window.addEventListener("mouseup", onMouseUp);
|
|
54
|
+
}
|
|
55
|
+
return () => {
|
|
56
|
+
window.removeEventListener("mousemove", onMouseMove);
|
|
57
|
+
window.removeEventListener("mouseup", onMouseUp);
|
|
58
|
+
};
|
|
59
|
+
}, [columns, actions, actionCellWidth, activeIndex]);
|
|
60
|
+
return {
|
|
61
|
+
tableRef,
|
|
62
|
+
columnRefs,
|
|
63
|
+
onResizeStart(index) {
|
|
64
|
+
setActiveIndex(index);
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
exports.useResizableColumns = useResizableColumns;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./table-v2";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./table-v2"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React, { FC } from "react";
|
|
2
|
+
export interface NoRowsFallbackProps {
|
|
3
|
+
error?: any;
|
|
4
|
+
loading: boolean;
|
|
5
|
+
}
|
|
6
|
+
export type NoRowsFallbackComponent = FC<NoRowsFallbackProps>;
|
|
7
|
+
export declare function NoRowsFallback(props: NoRowsFallbackProps): React.JSX.Element;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NoRowsFallback = void 0;
|
|
7
|
+
const cx_1 = require("@uxf/core/utils/cx");
|
|
8
|
+
const icon_1 = require("@uxf/ui/icon");
|
|
9
|
+
const react_1 = __importDefault(require("react"));
|
|
10
|
+
function NoRowsFallback(props) {
|
|
11
|
+
return (react_1.default.createElement("div", { className: (0, cx_1.cx)("uxf-data-grid__fallback", props.loading && "is-loading", props.error && "is-error") }, props.loading ? (react_1.default.createElement(react_1.default.Fragment, null, "Na\u010D\u00EDt\u00E1m...")) : props.error ? (react_1.default.createElement(react_1.default.Fragment, null,
|
|
12
|
+
react_1.default.createElement(icon_1.Icon, { name: "warning", size: 24 }),
|
|
13
|
+
react_1.default.createElement("p", null, "Vyskytla se chyba"))) : (react_1.default.createElement(react_1.default.Fragment, null, "\u017D\u00E1dn\u00E9 z\u00E1znamy"))));
|
|
14
|
+
}
|
|
15
|
+
exports.NoRowsFallback = NoRowsFallback;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
.uxf-data-grid__table-v2 {
|
|
2
|
+
display: grid;
|
|
3
|
+
font-size: theme("fontSize.sm");
|
|
4
|
+
overflow-x: auto;
|
|
5
|
+
width: 100%;
|
|
6
|
+
|
|
7
|
+
.uxf-data-grid__row {
|
|
8
|
+
display: contents;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.uxf-data-grid__cell {
|
|
12
|
+
align-items: center;
|
|
13
|
+
border-top: 1px solid theme("colors.lightBorder");
|
|
14
|
+
display: flex;
|
|
15
|
+
padding: 8px;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.uxf-data-grid__cell-header {
|
|
19
|
+
background-color: theme("colors.neutral.50");
|
|
20
|
+
color: theme("colors.neutral.400");
|
|
21
|
+
position: relative;
|
|
22
|
+
user-select: none;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.uxf-data-grid__cell-action {
|
|
26
|
+
background-color: theme("colors.white");
|
|
27
|
+
border-left: 1px solid theme("colors.lightBorder");
|
|
28
|
+
position: sticky;
|
|
29
|
+
right: 0;
|
|
30
|
+
|
|
31
|
+
&.uxf-data-grid__cell-header {
|
|
32
|
+
background-color: theme("colors.neutral.50");
|
|
33
|
+
z-index: 2;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.uxf-data-grid__cell-resize-handle {
|
|
38
|
+
bottom: 0;
|
|
39
|
+
cursor: col-resize;
|
|
40
|
+
position: absolute;
|
|
41
|
+
right: -8px;
|
|
42
|
+
top: 0;
|
|
43
|
+
width: 16px;
|
|
44
|
+
z-index: 2;
|
|
45
|
+
|
|
46
|
+
&::before {
|
|
47
|
+
background-color: theme("colors.lightBorder");
|
|
48
|
+
bottom: 0;
|
|
49
|
+
content: "";
|
|
50
|
+
position: absolute;
|
|
51
|
+
right: 8px;
|
|
52
|
+
top: 0;
|
|
53
|
+
width: 1px;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
&:hover {
|
|
57
|
+
&::before {
|
|
58
|
+
width: 2px;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TableV2 = void 0;
|
|
7
|
+
const is_nil_1 = require("@uxf/core/utils/is-nil");
|
|
8
|
+
const is_not_nil_1 = require("@uxf/core/utils/is-not-nil");
|
|
9
|
+
const rem_1 = require("@uxf/styles/units/rem");
|
|
10
|
+
const react_1 = __importDefault(require("react"));
|
|
11
|
+
const use_resizable_columns_1 = require("./hooks/use-resizable-columns");
|
|
12
|
+
const get_grid_template_rows_1 = require("./utils/get-grid-template-rows");
|
|
13
|
+
const defaultKeyExtractor = (r) => r.id;
|
|
14
|
+
function TableV2(props) {
|
|
15
|
+
var _a, _b, _c, _d;
|
|
16
|
+
const keyExtractor = (_a = props.keyExtractor) !== null && _a !== void 0 ? _a : defaultKeyExtractor;
|
|
17
|
+
const visibleColumns = props.schema.columns.filter((column) => { var _a, _b; return !((_b = (_a = props.state.userConfig.columns) === null || _a === void 0 ? void 0 : _a[column.name]) === null || _b === void 0 ? void 0 : _b.isHidden); });
|
|
18
|
+
const { tableRef, columnRefs, onResizeStart } = (0, use_resizable_columns_1.useResizableColumns)(visibleColumns, props.actionCell, props.actions);
|
|
19
|
+
const gridTemplateRows = (0, get_grid_template_rows_1.getGridTemplateRows)(props.data, (_b = props.headerRowHeight) !== null && _b !== void 0 ? _b : 36, (_c = props.rowHeight) !== null && _c !== void 0 ? _c : 44);
|
|
20
|
+
const gridTemplateColumnsWithoutAction = visibleColumns
|
|
21
|
+
.map((column) => { var _a, _b, _c, _d; return (_c = (_b = (_a = props.state.userConfig.columns) === null || _a === void 0 ? void 0 : _a[column.name]) === null || _b === void 0 ? void 0 : _b.width) !== null && _c !== void 0 ? _c : (_d = column.config) === null || _d === void 0 ? void 0 : _d.width; })
|
|
22
|
+
.map((width) => ((0, is_nil_1.isNil)(width) ? "1fr" : (0, rem_1.rem)(width)))
|
|
23
|
+
.join(" ");
|
|
24
|
+
const gridTemplateColumns = (0, is_nil_1.isNil)((_d = props.actionCell) === null || _d === void 0 ? void 0 : _d.width)
|
|
25
|
+
? gridTemplateColumnsWithoutAction
|
|
26
|
+
: `${gridTemplateColumnsWithoutAction} ${(0, rem_1.rem)(props.actionCell.width)}`;
|
|
27
|
+
return (react_1.default.createElement("div", { className: "uxf-data-grid__table-v2", ref: tableRef, style: { gridTemplateColumns, gridTemplateRows } },
|
|
28
|
+
react_1.default.createElement("div", { className: "uxf-data-grid__row" },
|
|
29
|
+
visibleColumns.map((column, index) => (react_1.default.createElement("div", { key: column.name, className: "uxf-data-grid__cell uxf-data-grid__cell-header", ref: (el) => (columnRefs.current[index] = el) },
|
|
30
|
+
column.label,
|
|
31
|
+
react_1.default.createElement("div", { className: "uxf-data-grid__cell-resize-handle", onMouseDown: () => onResizeStart(index) })))),
|
|
32
|
+
(0, is_not_nil_1.isNotNil)(props.actionCell) && (react_1.default.createElement("div", { className: "uxf-data-grid__cell uxf-data-grid__cell-header uxf-data-grid__cell-action" }))),
|
|
33
|
+
props.data.map((row) => (react_1.default.createElement("div", { className: "uxf-data-grid__row", key: keyExtractor(row) },
|
|
34
|
+
visibleColumns.map((column) => {
|
|
35
|
+
var _a, _b, _c;
|
|
36
|
+
const BodyCell = (_b = (_a = props.bodyCells) === null || _a === void 0 ? void 0 : _a[column.type]) !== null && _b !== void 0 ? _b : (_c = props.bodyCells) === null || _c === void 0 ? void 0 : _c.default;
|
|
37
|
+
if (!BodyCell) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return (react_1.default.createElement("div", { className: "uxf-data-grid__cell", key: column.name },
|
|
41
|
+
react_1.default.createElement(BodyCell, { column: column, row: row, value: row[column.name], reload: () => { var _a; return (_a = props.onReload) === null || _a === void 0 ? void 0 : _a.call(props); } })));
|
|
42
|
+
}),
|
|
43
|
+
(0, is_not_nil_1.isNotNil)(props.actionCell) && (react_1.default.createElement("div", { className: "uxf-data-grid__cell uxf-data-grid__cell-action" },
|
|
44
|
+
react_1.default.createElement(props.actionCell.Component, { row: row, reload: () => { var _a; return (_a = props.onReload) === null || _a === void 0 ? void 0 : _a.call(props); } }))))))));
|
|
45
|
+
}
|
|
46
|
+
exports.TableV2 = TableV2;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Default = void 0;
|
|
7
|
+
const json_renderer_1 = require("@uxf/example/src/components/json-renderer");
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const data_1 = require("../_story-utils/data");
|
|
10
|
+
const schema_1 = require("../_story-utils/schema");
|
|
11
|
+
const body_cell_1 = require("../body-cell");
|
|
12
|
+
const hidden_columns_button_1 = require("../hidden-columns-button");
|
|
13
|
+
const use_data_grid_control_1 = require("../use-data-grid-control");
|
|
14
|
+
const table_v2_1 = require("./table-v2");
|
|
15
|
+
function Default() {
|
|
16
|
+
const { state, actions } = (0, use_data_grid_control_1.useDataGridControl)({ schema: schema_1.schema });
|
|
17
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
18
|
+
react_1.default.createElement(hidden_columns_button_1.HiddenColumnsButton, { schema: schema_1.schema, state: state, actions: actions }),
|
|
19
|
+
react_1.default.createElement(table_v2_1.TableV2, { state: state, actions: actions, data: data_1.data, isLoading: true, error: undefined, schema: schema_1.schema, bodyCells: body_cell_1.BodyCells, isRowSelectable: true, actionCell: { width: 150, Component: () => react_1.default.createElement("div", null, "ActionCell") } }),
|
|
20
|
+
react_1.default.createElement(json_renderer_1.JsonRenderer, { value: state })));
|
|
21
|
+
}
|
|
22
|
+
exports.Default = Default;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Nullish } from "@uxf/core/types";
|
|
2
|
+
import { ActionCellComponent, BodyCellComponents } from "../types/components";
|
|
3
|
+
import { KeyExtractor } from "../types/core";
|
|
4
|
+
import { Schema } from "../types/schema";
|
|
5
|
+
import { DataGridControl } from "../use-data-grid-control";
|
|
6
|
+
import { NoRowsFallbackComponent } from "./no-rows-fallback";
|
|
7
|
+
export interface TableProps<Row> extends DataGridControl {
|
|
8
|
+
schema: Schema<any>;
|
|
9
|
+
data: Row[];
|
|
10
|
+
isLoading?: boolean;
|
|
11
|
+
error?: any | Nullish;
|
|
12
|
+
onReload?: () => void;
|
|
13
|
+
rowHeight?: number | ((row: Row) => number) | "auto";
|
|
14
|
+
headerRowHeight?: number;
|
|
15
|
+
rowClass?: (row: Row) => "success" | "warning" | "error" | "primary" | "secondary" | string | null | undefined;
|
|
16
|
+
keyExtractor?: KeyExtractor;
|
|
17
|
+
bodyCells?: BodyCellComponents<any, any>;
|
|
18
|
+
actionCell?: {
|
|
19
|
+
width: number;
|
|
20
|
+
Component: ActionCellComponent<any>;
|
|
21
|
+
};
|
|
22
|
+
NoRowsFallback?: NoRowsFallbackComponent;
|
|
23
|
+
isRowSelectable?: boolean;
|
|
24
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGridTemplateRows = void 0;
|
|
4
|
+
const is_nil_1 = require("@uxf/core/utils/is-nil");
|
|
5
|
+
const rem_1 = require("@uxf/styles/units/rem");
|
|
6
|
+
function getGridTemplateRows(rows, headerRowHeight, rowHeight) {
|
|
7
|
+
if (rowHeight === "auto" || (0, is_nil_1.isNil)(rowHeight)) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
if (typeof rowHeight === "number") {
|
|
11
|
+
return `${(0, rem_1.rem)(headerRowHeight)} repeat(${rows.length}, ${(0, rem_1.rem)(rowHeight)})`;
|
|
12
|
+
}
|
|
13
|
+
return `${headerRowHeight} ${rows.map(rowHeight).join(" ")}`;
|
|
14
|
+
}
|
|
15
|
+
exports.getGridTemplateRows = getGridTemplateRows;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Dispatch } from "react";
|
|
2
2
|
import { Tab } from "../types/schema";
|
|
3
|
+
import { DataGridUserConfig } from "../types/state";
|
|
3
4
|
export declare function createActions(dispatch: Dispatch<any>): {
|
|
4
5
|
changePage: (page: number) => void;
|
|
5
6
|
changePerPage: (perPage: number) => void;
|
|
@@ -12,4 +13,5 @@ export declare function createActions(dispatch: Dispatch<any>): {
|
|
|
12
13
|
setSelectedRows: (rows: any[]) => void;
|
|
13
14
|
hideColumn: (name: string) => void;
|
|
14
15
|
showColumn: (name: string) => void;
|
|
16
|
+
updateUserConfig: (userConfig: DataGridUserConfig<any>) => void;
|
|
15
17
|
};
|
|
@@ -14,6 +14,7 @@ function createActions(dispatch) {
|
|
|
14
14
|
setSelectedRows: (rows) => dispatch({ type: "SET_SELECTED_ROWS", rows }),
|
|
15
15
|
hideColumn: (name) => dispatch({ type: "HIDE_COLUMN", name }),
|
|
16
16
|
showColumn: (name) => dispatch({ type: "SHOW_COLUMN", name }),
|
|
17
|
+
updateUserConfig: (userConfig) => dispatch({ type: "UPDATE_USER_CONFIG", userConfig }),
|
|
17
18
|
};
|
|
18
19
|
}
|
|
19
20
|
exports.createActions = createActions;
|
|
@@ -22,6 +22,7 @@ export declare function useDataGridControl<T extends BaseGridType>(config: UseDa
|
|
|
22
22
|
setSelectedRows: (rows: any[]) => void;
|
|
23
23
|
hideColumn: (name: string) => void;
|
|
24
24
|
showColumn: (name: string) => void;
|
|
25
|
+
updateUserConfig: (userConfig: DataGridUserConfig<any>) => void;
|
|
25
26
|
};
|
|
26
27
|
};
|
|
27
28
|
export type DataGridControl = ReturnType<typeof useDataGridControl>;
|