Skip to content

Commit acf5233

Browse files
authored
refactor!: remove deprecated classNameGenerator API (#10502)
1 parent 63e2005 commit acf5233

File tree

7 files changed

+81
-222
lines changed

7 files changed

+81
-222
lines changed

packages/grid/src/vaadin-grid-mixin.d.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,10 @@ import type { GridRowDetailsRenderer, RowDetailsMixinClass } from './vaadin-grid
3131
import type { ScrollMixinClass } from './vaadin-grid-scroll-mixin.js';
3232
import type { SelectionMixinClass } from './vaadin-grid-selection-mixin.js';
3333
import type { SortMixinClass } from './vaadin-grid-sort-mixin.js';
34-
import type {
35-
GridCellClassNameGenerator,
36-
GridCellPartNameGenerator,
37-
StylingMixinClass,
38-
} from './vaadin-grid-styling-mixin.js';
34+
import type { GridCellPartNameGenerator, StylingMixinClass } from './vaadin-grid-styling-mixin.js';
3935

4036
export {
4137
GridBodyRenderer,
42-
GridCellClassNameGenerator,
4338
GridCellPartNameGenerator,
4439
GridDataProvider,
4540
GridDataProviderCallback,

packages/grid/src/vaadin-grid-mixin.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,6 @@ export const GridMixin = (superClass) =>
753753
this._resetKeyboardNavigation();
754754
this.__a11yUpdateHeaderRows();
755755
this.__a11yUpdateFooterRows();
756-
this.generateCellClassNames();
757756
this.generateCellPartNames();
758757
this.__updateHeaderAndFooter();
759758
}
@@ -788,7 +787,6 @@ export const GridMixin = (superClass) =>
788787

789788
if (loading) {
790789
// Run style generators for the loading row to have custom names cleared
791-
this._generateCellClassNames(row);
792790
this._generateCellPartNames(row);
793791
}
794792
}
@@ -819,7 +817,6 @@ export const GridMixin = (superClass) =>
819817

820818
this.__updateRowStateParts(row, model);
821819

822-
this._generateCellClassNames(row, model);
823820
this._generateCellPartNames(row, model);
824821
this._filterDragAndDrop(row, model);
825822
this.__updateDragSourceParts(row, model);

packages/grid/src/vaadin-grid-styling-mixin.d.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,11 @@ import type { GridColumn } from './vaadin-grid-column.js';
99

1010
export type GridCellPartNameGenerator<TItem> = (column: GridColumn<TItem>, model: GridItemModel<TItem>) => string;
1111

12-
/**
13-
* @deprecated Use `GridCellPartNameGenerator` type and `cellPartNameGenerator` API instead.
14-
*/
15-
export type GridCellClassNameGenerator<TItem> = GridCellPartNameGenerator<TItem>;
16-
1712
export declare function StylingMixin<TItem, T extends Constructor<HTMLElement>>(
1813
base: T,
1914
): Constructor<StylingMixinClass<TItem>> & T;
2015

