@azrico/reactgrid 1.6.2 → 1.6.5
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/CHANGELOG.md +33 -19
- package/README.md +165 -164
- package/__tests__/context-menu.config.cjs +14 -0
- package/__tests__/context-menu.test.js +150 -0
- package/config/generate-theme.cjs +1 -1
- package/config/theme-extras.css +11 -16
- package/dist/src/example.js +27 -2
- package/dist/src/func/func_a11y.d.ts +14 -0
- package/dist/src/func/func_a11y.js +63 -10
- package/dist/src/func/func_grid.d.ts +6 -0
- package/dist/src/func/func_grid.js +15 -4
- package/dist/src/hooks/useGridEvents.js +16 -4
- package/dist/src/themes/azgrid-theme.css +12 -17
- package/dist/src/types/types.d.ts +4 -0
- package/dist/src/views/DataGrid.js +10 -22
- package/package.json +1 -1
- package/src/example.tsx +202 -186
- package/src/func/func_a11y.ts +62 -4
- package/src/func/func_grid.ts +351 -340
- package/src/hooks/useGridEvents.ts +171 -158
- package/src/themes/azgrid-theme.css +12 -17
- package/src/types/types.ts +157 -153
- package/src/views/DataGrid.tsx +9 -17
package/src/types/types.ts
CHANGED
|
@@ -1,153 +1,157 @@
|
|
|
1
|
-
import { ModifyFields } from '../func/func_grid';
|
|
2
|
-
import { ConvertableToMenuItem } from '@azrico/controls/context-menu';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import {
|
|
5
|
-
TypeCellSelection,
|
|
6
|
-
TypeColumn,
|
|
7
|
-
TypeDataGridProps,
|
|
8
|
-
TypeDataSource,
|
|
9
|
-
TypeEditInfo,
|
|
10
|
-
TypeFilterTypes,
|
|
11
|
-
TypeFilterValue,
|
|
12
|
-
TypeRowDetailsInfo,
|
|
13
|
-
TypeRowProps,
|
|
14
|
-
TypeRowSelection,
|
|
15
|
-
TypeComputedProps,
|
|
16
|
-
TypeSortInfo,
|
|
17
|
-
TypeGroupBy,
|
|
18
|
-
} from '@inovua/reactdatagrid-community/types';
|
|
19
|
-
|
|
20
|
-
import { TypeOnSelectionChangeArg } from '@inovua/reactdatagrid-community/types/TypeDataGridProps';
|
|
21
|
-
|
|
22
|
-
/* -------------------------------------------------------------------------- */
|
|
23
|
-
export type ColumnDefinition = TypeColumn;
|
|
24
|
-
export type CellDefinition = any;
|
|
25
|
-
export type RowDefinition = any;
|
|
26
|
-
export type RowProps = TypeRowProps;
|
|
27
|
-
export type RowSelectionValue = TypeRowSelection;
|
|
28
|
-
export type CellSelectionValue = TypeCellSelection;
|
|
29
|
-
export type DataRowDefinition = any;
|
|
30
|
-
export type FilterTypes = TypeFilterTypes;
|
|
31
|
-
export type FilterValues = TypeFilterValue;
|
|
32
|
-
export type DataSourceDefinition = TypeDataSource;
|
|
33
|
-
export type OnSelectionChangeFunc = (config: TypeOnSelectionChangeArg) => void;
|
|
34
|
-
export type OnCellSelectionChangeFunc = (s: { [key: string]: boolean }) => void;
|
|
35
|
-
export type RowDetailsFunc = (rowDetailsInfo: TypeRowDetailsInfo) => React.ReactNode;
|
|
36
|
-
|
|
37
|
-
export type loose_column_names = {
|
|
38
|
-
key: string;
|
|
39
|
-
field: string;
|
|
40
|
-
columnName: string;
|
|
41
|
-
name: string;
|
|
42
|
-
};
|
|
43
|
-
export type loose_column_fields = loose_column_names & {
|
|
44
|
-
title: string;
|
|
45
|
-
type: string;
|
|
46
|
-
items: any[];
|
|
47
|
-
/** accessible name for cells whose visible text isn't descriptive (icons, badges, ...), set as aria-label */
|
|
48
|
-
ariaLabel: (value: any, data: any) => string;
|
|
49
|
-
};
|
|
50
|
-
export type LooseColumnDefinition = Partial<loose_column_fields & ColumnDefinition>;
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
export type CustomColumnDefinition = {
|
|
54
|
-
name: string;
|
|
55
|
-
render: (cell: any, formatterParams, onRendered) => React.ReactNode | undefined | null;
|
|
56
|
-
};
|
|
57
|
-
export type AzGridOptions = Partial<TypeDataGridProps> & {
|
|
58
|
-
/** called for every rendered row, after the grid's own row attributes are set */
|
|
59
|
-
onRenderRow?: (rowProps: any) => void;
|
|
60
|
-
/** extra DOM props for the header row */
|
|
61
|
-
headerProps?: { [key: string]: any };
|
|
62
|
-
};
|
|
63
|
-
/** arguments passed to a dataSource function */
|
|
64
|
-
export type AzDataSourceParams = {
|
|
65
|
-
skip?: number;
|
|
66
|
-
limit?: number;
|
|
67
|
-
/** current header filters, filter.value is an array of selected ids for a multi-select SelectFilter */
|
|
68
|
-
filterValue?: TypeFilterValue;
|
|
69
|
-
sortInfo?: TypeSortInfo;
|
|
70
|
-
groupBy?: TypeGroupBy;
|
|
71
|
-
cached_data: React.MutableRefObject<any>;
|
|
72
|
-
last_cache_info: React.MutableRefObject<any>;
|
|
73
|
-
};
|
|
74
|
-
export type AzDataSourceFunc = (args: AzDataSourceParams) => any[] | Promise<any[] | any>;
|
|
75
|
-
/* -------------------------------------------------------------------------- */
|
|
76
|
-
export type AzGridProps = {
|
|
77
|
-
dataSource?: any[] | AzDataSourceFunc;
|
|
78
|
-
details_dataSource?: any[] | AzDataSourceFunc; //details is rendered under each row
|
|
79
|
-
details_columns?: LooseColumnDefinition[];
|
|
80
|
-
details_filter?: FilterValues;
|
|
81
|
-
|
|
82
|
-
licenseKey?: string;
|
|
83
|
-
/** accessible name of the grid, set as aria-label on the grid root */
|
|
84
|
-
ariaLabel?: string;
|
|
85
|
-
|
|
86
|
-
gridRef?: React.MutableRefObject<TypeComputedProps>;
|
|
87
|
-
gridOptions?: AzGridOptions;
|
|
88
|
-
|
|
89
|
-
columns?: LooseColumnDefinition[];
|
|
90
|
-
columnExtensions?: Partial<LooseColumnDefinition>;
|
|
91
|
-
|
|
92
|
-
editableColumns?: string[];
|
|
93
|
-
leftColumns?: string[];
|
|
94
|
-
rightColumns?: string[];
|
|
95
|
-
customColumns?: CustomColumnDefinition[];
|
|
96
|
-
|
|
97
|
-
contextMenuItems?: ConvertableToMenuItem;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
1
|
+
import { ModifyFields } from '../func/func_grid';
|
|
2
|
+
import { ConvertableToMenuItem } from '@azrico/controls/context-menu';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import {
|
|
5
|
+
TypeCellSelection,
|
|
6
|
+
TypeColumn,
|
|
7
|
+
TypeDataGridProps,
|
|
8
|
+
TypeDataSource,
|
|
9
|
+
TypeEditInfo,
|
|
10
|
+
TypeFilterTypes,
|
|
11
|
+
TypeFilterValue,
|
|
12
|
+
TypeRowDetailsInfo,
|
|
13
|
+
TypeRowProps,
|
|
14
|
+
TypeRowSelection,
|
|
15
|
+
TypeComputedProps,
|
|
16
|
+
TypeSortInfo,
|
|
17
|
+
TypeGroupBy,
|
|
18
|
+
} from '@inovua/reactdatagrid-community/types';
|
|
19
|
+
|
|
20
|
+
import { TypeOnSelectionChangeArg } from '@inovua/reactdatagrid-community/types/TypeDataGridProps';
|
|
21
|
+
|
|
22
|
+
/* -------------------------------------------------------------------------- */
|
|
23
|
+
export type ColumnDefinition = TypeColumn;
|
|
24
|
+
export type CellDefinition = any;
|
|
25
|
+
export type RowDefinition = any;
|
|
26
|
+
export type RowProps = TypeRowProps;
|
|
27
|
+
export type RowSelectionValue = TypeRowSelection;
|
|
28
|
+
export type CellSelectionValue = TypeCellSelection;
|
|
29
|
+
export type DataRowDefinition = any;
|
|
30
|
+
export type FilterTypes = TypeFilterTypes;
|
|
31
|
+
export type FilterValues = TypeFilterValue;
|
|
32
|
+
export type DataSourceDefinition = TypeDataSource;
|
|
33
|
+
export type OnSelectionChangeFunc = (config: TypeOnSelectionChangeArg) => void;
|
|
34
|
+
export type OnCellSelectionChangeFunc = (s: { [key: string]: boolean }) => void;
|
|
35
|
+
export type RowDetailsFunc = (rowDetailsInfo: TypeRowDetailsInfo) => React.ReactNode;
|
|
36
|
+
|
|
37
|
+
export type loose_column_names = {
|
|
38
|
+
key: string;
|
|
39
|
+
field: string;
|
|
40
|
+
columnName: string;
|
|
41
|
+
name: string;
|
|
42
|
+
};
|
|
43
|
+
export type loose_column_fields = loose_column_names & {
|
|
44
|
+
title: string;
|
|
45
|
+
type: string;
|
|
46
|
+
items: any[];
|
|
47
|
+
/** accessible name for cells whose visible text isn't descriptive (icons, badges, ...), set as aria-label */
|
|
48
|
+
ariaLabel: (value: any, data: any) => string;
|
|
49
|
+
};
|
|
50
|
+
export type LooseColumnDefinition = Partial<loose_column_fields & ColumnDefinition>;
|
|
51
|
+
//
|
|
52
|
+
|
|
53
|
+
export type CustomColumnDefinition = {
|
|
54
|
+
name: string;
|
|
55
|
+
render: (cell: any, formatterParams, onRendered) => React.ReactNode | undefined | null;
|
|
56
|
+
};
|
|
57
|
+
export type AzGridOptions = Partial<TypeDataGridProps> & {
|
|
58
|
+
/** called for every rendered row, after the grid's own row attributes are set */
|
|
59
|
+
onRenderRow?: (rowProps: any) => void;
|
|
60
|
+
/** extra DOM props for the header row */
|
|
61
|
+
headerProps?: { [key: string]: any };
|
|
62
|
+
};
|
|
63
|
+
/** arguments passed to a dataSource function */
|
|
64
|
+
export type AzDataSourceParams = {
|
|
65
|
+
skip?: number;
|
|
66
|
+
limit?: number;
|
|
67
|
+
/** current header filters, filter.value is an array of selected ids for a multi-select SelectFilter */
|
|
68
|
+
filterValue?: TypeFilterValue;
|
|
69
|
+
sortInfo?: TypeSortInfo;
|
|
70
|
+
groupBy?: TypeGroupBy;
|
|
71
|
+
cached_data: React.MutableRefObject<any>;
|
|
72
|
+
last_cache_info: React.MutableRefObject<any>;
|
|
73
|
+
};
|
|
74
|
+
export type AzDataSourceFunc = (args: AzDataSourceParams) => any[] | Promise<any[] | any>;
|
|
75
|
+
/* -------------------------------------------------------------------------- */
|
|
76
|
+
export type AzGridProps = {
|
|
77
|
+
dataSource?: any[] | AzDataSourceFunc;
|
|
78
|
+
details_dataSource?: any[] | AzDataSourceFunc; //details is rendered under each row
|
|
79
|
+
details_columns?: LooseColumnDefinition[];
|
|
80
|
+
details_filter?: FilterValues;
|
|
81
|
+
|
|
82
|
+
licenseKey?: string;
|
|
83
|
+
/** accessible name of the grid, set as aria-label on the grid root */
|
|
84
|
+
ariaLabel?: string;
|
|
85
|
+
|
|
86
|
+
gridRef?: React.MutableRefObject<TypeComputedProps>;
|
|
87
|
+
gridOptions?: AzGridOptions;
|
|
88
|
+
|
|
89
|
+
columns?: LooseColumnDefinition[];
|
|
90
|
+
columnExtensions?: Partial<LooseColumnDefinition>;
|
|
91
|
+
|
|
92
|
+
editableColumns?: string[];
|
|
93
|
+
leftColumns?: string[];
|
|
94
|
+
rightColumns?: string[];
|
|
95
|
+
customColumns?: CustomColumnDefinition[];
|
|
96
|
+
|
|
97
|
+
contextMenuItems?: ConvertableToMenuItem;
|
|
98
|
+
/** Extra classes on the row context menu, which is portaled to <body> */
|
|
99
|
+
contextMenuClassName?: string;
|
|
100
|
+
|
|
101
|
+
highlightedRow?: any;
|
|
102
|
+
RowDetail?: RowDetailsFunc;
|
|
103
|
+
|
|
104
|
+
selected?: RowSelectionValue;
|
|
105
|
+
cellSelection?: CellSelectionValue;
|
|
106
|
+
/* -------------------------------------------------------------------------- */
|
|
107
|
+
onEditComplete?: (editInfo: TypeEditInfo) => void;
|
|
108
|
+
onSelectionChange?: OnSelectionChangeFunc;
|
|
109
|
+
onCellSelectionChange?: OnCellSelectionChangeFunc;
|
|
110
|
+
|
|
111
|
+
onRowClick?: (rowIndex: number, row: any) => void;
|
|
112
|
+
onRowDoubleClick?: (rowIndex: number, row: any) => void;
|
|
113
|
+
onLimitChange?: (v: number) => void;
|
|
114
|
+
onSkipChange?: (v: number) => void;
|
|
115
|
+
/* -------------------------------------------------------------------------- */
|
|
116
|
+
skip?: number;
|
|
117
|
+
limit?: number;
|
|
118
|
+
//
|
|
119
|
+
editable?: boolean | ((editValue: any, cellProps: any) => boolean);
|
|
120
|
+
advancedFilterFields?: string[];
|
|
121
|
+
/** Label of the quick-search box shown with `advancedFilterFields`. Default "Search". */
|
|
122
|
+
advancedFilterLabel?: React.ReactNode;
|
|
123
|
+
/** Placeholder of the quick-search input. A string is used as the native placeholder, any other node (custom HTML) is shown over the empty input. */
|
|
124
|
+
advancedFilterPlaceholder?: React.ReactNode;
|
|
125
|
+
//
|
|
126
|
+
|
|
127
|
+
loading?: boolean;
|
|
128
|
+
theme?: 'light' | 'dark' | (string & {});
|
|
129
|
+
/** @deprecated Use theme="dark" or theme="light" instead. */
|
|
130
|
+
dark?: boolean;
|
|
131
|
+
delayedSize?: boolean;
|
|
132
|
+
allowChildRows?: boolean;
|
|
133
|
+
looseCacheCheck?: boolean;
|
|
134
|
+
className?: string;
|
|
135
|
+
/** rendered after the grid, inside its container */
|
|
136
|
+
children?: React.ReactNode;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export type DataGridProps = ModifyFields<
|
|
140
|
+
AzGridProps,
|
|
141
|
+
{
|
|
142
|
+
columns: ColumnDefinition[];
|
|
143
|
+
dataSource: any;
|
|
144
|
+
}
|
|
145
|
+
>;
|
|
146
|
+
export type GridType = TypeComputedProps;
|
|
147
|
+
export type DataGridWrapperProps = ModifyFields<
|
|
148
|
+
DataGridProps,
|
|
149
|
+
{
|
|
150
|
+
gridRef: React.MutableRefObject<TypeComputedProps>;
|
|
151
|
+
/** internal: inovua's live computed props ref (gridRef holds a snapshot) */
|
|
152
|
+
liveGridRef: React.MutableRefObject<React.MutableRefObject<TypeComputedProps> | null>;
|
|
153
|
+
static_gridOptions: AzGridOptions;
|
|
154
|
+
dynamic_gridOptions: AzGridOptions;
|
|
155
|
+
children?: React.ReactNode;
|
|
156
|
+
}
|
|
157
|
+
>;
|
package/src/views/DataGrid.tsx
CHANGED
|
@@ -4,7 +4,6 @@ import '../themes/grid.css';
|
|
|
4
4
|
import { get_default_key } from '../func/func_grid';
|
|
5
5
|
import { ContextMenu } from '@azrico/controls/context-menu';
|
|
6
6
|
import React from 'react';
|
|
7
|
-
import { createTheme, ThemeProvider, useTheme } from '@mui/material/styles';
|
|
8
7
|
|
|
9
8
|
import ReactDataGrid from '@inovua/reactdatagrid-enterprise';
|
|
10
9
|
import clsx from 'clsx';
|
|
@@ -16,6 +15,8 @@ import { useColumnData } from '../hooks/useColumnData';
|
|
|
16
15
|
import { useDataSource } from '../hooks/useDatasource';
|
|
17
16
|
import { useGridSearch } from '../hooks/useGridSearch';
|
|
18
17
|
import { apply_column_a11y } from '../func/func_a11y';
|
|
18
|
+
import { id as rowIndexColumnId } from '@inovua/reactdatagrid-community/normalizeColumns/defaultRowIndexColumnId';
|
|
19
|
+
import { id as checkboxColumnId } from '@inovua/reactdatagrid-community/normalizeColumns/defaultCheckColumnId';
|
|
19
20
|
/* -------------------------------------------------------------------------- */
|
|
20
21
|
|
|
21
22
|
/* -------------------------------------------------------------------------- */
|
|
@@ -152,15 +153,6 @@ export function AzGrid(props: AzGridProps) {
|
|
|
152
153
|
* @returns
|
|
153
154
|
*/
|
|
154
155
|
function DataGridEventsWrapper(props: DataGridWrapperProps) {
|
|
155
|
-
const scopeRef = React.useRef<HTMLDivElement>(null);
|
|
156
|
-
const hostTheme = useTheme();
|
|
157
|
-
// Keep the existing context menu and its portal in this grid's CSS scope.
|
|
158
|
-
const menuTheme = React.useMemo(
|
|
159
|
-
() => createTheme(hostTheme, {
|
|
160
|
-
components: { MuiPopper: { defaultProps: { container: () => scopeRef.current } } },
|
|
161
|
-
}),
|
|
162
|
-
[hostTheme]
|
|
163
|
-
);
|
|
164
156
|
const themeClass = `azgrid-theme-${props.theme ?? (props.dark ? 'dark' : 'light')}`;
|
|
165
157
|
/* -------------------------------------------------------------------------- */
|
|
166
158
|
const {
|
|
@@ -204,13 +196,13 @@ function DataGridEventsWrapper(props: DataGridWrapperProps) {
|
|
|
204
196
|
headerProps: { role: 'row', 'aria-rowindex': 1, ...opts.headerProps },
|
|
205
197
|
rowIndexColumn: apply_column_a11y(
|
|
206
198
|
typeof opts.rowIndexColumn === 'object' ? opts.rowIndexColumn : {},
|
|
207
|
-
{ role: 'rowheader', gridEditable }
|
|
199
|
+
{ role: 'rowheader', gridEditable, id: rowIndexColumnId }
|
|
208
200
|
),
|
|
209
201
|
};
|
|
210
202
|
if (opts.checkboxColumn)
|
|
211
203
|
a11yProps.checkboxColumn = apply_column_a11y(
|
|
212
204
|
typeof opts.checkboxColumn === 'object' ? opts.checkboxColumn : {},
|
|
213
|
-
{ gridEditable, markReadonly: false }
|
|
205
|
+
{ gridEditable, markReadonly: false, id: checkboxColumnId }
|
|
214
206
|
);
|
|
215
207
|
|
|
216
208
|
return {
|
|
@@ -229,19 +221,19 @@ function DataGridEventsWrapper(props: DataGridWrapperProps) {
|
|
|
229
221
|
]);
|
|
230
222
|
|
|
231
223
|
/* -------------------------------------------------------------------------- */
|
|
232
|
-
//
|
|
224
|
+
// The menu is portaled to <body>, so it carries the theme class itself to get the theme tokens.
|
|
233
225
|
return (
|
|
234
|
-
<div
|
|
235
|
-
|
|
226
|
+
<div className={clsx('azgrid-scope azgrid-flexed azgrid-flexlayout', themeClass)}>
|
|
227
|
+
{props.contextMenuItems && (
|
|
236
228
|
<ContextMenu
|
|
237
|
-
classname=
|
|
229
|
+
classname={clsx('azgrid-context-menu', themeClass, props.contextMenuClassName)}
|
|
238
230
|
menuAnchorEl={menuAnchorEl}
|
|
239
231
|
menuRow={menuRow}
|
|
240
232
|
close={update_menuRow}
|
|
241
233
|
dontAutoClose={false}
|
|
242
234
|
menu_items={props.contextMenuItems as any}
|
|
243
235
|
/>
|
|
244
|
-
|
|
236
|
+
)}
|
|
245
237
|
{props.details_dataSource ? (
|
|
246
238
|
<DataGridDetailsWrapper {...props} static_gridOptions={static_gridOptions} />
|
|
247
239
|
) : (
|