UNPKG

2.72 kBPlain TextView Raw
1import {AbstractColDef} from "../entities/colDef";
2import {GridOptionsWrapper} from "../gridOptionsWrapper";
3import {Utils as _} from '../utils';
4import {ColumnGroup} from "../entities/columnGroup";
5import {Column} from "../entities/column";
6import {OriginalColumnGroup} from "../entities/originalColumnGroup";
7
8export 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