2116
export declare class StylingMixinClass<TItem> {
22-
/**
23-
* A function that allows generating CSS class names for grid cells
24-
* based on their row and column. The return value should be the generated
25-
* class name as a string, or multiple class names separated by whitespace
26-
* characters.
27-
*
28-
* Receives two arguments:
29-
* - `column` The `<vaadin-grid-column>` element (`undefined` for details-cell).
30-
* - `model` The object with the properties related with
31-
* the rendered item, contains:
32-
* - `model.index` The index of the item.
33-
* - `model.item` The item.
34-
* - `model.expanded` Sublevel toggle state.
35-
* - `model.level` Level of the tree represented with a horizontal offset of the toggle button.
36-
* - `model.selected` Selected state.
37-
*
38-
* @deprecated Use `cellPartNameGenerator` instead.
39-
*/
40-
cellClassNameGenerator: GridCellClassNameGenerator<TItem> | null | undefined;
41-
4217
/**
4318
* A function that allows generating CSS `part` names for grid cells in Shadow DOM based
4419
* on their row and column, for styling from outside using the `::part()` selector.
@@ -58,16 +33,6 @@ export declare class StylingMixinClass<TItem> {
5833
*/
5934
cellPartNameGenerator: GridCellPartNameGenerator<TItem> | null | undefined;
6035

61-
/**
62-
* Runs the `cellClassNameGenerator` for the visible cells.
63-
* If the generator depends on varying conditions, you need to
64-
* call this function manually in order to update the styles when
65-
* the conditions change.
66-
*
67-
* @deprecated Use `cellPartNameGenerator` and `generateCellPartNames()` instead.
68-
*/
69-
generateCellClassNames(): void;
70-
7136
/**
7237
* Runs the `cellPastNameGenerator` for the visible cells.
7338
* If the generator depends on varying conditions, you need to

packages/grid/src/vaadin-grid-styling-mixin.js

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,6 @@ export const StylingMixin = (superClass) =>
1212
class StylingMixin extends superClass {
1313
static get properties() {
1414
return {
15-
/**
16-
* A function that allows generating CSS class names for grid cells
17-
* based on their row and column. The return value should be the generated
18-
* class name as a string, or multiple class names separated by whitespace
19-
* characters.
20-
*
21-
* Receives two arguments:
22-
* - `column` The `<vaadin-grid-column>` element (`undefined` for details-cell).
23-
* - `model` The object with the properties related with
24-
* the rendered item, contains:
25-
* - `model.index` The index of the item.
26-
* - `model.item` The item.
27-
* - `model.expanded` Sublevel toggle state.
28-
* - `model.level` Level of the tree represented with a horizontal offset of the toggle button.
29-
* - `model.selected` Selected state.
30-
*
31-
* @type {GridCellClassNameGenerator | null | undefined}
32-
* @deprecated Use `cellPartNameGenerator` instead.
33-
*/
34-
cellClassNameGenerator: {
35-
type: Function,
36-
sync: true,
37-
},
38-
3915
/**
4016
* A function that allows generating CSS `part` names for grid cells in Shadow DOM based
4117
* on their row and column, for styling from outside using the `::part()` selector.
@@ -63,38 +39,14 @@ export const StylingMixin = (superClass) =>
6339
}
6440

6541
static get observers() {
66-
return [
67-
'__cellClassNameGeneratorChanged(cellClassNameGenerator)',
68-
'__cellPartNameGeneratorChanged(cellPartNameGenerator)',
69-
];
70-
}
71-
72-
/** @private */
73-
__cellClassNameGeneratorChanged() {
74-
this.generateCellClassNames();
42+
return ['__cellPartNameGeneratorChanged(cellPartNameGenerator)'];
7543
}
7644

7745
/** @private */
7846
__cellPartNameGeneratorChanged() {
7947
this.generateCellPartNames();
8048
}
8149

82-
/**
83-
* Runs the `cellClassNameGenerator` for the visible cells.
84-
* If the generator depends on varying conditions, you need to
85-
* call this function manually in order to update the styles when
86-
* the conditions change.
87-
*
88-
* @deprecated Use `cellPartNameGenerator` and `generateCellPartNames()` instead.
89-
*/
90-
generateCellClassNames() {
91-
iterateChildren(this.$.items, (row) => {
92-
if (!row.hidden) {
93-
this._generateCellClassNames(row, this.__getRowModel(row));
94-
}
95-
});
96-
}
97-
9850
/**
9951
* Runs the `cellPartNameGenerator` for the visible cells.
10052
* If the generator depends on varying conditions, you need to
@@ -109,22 +61,6 @@ export const StylingMixin = (superClass) =>
10961
});
11062
}
11163

112-
/** @private */
113-
_generateCellClassNames(row, model) {
114-
iterateRowCells(row, (cell) => {
115-
if (cell.__generatedClasses) {
116-
cell.__generatedClasses.forEach((className) => cell.classList.remove(className));
117-
}
118-
if (this.cellClassNameGenerator && !row.hasAttribute('loading')) {
119-
const result = this.cellClassNameGenerator(cell._column, model);
120-
cell.__generatedClasses = result && result.split(' ').filter((className) => className.length > 0);
121-
if (cell.__generatedClasses) {
122-
cell.__generatedClasses.forEach((className) => cell.classList.add(className));
123-
}
124-
}
125-
});
126-
}
127-
12864
/** @private */
12965
_generateCellPartNames(row, model) {
13066
iterateRowCells(row, (cell) => {

packages/grid/test/column-rendering.test.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -366,18 +366,6 @@ import { flushGrid, getCellContent, getHeaderCellContent } from './helpers.js';
366366
expectCellsVisualOrderToMatchColumnOrder();
367367
});
368368

369-
it('should have cell class names on the revealed cells', async () => {
370-
// Add a class name generator
371-
grid.cellClassNameGenerator = () => 'foo';
372-
await nextFrame();
373-
expect(getBodyCell(0, getLastVisibleColumnIndex()).classList.contains('foo')).to.be.true;
374-
375-
// Scroll back to the beginning
376-
await scrollHorizontally(-grid.$.table.scrollWidth);
377-
// Expect the cell that was previously not visible to have the class name
378-
expect(getBodyCell(0, 0).classList.contains('foo')).to.be.true;
379-
});
380-
381369
it('should have cell part names on the revealed cells', async () => {
382370
// Add a part name generator
383371
grid.cellPartNameGenerator = () => 'foo';

0 commit comments

Comments
 (0)