1 | import {AbstractColDef} from "../entities/colDef";
|
2 | import {GridOptionsWrapper} from "../gridOptionsWrapper";
|
3 | import {Utils as _} from '../utils';
|
4 | import {ColumnGroup} from "../entities/columnGroup";
|
5 | import {Column} from "../entities/column";
|
6 | import {OriginalColumnGroup} from "../entities/originalColumnGroup";
|
7 |
|
8 | export class CssClassApplier {
|
9 |
|
10 | public static addHeaderClassesFromColDef(abstractColDef: AbstractColDef, eHeaderCell: HTMLElement, gridOptionsWrapper: GridOptionsWrapper, column: Column, columnGroup: ColumnGroup) {
|
11 | if (_.missing(abstractColDef)) { return; }
|
12 | this.addColumnClassesFromCollDef(abstractColDef.headerClass, abstractColDef, eHeaderCell, gridOptionsWrapper, column, columnGroup);
|
13 | }
|
14 |
|
15 | public static addToolPanelClassesFromColDef(abstractColDef: AbstractColDef, eHeaderCell: HTMLElement, gridOptionsWrapper: GridOptionsWrapper, column: Column, columnGroup: OriginalColumnGroup) {
|
16 | if (_.missing(abstractColDef)) { return; }
|
17 | this.addColumnClassesFromCollDef(abstractColDef.toolPanelClass, abstractColDef, eHeaderCell, gridOptionsWrapper, column, columnGroup);
|
18 | }
|
19 |
|
20 | public static addColumnClassesFromCollDef(
|
21 | classesOrFunc: string | string[] | ((params: any) => string | string[]),
|
22 | abstractColDef: AbstractColDef,
|
23 | eHeaderCell: HTMLElement,
|
24 | gridOptionsWrapper: GridOptionsWrapper,
|
25 | column: Column,
|
26 | columnGroup: ColumnGroup|OriginalColumnGroup) {
|
27 | if (_.missing(classesOrFunc)) { return; }
|
28 | let classToUse: string | string[];
|
29 | if (typeof classesOrFunc === 'function') {
|
30 | let params = {
|
31 | // bad naming, as colDef here can be a group or a column,
|
32 | // however most people won't appreciate the difference,
|
33 | // so keeping it as colDef to avoid confusion.
|
34 | colDef: abstractColDef,
|
35 | column: column,
|
36 | columnGroup: columnGroup,
|
37 | context: gridOptionsWrapper.getContext(),
|
38 | api: gridOptionsWrapper.getApi()
|
39 | };
|
40 | let headerClassFunc = <(params: any) => string | string[]> classesOrFunc;
|
41 | classToUse = headerClassFunc(params);
|
42 | } else {
|
43 | classToUse = <string | string[]> classesOrFunc;
|
44 | }
|
45 |
|
46 | if (typeof classToUse === 'string') {
|
47 | _.addCssClass(eHeaderCell, classToUse);
|
48 | } else if (Array.isArray(classToUse)) {
|
49 | classToUse.forEach((cssClassItem: any): void => {
|
50 | _.addCssClass(eHeaderCell, cssClassItem);
|
51 | });
|
52 | }
|
53 | }
|
54 | } |
\ | No newline at end of file |