@astral/ui 1.2.0-dev.2 → 1.3.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/DataGrid/DataGrid.d.ts +5 -5
- package/DataGrid/DataGrid.js +3 -3
- package/DataGrid/DataGridBody/DataGridBody.js +2 -2
- package/DataGrid/DataGridBody/{styled.d.ts → styles.d.ts} +0 -0
- package/DataGrid/DataGridBody/{styled.js → styles.js} +0 -0
- package/DataGrid/DataGridHead/DataGridHead.d.ts +2 -2
- package/DataGrid/DataGridHead/DataGridHead.js +8 -30
- package/DataGrid/DataGridHeadColumn/DataGridHeadColumn.d.ts +1 -1
- package/DataGrid/DataGridHeadColumn/DataGridHeadColumn.js +19 -9
- package/DataGrid/DataGridHeadColumn/styles.d.ts +11 -0
- package/DataGrid/DataGridHeadColumn/{styled.js → styles.js} +5 -7
- package/DataGrid/DataGridLoader/DataGridLoader.js +2 -2
- package/DataGrid/DataGridLoader/index.d.ts +1 -1
- package/DataGrid/DataGridLoader/index.js +1 -1
- package/DataGrid/DataGridLoader/{styled.d.ts → styles.d.ts} +0 -0
- package/DataGrid/DataGridLoader/{styled.js → styles.js} +0 -0
- package/DataGrid/{styled.d.ts → styles.d.ts} +0 -0
- package/DataGrid/{styled.js → styles.js} +0 -0
- package/esm/DataGrid/DataGrid.d.ts +5 -5
- package/esm/DataGrid/DataGrid.js +2 -2
- package/esm/DataGrid/DataGridBody/DataGridBody.js +1 -1
- package/esm/DataGrid/DataGridBody/{styled.d.ts → styles.d.ts} +0 -0
- package/esm/DataGrid/DataGridBody/{styled.js → styles.js} +0 -0
- package/esm/DataGrid/DataGridHead/DataGridHead.d.ts +2 -2
- package/esm/DataGrid/DataGridHead/DataGridHead.js +8 -30
- package/esm/DataGrid/DataGridHeadColumn/DataGridHeadColumn.d.ts +1 -1
- package/esm/DataGrid/DataGridHeadColumn/DataGridHeadColumn.js +19 -9
- package/esm/DataGrid/DataGridHeadColumn/styles.d.ts +11 -0
- package/esm/DataGrid/DataGridHeadColumn/{styled.js → styles.js} +5 -7
- package/esm/DataGrid/DataGridLoader/DataGridLoader.js +1 -1
- package/esm/DataGrid/DataGridLoader/index.d.ts +1 -1
- package/esm/DataGrid/DataGridLoader/index.js +1 -1
- package/esm/DataGrid/DataGridLoader/{styled.d.ts → styles.d.ts} +0 -0
- package/esm/DataGrid/DataGridLoader/{styled.js → styles.js} +0 -0
- package/esm/DataGrid/{styled.d.ts → styles.d.ts} +0 -0
- package/esm/DataGrid/{styled.js → styles.js} +0 -0
- package/package.json +2 -2
- package/DataGrid/DataGridHeadColumn/styled.d.ts +0 -39
- package/esm/DataGrid/DataGridHeadColumn/styled.d.ts +0 -39
package/DataGrid/DataGrid.d.ts
CHANGED
|
@@ -33,15 +33,15 @@ export declare type DataGridProps<Data extends object = DataGridRow, SortField e
|
|
|
33
33
|
*/
|
|
34
34
|
onSelectRow?: (row: Data[]) => void;
|
|
35
35
|
/**
|
|
36
|
-
* @example <DataGrid sorting={
|
|
37
|
-
*
|
|
36
|
+
* @example <DataGrid sorting={{fieldId: 'test', sort: 'asc'}} />
|
|
37
|
+
* Параметры сортируемой колонки
|
|
38
38
|
*/
|
|
39
|
-
sorting?: DataGridSort<SortField
|
|
39
|
+
sorting?: DataGridSort<SortField>;
|
|
40
40
|
/**
|
|
41
41
|
* @example <DataGrid onSort={({fieldId: 'test', sort: 'asc'}) => console.log('sorted')} />
|
|
42
42
|
* Обработчик сортировки
|
|
43
43
|
*/
|
|
44
|
-
onSort?: (sorting: DataGridSort<SortField>
|
|
44
|
+
onSort?: (sorting: DataGridSort<SortField> | undefined) => void;
|
|
45
45
|
/**
|
|
46
46
|
* @example <DataGrid Footer={<DataGridPagination />} />
|
|
47
47
|
* Компонент кастомного футера (н-р Pagination)
|
|
@@ -66,7 +66,7 @@ export declare type DataGridProps<Data extends object = DataGridRow, SortField e
|
|
|
66
66
|
/**
|
|
67
67
|
* @default 10
|
|
68
68
|
* @example <DataGrid minDisplayRows{10} />
|
|
69
|
-
*
|
|
69
|
+
* Используется для отображения переданного кол-ва строк при отсутствии данных
|
|
70
70
|
*/
|
|
71
71
|
minDisplayRows?: number;
|
|
72
72
|
};
|
package/DataGrid/DataGrid.js
CHANGED
|
@@ -30,9 +30,9 @@ var Table_1 = require("../Table");
|
|
|
30
30
|
var DataGridHead_1 = require("./DataGridHead");
|
|
31
31
|
var DataGridBody_1 = require("./DataGridBody");
|
|
32
32
|
var DataGridLoader_1 = __importDefault(require("./DataGridLoader/DataGridLoader"));
|
|
33
|
-
var
|
|
33
|
+
var styles_1 = require("./styles");
|
|
34
34
|
function DataGrid(_a) {
|
|
35
|
-
var columns = _a.columns, _b = _a.rows, rows = _b === void 0 ? [] : _b, _c = _a.selectedRows, selectedRows = _c === void 0 ? [] : _c,
|
|
35
|
+
var columns = _a.columns, _b = _a.rows, rows = _b === void 0 ? [] : _b, _c = _a.selectedRows, selectedRows = _c === void 0 ? [] : _c, sorting = _a.sorting, maxHeight = _a.maxHeight, _d = _a.minDisplayRows, minDisplayRows = _d === void 0 ? 10 : _d, onRowClick = _a.onRowClick, onSelectRow = _a.onSelectRow, Footer = _a.Footer, loading = _a.loading, onSort = _a.onSort, keyId = _a.keyId, emptyCellValue = _a.emptyCellValue;
|
|
36
36
|
var selectable = Boolean(onSelectRow);
|
|
37
37
|
var handleSelectAllRows = function (event) {
|
|
38
38
|
if (!onSelectRow) {
|
|
@@ -61,6 +61,6 @@ function DataGrid(_a) {
|
|
|
61
61
|
return !selectedRows.find(function (selectedRow) { return selectedRow[keyId] === row[keyId]; });
|
|
62
62
|
}).length;
|
|
63
63
|
}, [rows, selectedRows, keyId]);
|
|
64
|
-
return ((0, jsx_runtime_1.jsxs)(
|
|
64
|
+
return ((0, jsx_runtime_1.jsxs)(styles_1.DataGridContainer, { children: [(0, jsx_runtime_1.jsxs)(styles_1.StyledTableContainer, __assign({ maxHeight: maxHeight }, { children: [(0, jsx_runtime_1.jsxs)(Table_1.Table, __assign({ stickyHeader: true }, { children: [(0, jsx_runtime_1.jsx)(DataGridHead_1.DataGridHead, { onSort: onSort, rowsCount: rows.length, uncheckedRowsCount: uncheckedRowsCount, onSelectAllRows: handleSelectAllRows, selectable: selectable, sorting: sorting, columns: columns }), (0, jsx_runtime_1.jsx)(DataGridBody_1.DataGridBody, { keyId: keyId, selectedRows: selectedRows, minDisplayRows: minDisplayRows, onRowClick: onRowClick, onSelectRow: handleSelectRow, selectable: selectable, rows: rows, columns: columns, emptyCellValue: emptyCellValue })] })), (0, jsx_runtime_1.jsx)(DataGridLoader_1.default, { loading: loading })] })), Footer] }));
|
|
65
65
|
}
|
|
66
66
|
exports.DataGrid = DataGrid;
|
|
@@ -17,7 +17,7 @@ var react_1 = require("react");
|
|
|
17
17
|
var Table_1 = require("../../Table");
|
|
18
18
|
var DataGridCell_1 = require("../DataGridCell");
|
|
19
19
|
var Checkbox_1 = require("../../Checkbox");
|
|
20
|
-
var
|
|
20
|
+
var styles_1 = require("./styles");
|
|
21
21
|
function DataGridBody(_a) {
|
|
22
22
|
var rows = _a.rows, columns = _a.columns, selectable = _a.selectable, onRowClick = _a.onRowClick, onSelectRow = _a.onSelectRow, _b = _a.selectedRows, selectedRows = _b === void 0 ? [] : _b, minDisplayRows = _a.minDisplayRows, keyId = _a.keyId, emptyCellValue = _a.emptyCellValue;
|
|
23
23
|
var renderCells = (0, react_1.useCallback)(function (row, rowId) {
|
|
@@ -39,6 +39,6 @@ function DataGridBody(_a) {
|
|
|
39
39
|
return ((0, jsx_runtime_1.jsxs)(Table_1.TableRow, __assign({ hover: Boolean(onRowClick), onClick: handleRowClick(row) }, { children: [selectable && ((0, jsx_runtime_1.jsx)(Table_1.TableCell, __assign({ padding: "checkbox", onClick: function (event) { return event.stopPropagation(); } }, { children: (0, jsx_runtime_1.jsx)(Checkbox_1.Checkbox, { checked: checked, onChange: onSelectRow(row) }) }))), renderCells(row, rowId)] }), rowId));
|
|
40
40
|
});
|
|
41
41
|
}, [rows, keyId, selectable, selectedRows, onSelectRow, onRowClick, columns]);
|
|
42
|
-
return ((0, jsx_runtime_1.jsx)(
|
|
42
|
+
return ((0, jsx_runtime_1.jsx)(styles_1.StyledTableBody, __assign({ empty: !rows.length, minDisplayRows: minDisplayRows }, { children: renderedRows })));
|
|
43
43
|
}
|
|
44
44
|
exports.DataGridBody = DataGridBody;
|
|
File without changes
|
|
File without changes
|
|
@@ -4,8 +4,8 @@ export declare type DataGridHeadProps<Data = DataGridRow, SortField extends keyo
|
|
|
4
4
|
columns: DataGridColumns<Data>[];
|
|
5
5
|
selectable: boolean;
|
|
6
6
|
onSelectAllRows: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
7
|
-
sorting
|
|
8
|
-
onSort?: (sorting: DataGridSort<SortField>
|
|
7
|
+
sorting?: DataGridSort<SortField>;
|
|
8
|
+
onSort?: (sorting: DataGridSort<SortField> | undefined) => void;
|
|
9
9
|
uncheckedRowsCount: number;
|
|
10
10
|
rowsCount: number;
|
|
11
11
|
};
|
|
@@ -10,15 +10,6 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
14
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
15
|
-
if (ar || !(i in from)) {
|
|
16
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
17
|
-
ar[i] = from[i];
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
|
-
};
|
|
22
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
14
|
exports.DataGridHead = void 0;
|
|
24
15
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
@@ -29,37 +20,24 @@ var Checkbox_1 = require("../../Checkbox");
|
|
|
29
20
|
var constants_1 = require("../constants");
|
|
30
21
|
var DataGridHeadColumn_1 = require("../DataGridHeadColumn");
|
|
31
22
|
function DataGridHead(_a) {
|
|
32
|
-
var columns = _a.columns, selectable = _a.selectable, onSelectAllRows = _a.onSelectAllRows, rowsCount = _a.rowsCount, onSort = _a.onSort,
|
|
23
|
+
var columns = _a.columns, selectable = _a.selectable, onSelectAllRows = _a.onSelectAllRows, rowsCount = _a.rowsCount, onSort = _a.onSort, sorting = _a.sorting, uncheckedRowsCount = _a.uncheckedRowsCount;
|
|
33
24
|
var checked = (0, react_1.useMemo)(function () { return !Boolean(uncheckedRowsCount) && rowsCount > 0; }, [uncheckedRowsCount, rowsCount]);
|
|
34
25
|
var indeterminate = (0, react_1.useMemo)(function () { return uncheckedRowsCount > 0 && uncheckedRowsCount < rowsCount; }, [uncheckedRowsCount, rowsCount]);
|
|
35
26
|
var handleSort = (0, react_1.useCallback)(function (field) {
|
|
36
27
|
if (!onSort) {
|
|
37
28
|
return;
|
|
38
29
|
}
|
|
39
|
-
var
|
|
40
|
-
var fieldId = _a.fieldId;
|
|
41
|
-
return fieldId === field;
|
|
42
|
-
});
|
|
30
|
+
var isCurrentField = (sorting === null || sorting === void 0 ? void 0 : sorting.fieldId) === field;
|
|
43
31
|
// если для выбранного столбца текущая сортировка ASC - меняем на DESC
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
var fieldId = _a.fieldId;
|
|
47
|
-
return fieldId !== field;
|
|
48
|
-
}), true), [
|
|
49
|
-
{ fieldId: field, sort: constants_1.SortStates.DESC },
|
|
50
|
-
], false);
|
|
51
|
-
return onSort(newSorting);
|
|
52
|
-
// если для выбранного столбца текущая сортировка DESC - убираем сортировку
|
|
32
|
+
if (isCurrentField && sorting.sort === constants_1.SortStates.ASC) {
|
|
33
|
+
return onSort({ fieldId: field, sort: constants_1.SortStates.DESC });
|
|
53
34
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return fieldId !== field;
|
|
58
|
-
});
|
|
59
|
-
return onSort(newSorting);
|
|
35
|
+
// если для выбранного столбца текущая сортировка DESC - убираем сортировку
|
|
36
|
+
if (isCurrentField && sorting.sort === constants_1.SortStates.DESC) {
|
|
37
|
+
return onSort(undefined);
|
|
60
38
|
}
|
|
61
39
|
// если для выбранного столбца нет сортировки - добавляем сортировку ASC
|
|
62
|
-
onSort(
|
|
40
|
+
onSort({ fieldId: field, sort: constants_1.SortStates.ASC });
|
|
63
41
|
}, [sorting, onSort]);
|
|
64
42
|
var renderColumns = (0, react_1.useMemo)(function () {
|
|
65
43
|
return columns.map(function (_a) {
|
|
@@ -3,7 +3,7 @@ import { TableCellProps } from '@mui/material';
|
|
|
3
3
|
import { DataGridRow, DataGridSort } from '../types';
|
|
4
4
|
export declare type DataGridHeadColumnProps<Data = DataGridRow, SortField extends keyof Data = keyof Data> = {
|
|
5
5
|
onSort: (field: SortField) => void;
|
|
6
|
-
sorting
|
|
6
|
+
sorting?: DataGridSort<SortField>;
|
|
7
7
|
label?: string;
|
|
8
8
|
sortable?: boolean;
|
|
9
9
|
align?: TableCellProps['align'];
|
|
@@ -14,22 +14,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
exports.DataGridHeadColumn = void 0;
|
|
15
15
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
16
16
|
var react_1 = require("react");
|
|
17
|
-
var
|
|
17
|
+
var icons_1 = require("@astral/icons");
|
|
18
18
|
var constants_1 = require("../constants");
|
|
19
|
-
var
|
|
19
|
+
var styles_1 = require("./styles");
|
|
20
20
|
function DataGridHeadColumn(_a) {
|
|
21
21
|
var onSort = _a.onSort, field = _a.field, sortable = _a.sortable, align = _a.align, label = _a.label, sorting = _a.sorting, width = _a.width;
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
var sortIcon = (0, react_1.useMemo)(function () {
|
|
23
|
+
if (!sortable) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
if ((sorting === null || sorting === void 0 ? void 0 : sorting.fieldId) !== field) {
|
|
27
|
+
return (0, jsx_runtime_1.jsx)(icons_1.SortFillSm, {});
|
|
28
|
+
}
|
|
29
|
+
switch (sorting === null || sorting === void 0 ? void 0 : sorting.sort) {
|
|
30
|
+
case constants_1.SortStates.ASC:
|
|
31
|
+
return (0, jsx_runtime_1.jsx)(icons_1.SortUpFillSm, { color: "primary" });
|
|
32
|
+
case constants_1.SortStates.DESC:
|
|
33
|
+
return (0, jsx_runtime_1.jsx)(icons_1.SortDownFillSm, { color: "primary" });
|
|
34
|
+
default:
|
|
35
|
+
return (0, jsx_runtime_1.jsx)(icons_1.SortFillSm, {});
|
|
36
|
+
}
|
|
37
|
+
}, [sorting, sortable, field]);
|
|
28
38
|
var handleSortClick = function () {
|
|
29
39
|
if (field && sortable) {
|
|
30
40
|
onSort(field);
|
|
31
41
|
}
|
|
32
42
|
};
|
|
33
|
-
return ((0, jsx_runtime_1.
|
|
43
|
+
return ((0, jsx_runtime_1.jsx)(styles_1.StyledTableCell, __assign({ onClick: handleSortClick, align: align, width: width, sortable: sortable }, { children: (0, jsx_runtime_1.jsxs)(styles_1.TableCellTitle, __assign({ variant: "pointer" }, { children: [label, sortIcon] })) })));
|
|
34
44
|
}
|
|
35
45
|
exports.DataGridHeadColumn = DataGridHeadColumn;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TableCellProps } from '@mui/material';
|
|
2
|
+
import { CSSProperties } from 'react';
|
|
3
|
+
export declare const StyledTableCell: import("@emotion/styled").StyledComponent<TableCellProps & {
|
|
4
|
+
theme?: import("@emotion/react").Theme | undefined;
|
|
5
|
+
} & {
|
|
6
|
+
width?: CSSProperties['width'];
|
|
7
|
+
sortable?: boolean | undefined;
|
|
8
|
+
}, {}, {}>;
|
|
9
|
+
export declare const TableCellTitle: import("@emotion/styled").StyledComponent<Pick<import("../../Typography").TypographyProps, string | number | symbol> & import("react").RefAttributes<HTMLElement> & {
|
|
10
|
+
theme?: import("@emotion/react").Theme | undefined;
|
|
11
|
+
}, {}, {}>;
|
|
@@ -4,16 +4,13 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
|
|
|
4
4
|
return cooked;
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
7
|
+
exports.TableCellTitle = exports.StyledTableCell = void 0;
|
|
8
8
|
var styles_1 = require("../../styles");
|
|
9
9
|
var Table_1 = require("../../Table");
|
|
10
|
-
|
|
11
|
-
var hideSortIcon = _a.hideSortIcon;
|
|
12
|
-
return hideSortIcon && 'hidden';
|
|
13
|
-
});
|
|
10
|
+
var Typography_1 = require("../../Typography");
|
|
14
11
|
exports.StyledTableCell = (0, styles_1.styled)(Table_1.TableCell, {
|
|
15
|
-
shouldForwardProp: function (prop) { return prop !== 'width'; },
|
|
16
|
-
})(
|
|
12
|
+
shouldForwardProp: function (prop) { return prop !== 'width' && prop !== 'sortable'; },
|
|
13
|
+
})(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n width: ", ";\n padding: ", ";\n\n color: ", ";\n\n cursor: ", ";\n\n user-select: none;\n"], ["\n width: ", ";\n padding: ", ";\n\n color: ", ";\n\n cursor: ", ";\n\n user-select: none;\n"])), function (_a) {
|
|
17
14
|
var _b = _a.width, width = _b === void 0 ? 'auto' : _b;
|
|
18
15
|
return width;
|
|
19
16
|
}, function (_a) {
|
|
@@ -26,4 +23,5 @@ exports.StyledTableCell = (0, styles_1.styled)(Table_1.TableCell, {
|
|
|
26
23
|
var sortable = _a.sortable;
|
|
27
24
|
return (sortable ? 'pointer' : 'initial');
|
|
28
25
|
});
|
|
26
|
+
exports.TableCellTitle = (0, styles_1.styled)(Typography_1.Typography)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n display: flex;\n align-items: center;\n\n > svg {\n width: 16px;\n height: 16px;\n }\n"], ["\n display: flex;\n align-items: center;\n\n > svg {\n width: 16px;\n height: 16px;\n }\n"])));
|
|
29
27
|
var templateObject_1, templateObject_2;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
|
-
var
|
|
4
|
+
var styles_1 = require("./styles");
|
|
5
5
|
var DataGridLoader = function (_a) {
|
|
6
6
|
var _b = _a.loading, loading = _b === void 0 ? false : _b;
|
|
7
|
-
return ((0, jsx_runtime_1.jsxs)(
|
|
7
|
+
return ((0, jsx_runtime_1.jsxs)(styles_1.LoaderWrapper, { children: [loading && (0, jsx_runtime_1.jsx)(styles_1.Backdrop, {}), loading ? (0, jsx_runtime_1.jsx)(styles_1.StyledLinearProgress, {}) : (0, jsx_runtime_1.jsx)(styles_1.StyledDivider, {})] }));
|
|
8
8
|
};
|
|
9
9
|
exports.default = DataGridLoader;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './styles';
|
|
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./styles"), exports);
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -33,15 +33,15 @@ export declare type DataGridProps<Data extends object = DataGridRow, SortField e
|
|
|
33
33
|
*/
|
|
34
34
|
onSelectRow?: (row: Data[]) => void;
|
|
35
35
|
/**
|
|
36
|
-
* @example <DataGrid sorting={
|
|
37
|
-
*
|
|
36
|
+
* @example <DataGrid sorting={{fieldId: 'test', sort: 'asc'}} />
|
|
37
|
+
* Параметры сортируемой колонки
|
|
38
38
|
*/
|
|
39
|
-
sorting?: DataGridSort<SortField
|
|
39
|
+
sorting?: DataGridSort<SortField>;
|
|
40
40
|
/**
|
|
41
41
|
* @example <DataGrid onSort={({fieldId: 'test', sort: 'asc'}) => console.log('sorted')} />
|
|
42
42
|
* Обработчик сортировки
|
|
43
43
|
*/
|
|
44
|
-
onSort?: (sorting: DataGridSort<SortField>
|
|
44
|
+
onSort?: (sorting: DataGridSort<SortField> | undefined) => void;
|
|
45
45
|
/**
|
|
46
46
|
* @example <DataGrid Footer={<DataGridPagination />} />
|
|
47
47
|
* Компонент кастомного футера (н-р Pagination)
|
|
@@ -66,7 +66,7 @@ export declare type DataGridProps<Data extends object = DataGridRow, SortField e
|
|
|
66
66
|
/**
|
|
67
67
|
* @default 10
|
|
68
68
|
* @example <DataGrid minDisplayRows{10} />
|
|
69
|
-
*
|
|
69
|
+
* Используется для отображения переданного кол-ва строк при отсутствии данных
|
|
70
70
|
*/
|
|
71
71
|
minDisplayRows?: number;
|
|
72
72
|
};
|
package/esm/DataGrid/DataGrid.js
CHANGED
|
@@ -24,9 +24,9 @@ import { Table } from '../Table';
|
|
|
24
24
|
import { DataGridHead } from './DataGridHead';
|
|
25
25
|
import { DataGridBody } from './DataGridBody';
|
|
26
26
|
import DataGridLoader from './DataGridLoader/DataGridLoader';
|
|
27
|
-
import { DataGridContainer, StyledTableContainer } from './
|
|
27
|
+
import { DataGridContainer, StyledTableContainer } from './styles';
|
|
28
28
|
export function DataGrid(_a) {
|
|
29
|
-
var columns = _a.columns, _b = _a.rows, rows = _b === void 0 ? [] : _b, _c = _a.selectedRows, selectedRows = _c === void 0 ? [] : _c,
|
|
29
|
+
var columns = _a.columns, _b = _a.rows, rows = _b === void 0 ? [] : _b, _c = _a.selectedRows, selectedRows = _c === void 0 ? [] : _c, sorting = _a.sorting, maxHeight = _a.maxHeight, _d = _a.minDisplayRows, minDisplayRows = _d === void 0 ? 10 : _d, onRowClick = _a.onRowClick, onSelectRow = _a.onSelectRow, Footer = _a.Footer, loading = _a.loading, onSort = _a.onSort, keyId = _a.keyId, emptyCellValue = _a.emptyCellValue;
|
|
30
30
|
var selectable = Boolean(onSelectRow);
|
|
31
31
|
var handleSelectAllRows = function (event) {
|
|
32
32
|
if (!onSelectRow) {
|
|
@@ -14,7 +14,7 @@ import { useCallback, useMemo } from 'react';
|
|
|
14
14
|
import { TableCell, TableRow } from '../../Table';
|
|
15
15
|
import { DataGridCell } from '../DataGridCell';
|
|
16
16
|
import { Checkbox } from '../../Checkbox';
|
|
17
|
-
import { StyledTableBody } from './
|
|
17
|
+
import { StyledTableBody } from './styles';
|
|
18
18
|
export function DataGridBody(_a) {
|
|
19
19
|
var rows = _a.rows, columns = _a.columns, selectable = _a.selectable, onRowClick = _a.onRowClick, onSelectRow = _a.onSelectRow, _b = _a.selectedRows, selectedRows = _b === void 0 ? [] : _b, minDisplayRows = _a.minDisplayRows, keyId = _a.keyId, emptyCellValue = _a.emptyCellValue;
|
|
20
20
|
var renderCells = useCallback(function (row, rowId) {
|
|
File without changes
|
|
File without changes
|
|
@@ -4,8 +4,8 @@ export declare type DataGridHeadProps<Data = DataGridRow, SortField extends keyo
|
|
|
4
4
|
columns: DataGridColumns<Data>[];
|
|
5
5
|
selectable: boolean;
|
|
6
6
|
onSelectAllRows: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
7
|
-
sorting
|
|
8
|
-
onSort?: (sorting: DataGridSort<SortField>
|
|
7
|
+
sorting?: DataGridSort<SortField>;
|
|
8
|
+
onSort?: (sorting: DataGridSort<SortField> | undefined) => void;
|
|
9
9
|
uncheckedRowsCount: number;
|
|
10
10
|
rowsCount: number;
|
|
11
11
|
};
|
|
@@ -9,15 +9,6 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
-
if (ar || !(i in from)) {
|
|
15
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
-
ar[i] = from[i];
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
-
};
|
|
21
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
13
|
import { useCallback, useMemo } from 'react';
|
|
23
14
|
import { TableHead } from '../../Table/TableHead';
|
|
@@ -26,37 +17,24 @@ import { Checkbox } from '../../Checkbox';
|
|
|
26
17
|
import { SortStates } from '../constants';
|
|
27
18
|
import { DataGridHeadColumn } from '../DataGridHeadColumn';
|
|
28
19
|
export function DataGridHead(_a) {
|
|
29
|
-
var columns = _a.columns, selectable = _a.selectable, onSelectAllRows = _a.onSelectAllRows, rowsCount = _a.rowsCount, onSort = _a.onSort,
|
|
20
|
+
var columns = _a.columns, selectable = _a.selectable, onSelectAllRows = _a.onSelectAllRows, rowsCount = _a.rowsCount, onSort = _a.onSort, sorting = _a.sorting, uncheckedRowsCount = _a.uncheckedRowsCount;
|
|
30
21
|
var checked = useMemo(function () { return !Boolean(uncheckedRowsCount) && rowsCount > 0; }, [uncheckedRowsCount, rowsCount]);
|
|
31
22
|
var indeterminate = useMemo(function () { return uncheckedRowsCount > 0 && uncheckedRowsCount < rowsCount; }, [uncheckedRowsCount, rowsCount]);
|
|
32
23
|
var handleSort = useCallback(function (field) {
|
|
33
24
|
if (!onSort) {
|
|
34
25
|
return;
|
|
35
26
|
}
|
|
36
|
-
var
|
|
37
|
-
var fieldId = _a.fieldId;
|
|
38
|
-
return fieldId === field;
|
|
39
|
-
});
|
|
27
|
+
var isCurrentField = (sorting === null || sorting === void 0 ? void 0 : sorting.fieldId) === field;
|
|
40
28
|
// если для выбранного столбца текущая сортировка ASC - меняем на DESC
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
var fieldId = _a.fieldId;
|
|
44
|
-
return fieldId !== field;
|
|
45
|
-
}), true), [
|
|
46
|
-
{ fieldId: field, sort: SortStates.DESC },
|
|
47
|
-
], false);
|
|
48
|
-
return onSort(newSorting);
|
|
49
|
-
// если для выбранного столбца текущая сортировка DESC - убираем сортировку
|
|
29
|
+
if (isCurrentField && sorting.sort === SortStates.ASC) {
|
|
30
|
+
return onSort({ fieldId: field, sort: SortStates.DESC });
|
|
50
31
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return fieldId !== field;
|
|
55
|
-
});
|
|
56
|
-
return onSort(newSorting);
|
|
32
|
+
// если для выбранного столбца текущая сортировка DESC - убираем сортировку
|
|
33
|
+
if (isCurrentField && sorting.sort === SortStates.DESC) {
|
|
34
|
+
return onSort(undefined);
|
|
57
35
|
}
|
|
58
36
|
// если для выбранного столбца нет сортировки - добавляем сортировку ASC
|
|
59
|
-
onSort(
|
|
37
|
+
onSort({ fieldId: field, sort: SortStates.ASC });
|
|
60
38
|
}, [sorting, onSort]);
|
|
61
39
|
var renderColumns = useMemo(function () {
|
|
62
40
|
return columns.map(function (_a) {
|
|
@@ -3,7 +3,7 @@ import { TableCellProps } from '@mui/material';
|
|
|
3
3
|
import { DataGridRow, DataGridSort } from '../types';
|
|
4
4
|
export declare type DataGridHeadColumnProps<Data = DataGridRow, SortField extends keyof Data = keyof Data> = {
|
|
5
5
|
onSort: (field: SortField) => void;
|
|
6
|
-
sorting
|
|
6
|
+
sorting?: DataGridSort<SortField>;
|
|
7
7
|
label?: string;
|
|
8
8
|
sortable?: boolean;
|
|
9
9
|
align?: TableCellProps['align'];
|
|
@@ -11,21 +11,31 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
import { useMemo } from 'react';
|
|
14
|
-
import {
|
|
14
|
+
import { SortDownFillSm, SortFillSm, SortUpFillSm } from '@astral/icons';
|
|
15
15
|
import { SortStates } from '../constants';
|
|
16
|
-
import { StyledTableCell,
|
|
16
|
+
import { StyledTableCell, TableCellTitle } from './styles';
|
|
17
17
|
export function DataGridHeadColumn(_a) {
|
|
18
18
|
var onSort = _a.onSort, field = _a.field, sortable = _a.sortable, align = _a.align, label = _a.label, sorting = _a.sorting, width = _a.width;
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
var sortIcon = useMemo(function () {
|
|
20
|
+
if (!sortable) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
if ((sorting === null || sorting === void 0 ? void 0 : sorting.fieldId) !== field) {
|
|
24
|
+
return _jsx(SortFillSm, {});
|
|
25
|
+
}
|
|
26
|
+
switch (sorting === null || sorting === void 0 ? void 0 : sorting.sort) {
|
|
27
|
+
case SortStates.ASC:
|
|
28
|
+
return _jsx(SortUpFillSm, { color: "primary" });
|
|
29
|
+
case SortStates.DESC:
|
|
30
|
+
return _jsx(SortDownFillSm, { color: "primary" });
|
|
31
|
+
default:
|
|
32
|
+
return _jsx(SortFillSm, {});
|
|
33
|
+
}
|
|
34
|
+
}, [sorting, sortable, field]);
|
|
25
35
|
var handleSortClick = function () {
|
|
26
36
|
if (field && sortable) {
|
|
27
37
|
onSort(field);
|
|
28
38
|
}
|
|
29
39
|
};
|
|
30
|
-
return (
|
|
40
|
+
return (_jsx(StyledTableCell, __assign({ onClick: handleSortClick, align: align, width: width, sortable: sortable }, { children: _jsxs(TableCellTitle, __assign({ variant: "pointer" }, { children: [label, sortIcon] })) })));
|
|
31
41
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TableCellProps } from '@mui/material';
|
|
2
|
+
import { CSSProperties } from 'react';
|
|
3
|
+
export declare const StyledTableCell: import("@emotion/styled").StyledComponent<TableCellProps & {
|
|
4
|
+
theme?: import("@emotion/react").Theme | undefined;
|
|
5
|
+
} & {
|
|
6
|
+
width?: CSSProperties['width'];
|
|
7
|
+
sortable?: boolean | undefined;
|
|
8
|
+
}, {}, {}>;
|
|
9
|
+
export declare const TableCellTitle: import("@emotion/styled").StyledComponent<Pick<import("../../Typography").TypographyProps, string | number | symbol> & import("react").RefAttributes<HTMLElement> & {
|
|
10
|
+
theme?: import("@emotion/react").Theme | undefined;
|
|
11
|
+
}, {}, {}>;
|
|
@@ -3,14 +3,11 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
|
|
|
3
3
|
return cooked;
|
|
4
4
|
};
|
|
5
5
|
import { styled } from '../../styles';
|
|
6
|
-
import { TableCell
|
|
7
|
-
|
|
8
|
-
var hideSortIcon = _a.hideSortIcon;
|
|
9
|
-
return hideSortIcon && 'hidden';
|
|
10
|
-
});
|
|
6
|
+
import { TableCell } from '../../Table';
|
|
7
|
+
import { Typography } from '../../Typography';
|
|
11
8
|
export var StyledTableCell = styled(TableCell, {
|
|
12
|
-
shouldForwardProp: function (prop) { return prop !== 'width'; },
|
|
13
|
-
})(
|
|
9
|
+
shouldForwardProp: function (prop) { return prop !== 'width' && prop !== 'sortable'; },
|
|
10
|
+
})(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n width: ", ";\n padding: ", ";\n\n color: ", ";\n\n cursor: ", ";\n\n user-select: none;\n"], ["\n width: ", ";\n padding: ", ";\n\n color: ", ";\n\n cursor: ", ";\n\n user-select: none;\n"])), function (_a) {
|
|
14
11
|
var _b = _a.width, width = _b === void 0 ? 'auto' : _b;
|
|
15
12
|
return width;
|
|
16
13
|
}, function (_a) {
|
|
@@ -23,4 +20,5 @@ export var StyledTableCell = styled(TableCell, {
|
|
|
23
20
|
var sortable = _a.sortable;
|
|
24
21
|
return (sortable ? 'pointer' : 'initial');
|
|
25
22
|
});
|
|
23
|
+
export var TableCellTitle = styled(Typography)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n display: flex;\n align-items: center;\n\n > svg {\n width: 16px;\n height: 16px;\n }\n"], ["\n display: flex;\n align-items: center;\n\n > svg {\n width: 16px;\n height: 16px;\n }\n"])));
|
|
26
24
|
var templateObject_1, templateObject_2;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Backdrop, LoaderWrapper, StyledDivider, StyledLinearProgress, } from './
|
|
2
|
+
import { Backdrop, LoaderWrapper, StyledDivider, StyledLinearProgress, } from './styles';
|
|
3
3
|
var DataGridLoader = function (_a) {
|
|
4
4
|
var _b = _a.loading, loading = _b === void 0 ? false : _b;
|
|
5
5
|
return (_jsxs(LoaderWrapper, { children: [loading && _jsx(Backdrop, {}), loading ? _jsx(StyledLinearProgress, {}) : _jsx(StyledDivider, {})] }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './styles';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './styles';
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astral/ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"browser": "./src/index.ts",
|
|
5
5
|
"jest": {
|
|
6
6
|
"moduleNameMapper": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
}
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@astral/icons": "^1.
|
|
11
|
+
"@astral/icons": "^1.3.0",
|
|
12
12
|
"@emotion/cache": "11.7.1",
|
|
13
13
|
"@emotion/react": "11.9.0",
|
|
14
14
|
"@emotion/server": "11.4.0",
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { TableCellProps } from '@mui/material';
|
|
2
|
-
import { CSSProperties } from 'react';
|
|
3
|
-
export declare const StyledTableSortLabel: import("@emotion/styled").StyledComponent<{
|
|
4
|
-
active?: boolean | undefined;
|
|
5
|
-
children?: import("react").ReactNode;
|
|
6
|
-
classes?: Partial<import("@mui/material").TableSortLabelClasses> | undefined;
|
|
7
|
-
direction?: "desc" | "asc" | undefined;
|
|
8
|
-
hideSortIcon?: boolean | undefined;
|
|
9
|
-
IconComponent?: import("react").JSXElementConstructor<{
|
|
10
|
-
className: string;
|
|
11
|
-
}> | undefined;
|
|
12
|
-
sx?: import("@mui/material").SxProps<import("@mui/material").Theme> | undefined;
|
|
13
|
-
} & Omit<{
|
|
14
|
-
action?: import("react").Ref<import("@mui/material").ButtonBaseActions> | undefined;
|
|
15
|
-
centerRipple?: boolean | undefined;
|
|
16
|
-
children?: import("react").ReactNode;
|
|
17
|
-
classes?: Partial<import("@mui/material").ButtonBaseClasses> | undefined;
|
|
18
|
-
disabled?: boolean | undefined;
|
|
19
|
-
disableRipple?: boolean | undefined;
|
|
20
|
-
disableTouchRipple?: boolean | undefined;
|
|
21
|
-
focusRipple?: boolean | undefined;
|
|
22
|
-
focusVisibleClassName?: string | undefined;
|
|
23
|
-
LinkComponent?: import("react").ElementType<any> | undefined;
|
|
24
|
-
onFocusVisible?: import("react").FocusEventHandler<any> | undefined;
|
|
25
|
-
sx?: import("@mui/material").SxProps<import("@mui/material").Theme> | undefined;
|
|
26
|
-
tabIndex?: number | undefined;
|
|
27
|
-
TouchRippleProps?: Partial<import("@mui/material/ButtonBase/TouchRipple").TouchRippleProps> | undefined;
|
|
28
|
-
touchRippleRef?: import("react").Ref<import("@mui/material/ButtonBase/TouchRipple").TouchRippleActions> | undefined;
|
|
29
|
-
}, "classes"> & import("@mui/material/OverridableComponent").CommonProps & Omit<Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "key" | "css" | keyof import("react").HTMLAttributes<HTMLSpanElement>> & {
|
|
30
|
-
ref?: ((instance: HTMLSpanElement | null) => void) | import("react").RefObject<HTMLSpanElement> | null | undefined;
|
|
31
|
-
}, "disabled" | "active" | "onFocusVisible" | "tabIndex" | "action" | "children" | "direction" | keyof import("@mui/material/OverridableComponent").CommonProps | "centerRipple" | "disableRipple" | "disableTouchRipple" | "focusRipple" | "focusVisibleClassName" | "LinkComponent" | "sx" | "TouchRippleProps" | "touchRippleRef" | "hideSortIcon" | "IconComponent"> & {
|
|
32
|
-
theme?: import("@emotion/react").Theme | undefined;
|
|
33
|
-
}, {}, {}>;
|
|
34
|
-
export declare const StyledTableCell: import("@emotion/styled").StyledComponent<TableCellProps & {
|
|
35
|
-
theme?: import("@emotion/react").Theme | undefined;
|
|
36
|
-
} & {
|
|
37
|
-
width?: CSSProperties['width'];
|
|
38
|
-
sortable?: boolean | undefined;
|
|
39
|
-
}, {}, {}>;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { TableCellProps } from '@mui/material';
|
|
2
|
-
import { CSSProperties } from 'react';
|
|
3
|
-
export declare const StyledTableSortLabel: import("@emotion/styled").StyledComponent<{
|
|
4
|
-
active?: boolean | undefined;
|
|
5
|
-
children?: import("react").ReactNode;
|
|
6
|
-
classes?: Partial<import("@mui/material").TableSortLabelClasses> | undefined;
|
|
7
|
-
direction?: "desc" | "asc" | undefined;
|
|
8
|
-
hideSortIcon?: boolean | undefined;
|
|
9
|
-
IconComponent?: import("react").JSXElementConstructor<{
|
|
10
|
-
className: string;
|
|
11
|
-
}> | undefined;
|
|
12
|
-
sx?: import("@mui/material").SxProps<import("@mui/material").Theme> | undefined;
|
|
13
|
-
} & Omit<{
|
|
14
|
-
action?: import("react").Ref<import("@mui/material").ButtonBaseActions> | undefined;
|
|
15
|
-
centerRipple?: boolean | undefined;
|
|
16
|
-
children?: import("react").ReactNode;
|
|
17
|
-
classes?: Partial<import("@mui/material").ButtonBaseClasses> | undefined;
|
|
18
|
-
disabled?: boolean | undefined;
|
|
19
|
-
disableRipple?: boolean | undefined;
|
|
20
|
-
disableTouchRipple?: boolean | undefined;
|
|
21
|
-
focusRipple?: boolean | undefined;
|
|
22
|
-
focusVisibleClassName?: string | undefined;
|
|
23
|
-
LinkComponent?: import("react").ElementType<any> | undefined;
|
|
24
|
-
onFocusVisible?: import("react").FocusEventHandler<any> | undefined;
|
|
25
|
-
sx?: import("@mui/material").SxProps<import("@mui/material").Theme> | undefined;
|
|
26
|
-
tabIndex?: number | undefined;
|
|
27
|
-
TouchRippleProps?: Partial<import("@mui/material/ButtonBase/TouchRipple").TouchRippleProps> | undefined;
|
|
28
|
-
touchRippleRef?: import("react").Ref<import("@mui/material/ButtonBase/TouchRipple").TouchRippleActions> | undefined;
|
|
29
|
-
}, "classes"> & import("@mui/material/OverridableComponent").CommonProps & Omit<Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "key" | "css" | keyof import("react").HTMLAttributes<HTMLSpanElement>> & {
|
|
30
|
-
ref?: ((instance: HTMLSpanElement | null) => void) | import("react").RefObject<HTMLSpanElement> | null | undefined;
|
|
31
|
-
}, "disabled" | "active" | "onFocusVisible" | "tabIndex" | "action" | "children" | "direction" | keyof import("@mui/material/OverridableComponent").CommonProps | "centerRipple" | "disableRipple" | "disableTouchRipple" | "focusRipple" | "focusVisibleClassName" | "LinkComponent" | "sx" | "TouchRippleProps" | "touchRippleRef" | "hideSortIcon" | "IconComponent"> & {
|
|
32
|
-
theme?: import("@emotion/react").Theme | undefined;
|
|
33
|
-
}, {}, {}>;
|
|
34
|
-
export declare const StyledTableCell: import("@emotion/styled").StyledComponent<TableCellProps & {
|
|
35
|
-
theme?: import("@emotion/react").Theme | undefined;
|
|
36
|
-
} & {
|
|
37
|
-
width?: CSSProperties['width'];
|
|
38
|
-
sortable?: boolean | undefined;
|
|
39
|
-
}, {}, {}>;
|