Skip to content

Commit babc329

Browse files
authored
Merge pull request #4171 from terrestris/ag-grid-update-theming
Ag grid update theming
2 parents 7101c19 + caee745 commit babc329

File tree

4 files changed

+66
-117
lines changed

4 files changed

+66
-117
lines changed

README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,23 @@ For a full list of available components, their properties and examples see [here
2323

2424
The `react-geo` package includes TypeScript declarations as `*.d.ts` files. The build itself is included in ESM format (currently ES2022).
2525

26-
### Styling
27-
28-
`react-geo` supports dynamic theming [via CSS variables](https://4x.ant.design/docs/react/customize-theme-variable) and requires the following import inside your project.
29-
30-
```css
31-
@import '~antd/dist/antd.variable.min.css';
26+
### Ant-Design ConfigProvider
27+
28+
`react-geo` supports [dynamic theming](https://ant.design/docs/react/customize-theme) of the Toggle Button via the antd `ConfigProvider`.
29+
30+
```tsx
31+
<ConfigProvider
32+
theme={{
33+
cssVar: true,
34+
Component: {
35+
Button: {
36+
primaryActive: '#0958d9'
37+
}
38+
}
39+
}}
40+
>
41+
//...
42+
</ConfigProvider>
3243
```
3344

3445
## Workshop

package-lock.json

Lines changed: 26 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@
6565
"typecheck": "tsc --noEmit --project tsconfig.json"
6666
},
6767
"dependencies": {
68-
"@ag-grid-community/client-side-row-model": "^32.3.2",
69-
"@ag-grid-community/react": "^32.3.2",
70-
"@ag-grid-community/styles": "^32.3.2",
7168
"@dnd-kit/core": "^6.1.0",
7269
"@dnd-kit/modifiers": "^8.0.0",
7370
"@dnd-kit/sortable": "^9.0.0",
@@ -79,6 +76,7 @@
7976
"@terrestris/base-util": "^3.0.0",
8077
"@terrestris/react-util": "^10.0.1",
8178
"@types/lodash": "^4.17.4",
79+
"ag-grid-react": "^33.0.4",
8280
"jspdf": "^2.5.1",
8381
"lodash": "^4.17.21",
8482
"moment": "^2.30.1",

src/Grid/AgFeatureGrid/AgFeatureGrid.tsx

Lines changed: 22 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
/* eslint-disable simple-import-sort/imports */
2-
import '@ag-grid-community/styles/ag-grid.css';
3-
import '@ag-grid-community/styles/ag-theme-balham.css';
4-
/* eslint-enable simple-import-sort/imports */
5-
61
import MapUtil from '@terrestris/ol-util/dist/MapUtil/MapUtil';
72
import useMap from '@terrestris/react-util/dist/Hooks/useMap/useMap';
83
import useOlLayer from '@terrestris/react-util/dist/Hooks/useOlLayer/useOlLayer';
9-
10-
import { ClientSideRowModelModule } from '@ag-grid-community/client-side-row-model';
114
import {
5+
AllCommunityModule,
126
CellMouseOutEvent,
137
CellMouseOverEvent,
148
ColDef,
@@ -21,28 +15,25 @@ import {
2115
RowClickedEvent,
2216
RowNode,
2317
RowStyle,
24-
SelectionChangedEvent
25-
} from '@ag-grid-community/core';
18+
SelectionChangedEvent,
19+
Theme,
20+
themeBalham} from 'ag-grid-community';
2621
import {
2722
AgGridReact,
2823
AgGridReactProps
29-
} from '@ag-grid-community/react';
30-
24+
} from 'ag-grid-react';
3125
import _differenceWith from 'lodash/differenceWith';
32-
import _has from 'lodash/has';
3326
import _isFunction from 'lodash/isFunction';
3427
import _isNil from 'lodash/isNil';
3528
import _isNumber from 'lodash/isNumber';
3629
import _isString from 'lodash/isString';
37-
3830
import { getUid } from 'ol';
3931
import OlFeature from 'ol/Feature';
4032
import OlGeometry from 'ol/geom/Geometry';
4133
import OlLayerBase from 'ol/layer/Base';
4234
import OlLayerVector from 'ol/layer/Vector';
4335
import OlMapBrowserEvent from 'ol/MapBrowserEvent';
4436
import OlSourceVector from 'ol/source/Vector';
45-
4637
import React, { Key, ReactElement, useCallback, useEffect, useMemo, useState } from 'react';
4738

4839
import { CSS_PREFIX } from '../../constants';
@@ -65,11 +56,11 @@ interface OwnProps<T> {
6556
*/
6657
height?: number | string;
6758
/**
68-
* The theme to use for the grid. See
69-
* https://www.ag-grid.com/javascript-grid-styling/ for available options.
70-
* Note: CSS must be loaded to use the theme!
59+
* The theme to use for the grid. See https://www.ag-grid.com/angular-data-grid/theming/ for available options
60+
* and customization possibilities. Default is the balham theme.
61+
* NOTE: AG-Grid CSS should *not* be imported.
7162
*/
72-
theme?: string;
63+
theme?: Theme;
7364
/**
7465
* Custom column definitions to apply to the given column (mapping via key).
7566
*/
@@ -117,7 +108,7 @@ const defaultClassName = `${CSS_PREFIX}ag-feature-grid`;
117108
export type AgFeatureGridProps<T> = OwnProps<T> & RgCommonGridProps<T> & Omit<AgGridReactProps, 'theme'>;
118109

119110
ModuleRegistry.registerModules([
120-
ClientSideRowModelModule
111+
AllCommunityModule
121112
]);
122113

123114
/**
@@ -143,7 +134,7 @@ export function AgFeatureGrid<T>({
143134
rowStyleFn,
144135
selectStyle = defaultSelectStyle,
145136
selectable = false,
146-
theme = 'ag-theme-balham',
137+
theme = themeBalham,
147138
width,
148139
zoomToExtent = false,
149140
...agGridPassThroughProps
@@ -169,17 +160,6 @@ export function AgFeatureGrid<T>({
169160
style: featureStyle
170161
}), [features, layerName], true);
171162

172-
const checkBoxColumnDefinition: ColDef<WithKey<T>> = useMemo(() => ({
173-
checkboxSelection: true,
174-
headerCheckboxSelection: true,
175-
headerName: '',
176-
lockPosition: true,
177-
pinned: 'left',
178-
suppressHeaderMenuButton: true,
179-
suppressMovable: true,
180-
width: 40
181-
}), []);
182-
183163
/**
184164
* Returns the currently selected row keys.
185165
*
@@ -190,8 +170,7 @@ export function AgFeatureGrid<T>({
190170
return [];
191171
}
192172

193-
const sr = gridApi.getSelectedRows();
194-
return sr.map(row => row.key);
173+
return gridApi.getSelectedRows()?.map(row => row.key) ?? [];
195174
}, [gridApi]);
196175

197176
/**
@@ -326,11 +305,6 @@ export function AgFeatureGrid<T>({
326305
const feature = features[0];
327306
const props = feature.getProperties();
328307

329-
if (selectable) {
330-
// adds select checkbox column
331-
columns.push(checkBoxColumnDefinition);
332-
}
333-
334308
const colDefsFromFeature = Object.keys(props).map((key: string): ColDef<WithKey<T>> | undefined => {
335309
if (attributeBlacklist.includes(key)) {
336310
return;
@@ -363,7 +337,7 @@ export function AgFeatureGrid<T>({
363337
...columns,
364338
...(colDefsFromFeature.filter(c => !_isNil(c)) as ColDef<WithKey<T>>[])
365339
];
366-
}, [attributeBlacklist, features, selectable, checkBoxColumnDefinition]);
340+
}, [attributeBlacklist, features]);
367341

368342
/**
369343
* Returns the table row data from all the given features.
@@ -585,28 +559,12 @@ export function AgFeatureGrid<T>({
585559

586560
const colDefs = useMemo(() => {
587561
if (!_isNil(columnDefs)) {
588-
if (!selectable) {
589-
return columnDefs;
590-
}
591-
// check for checkbox column - if not present => add
592-
const checkboxSelectionPresent = columnDefs?.
593-
some((colDef: ColDef<WithKey<T>>) =>
594-
_has(colDef, 'checkboxSelection') && !_isNil(colDef.checkboxSelection)
595-
);
596-
if (checkboxSelectionPresent) {
597-
return columnDefs;
598-
}
599-
return [
600-
checkBoxColumnDefinition,
601-
...columnDefs
602-
];
562+
return columnDefs;
603563
}
604564
return getColumnDefsFromFeature();
605565
}, [
606-
checkBoxColumnDefinition,
607566
columnDefs,
608-
getColumnDefsFromFeature,
609-
selectable
567+
getColumnDefsFromFeature
610568
]);
611569

612570
const passedRowData = useMemo(() => !_isNil(rowData) ? rowData : getRowData(), [
@@ -615,8 +573,8 @@ export function AgFeatureGrid<T>({
615573
]);
616574

617575
const finalClassName = className
618-
? `${className} ${defaultClassName} ${theme}`
619-
: `${defaultClassName} ${theme}`;
576+
? `${className} ${defaultClassName}`
577+
: `${defaultClassName}`;
620578

621579
return (
622580
<div
@@ -632,8 +590,11 @@ export function AgFeatureGrid<T>({
632590
onRowClicked={onRowClickInner}
633591
onSelectionChanged={onSelectionChanged}
634592
rowData={passedRowData}
635-
rowSelection="multiple"
636-
suppressRowClickSelection
593+
rowSelection={selectable ? {
594+
mode: 'multiRow',
595+
enableClickSelection: false
596+
} : undefined}
597+
theme={theme}
637598
{...agGridPassThroughProps}
638599
/>
639600
</div>

0 commit comments

Comments
 (0)