Skip to content

Commit 18e62a5

Browse files
committed
refactor(*): Transform abs base classes to directives
1 parent 8eb90fb commit 18e62a5

File tree

11 files changed

+80
-34
lines changed

11 files changed

+80
-34
lines changed

projects/igniteui-angular/src/lib/core/displayDensity.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { InjectionToken, Input, Output, EventEmitter, DoCheck, OnInit } from '@angular/core';
1+
import { InjectionToken, Input, Output, EventEmitter, DoCheck, OnInit, Directive, NgModule, Optional, Inject } from '@angular/core';
22
import { IBaseEventArgs } from './utils';
33

44

@@ -31,6 +31,10 @@ export const DisplayDensityToken = new InjectionToken<IDisplayDensityOptions>('D
3131
/**
3232
* Base class containing all logic required for implementing DisplayDensity.
3333
*/
34+
@Directive({
35+
selector: '[igxDisplayDensityBase]'
36+
})
37+
// tslint:disable-next-line: directive-class-suffix
3438
export class DisplayDensityBase implements DoCheck, OnInit {
3539
protected _displayDensity: DisplayDensity;
3640

@@ -76,7 +80,7 @@ export class DisplayDensityBase implements DoCheck, OnInit {
7680
protected oldDisplayDensityOptions: IDisplayDensityOptions = { displayDensity: DisplayDensity.comfortable };
7781

7882

79-
constructor(protected displayDensityOptions: IDisplayDensityOptions) {
83+
constructor(@Optional() @Inject(DisplayDensityToken) protected displayDensityOptions: IDisplayDensityOptions) {
8084
Object.assign(this.oldDisplayDensityOptions, displayDensityOptions);
8185
}
8286

@@ -115,3 +119,13 @@ export class DisplayDensityBase implements DoCheck, OnInit {
115119
}
116120
}
117121
}
122+
123+
@NgModule({
124+
declarations: [
125+
DisplayDensityBase
126+
],
127+
exports: [
128+
DisplayDensityBase
129+
]
130+
})
131+
export class IgxDisplayDensityModule {}

projects/igniteui-angular/src/lib/drop-down/drop-down.base.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
Input, HostBinding, ElementRef, QueryList, Output, EventEmitter, ChangeDetectorRef, Optional, Inject
2+
Input, HostBinding, ElementRef, QueryList, Output, EventEmitter, ChangeDetectorRef, Optional, Inject, Directive
33
} from '@angular/core';
44

55
import { Navigate, ISelectionEventArgs } from './drop-down.common';
@@ -17,7 +17,10 @@ let NEXT_ID = 0;
1717
* Properties and methods for navigating (highlighting/focusing) items from the collection
1818
* Properties and methods for selecting items from the collection
1919
*/
20-
export abstract class IgxDropDownBase extends DisplayDensityBase implements IDropDownList {
20+
@Directive({
21+
selector: '[igxDropDownBase]'
22+
})
23+
export class IgxDropDownBase extends DisplayDensityBase implements IDropDownList {
2124
protected _width;
2225
protected _height;
2326
protected _focusedItem: any = null;
@@ -167,7 +170,7 @@ export abstract class IgxDropDownBase extends DisplayDensityBase implements IDro
167170
/**
168171
* Gets if the dropdown is collapsed
169172
*/
170-
public abstract collapsed: boolean;
173+
public collapsed: boolean;
171174

172175
constructor(
173176
protected elementRef: ElementRef,

projects/igniteui-angular/src/lib/drop-down/index.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { CommonModule } from '@angular/common';
66
import { IgxToggleModule } from '../directives/toggle/toggle.directive';
77
import { IgxSelectionAPIService } from '../core/selection';
88
import { IgxDropDownGroupComponent } from './drop-down-group.component';
9+
import { IgxDropDownBase } from './drop-down.base';
910

1011
export * from './drop-down.component';
1112
export * from './drop-down-item.component';
@@ -19,11 +20,22 @@ export * from './drop-down-group.component';
1920
* @hidden
2021
*/
2122
@NgModule({
22-
declarations: [IgxDropDownComponent, IgxDropDownItemComponent, IgxDropDownGroupComponent,
23-
IgxDropDownItemNavigationDirective],
24-
exports: [IgxDropDownComponent, IgxDropDownItemComponent, IgxDropDownGroupComponent,
25-
IgxDropDownItemNavigationDirective],
26-
imports: [CommonModule, IgxToggleModule],
27-
providers: [IgxSelectionAPIService]
23+
declarations: [
24+
IgxDropDownBase,
25+
IgxDropDownComponent,
26+
IgxDropDownItemComponent,
27+
IgxDropDownGroupComponent,
28+
IgxDropDownItemNavigationDirective
29+
],
30+
exports: [
31+
IgxDropDownComponent,
32+
IgxDropDownItemComponent,
33+
IgxDropDownGroupComponent,
34+
IgxDropDownItemNavigationDirective
35+
],
36+
imports: [
37+
CommonModule,
38+
IgxToggleModule
39+
]
2840
})
2941
export class IgxDropDownModule { }

projects/igniteui-angular/src/lib/grids/common/pipes.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Pipe, PipeTransform } from '@angular/core';
1+
import { Pipe, PipeTransform, Inject, LOCALE_ID } from '@angular/core';
22
import { GridBaseAPIService } from '../api.service';
33
import { IgxGridBaseComponent } from '../grid-base.component';
44
import { DataUtil } from '../../data-operations/data-util';
@@ -147,10 +147,10 @@ export class IgxDatePipeComponent extends DatePipe implements PipeTransform {
147147

148148
private readonly DEFAULT_DATE_FORMAT = 'mediumDate';
149149

150-
// constructor(@Inject(LOCALE_ID) locale: string) {
151-
// // D.P. constructor duplication due to es6 compilation, might be obsolete in the future
152-
// super(locale);
153-
// }
150+
constructor(@Inject(LOCALE_ID) locale: string) {
151+
// D.P. constructor duplication due to es6 compilation, might be obsolete in the future
152+
super(locale);
153+
}
154154
transform(value: any, locale: string): string {
155155
if (value && value instanceof Date) {
156156
if (locale) {
@@ -172,10 +172,10 @@ export class IgxDatePipeComponent extends DatePipe implements PipeTransform {
172172
name: 'igxdecimal'
173173
})
174174
export class IgxDecimalPipeComponent extends DecimalPipe implements PipeTransform {
175-
// constructor(@Inject(LOCALE_ID) locale: string) {
176-
// // D.P. constructor duplication due to es6 compilation, might be obsolete in the future
177-
// super(locale);
178-
// }
175+
constructor(@Inject(LOCALE_ID) locale: string) {
176+
// D.P. constructor duplication due to es6 compilation, might be obsolete in the future
177+
super(locale);
178+
}
179179
transform(value: any, locale: string): string {
180180
if (value && typeof value === 'number') {
181181
if (locale) {

projects/igniteui-angular/src/lib/grids/grid-base.component.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
InjectionToken,
2626
Optional,
2727
DoCheck,
28-
Injectable
28+
Directive
2929
} from '@angular/core';
3030
import ResizeObserver from 'resize-observer-polyfill';
3131
import { Subject, combineLatest, pipe } from 'rxjs';
@@ -121,8 +121,10 @@ export const IgxGridTransaction = new InjectionToken<string>('IgxGridTransaction
121121

122122

123123

124-
@Injectable()
125-
export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
124+
@Directive({
125+
selector: '[igxGridBaseComponent]'
126+
})
127+
export class IgxGridBaseComponent extends DisplayDensityBase implements
126128
OnInit, DoCheck, OnDestroy, AfterContentInit, AfterViewInit {
127129
private _scrollWidth: number;
128130
protected _init = true;
@@ -198,7 +200,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
198200
@Input()
199201
public autoGenerate = false;
200202

201-
public abstract id: string;
203+
public id: string;
202204

203205
/**
204206
* An @Input property that sets a custom template when the `IgxGridComponent` is empty.
@@ -2545,8 +2547,8 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
25452547
*/
25462548
public columnWidthSetByUser = false;
25472549

2548-
abstract data: any[];
2549-
abstract filteredData: any[];
2550+
data: any[];
2551+
filteredData: any[];
25502552

25512553
/**
25522554
* @hidden

projects/igniteui-angular/src/lib/grids/grid-common.module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { IgxGridFooterComponent } from './grid-footer/grid-footer.component';
44
import {
55
IgxGridBodyDirective,
66
} from './grid.common';
7-
import { IgxGridTransaction } from './grid-base.component';
7+
import { IgxGridTransaction, IgxGridBaseComponent } from './grid-base.component';
88
import { IgxBaseTransactionService } from '../services/transaction/base-transaction';
99
import {
1010
IgxRowEditTemplateDirective,
@@ -28,11 +28,14 @@ import { IgxColumnPinningModule } from './pinning/pinning.module';
2828
import { IgxGridColumnModule } from './columns/column.module';
2929
import { IgxGridHeadersModule } from './headers/headers.module';
3030
import { IgxGridFilteringModule } from './filtering/base/filtering.module';
31+
import { IgxRowComponent } from './row.component';
3132
/**
3233
* @hidden
3334
*/
3435
@NgModule({
3536
declarations: [
37+
IgxGridBaseComponent,
38+
IgxRowComponent,
3639
IgxGridCellComponent,
3740
IgxRowEditTemplateDirective,
3841
IgxRowEditActionsDirective,

projects/igniteui-angular/src/lib/grids/hierarchical-grid/hierarchical-grid-base.component.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
Optional,
1010
Input,
1111
ViewChild,
12-
TemplateRef
12+
TemplateRef,
13+
Directive
1314
} from '@angular/core';
1415
import { IgxGridBaseComponent, IgxGridTransaction } from '../grid-base.component';
1516
import { GridBaseAPIService } from '../api.service';
@@ -43,8 +44,11 @@ export interface IPathSegment {
4344
rowIslandKey: string;
4445
}
4546

46-
export abstract class IgxHierarchicalGridBaseComponent extends IgxGridBaseComponent {
47-
public abstract rootGrid;
47+
@Directive({
48+
selector: '[igxHGridBase]'
49+
})
50+
export class IgxHierarchicalGridBaseComponent extends IgxGridBaseComponent {
51+
public rootGrid;
4852

4953
@Input()
5054
public expandChildren: boolean;

projects/igniteui-angular/src/lib/grids/hierarchical-grid/hierarchical-grid.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import { IgxRowIslandComponent } from './row-island.component';
77
import { IgxChildGridRowComponent } from './child-grid-row.component';
88
import { IgxHierarchicalGridCellComponent } from './hierarchical-cell.component';
99
import { IgxGridComponent } from '../grid/grid.component';
10+
import { IgxHierarchicalGridBaseComponent } from './hierarchical-grid-base.component';
1011

1112
/**
1213
* @hidden
1314
*/
1415
@NgModule({
1516
declarations: [
17+
IgxHierarchicalGridBaseComponent,
1618
IgxHierarchicalGridComponent,
1719
IgxHierarchicalRowComponent,
1820
IgxRowIslandComponent,

projects/igniteui-angular/src/lib/grids/row.component.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
QueryList,
1010
ViewChild,
1111
ViewChildren,
12-
Injectable
12+
Directive
1313
} from '@angular/core';
1414
import { IgxCheckboxComponent } from '../checkbox/checkbox.component';
1515
import { IgxGridForOfDirective } from '../directives/for-of/for_of.directive';
@@ -22,8 +22,10 @@ import { IgxGridSelectionService, IgxGridCRUDService, IgxRow } from './selection
2222
import { DeprecateProperty } from '../core/deprecateDecorators';
2323
import { GridType } from './common/grid.interface';
2424

25-
@Injectable()
26-
export abstract class IgxRowComponent<T extends IgxGridBaseComponent & GridType> implements DoCheck {
25+
@Directive({
26+
selector: '[igxRowBaseComponent]'
27+
})
28+
export class IgxRowComponent<T extends IgxGridBaseComponent & GridType> implements DoCheck {
2729

2830
private _rowData: any;
2931
/**

projects/igniteui-angular/src/lib/list/list.common.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ export interface IListChild {
66
}
77

88
/** @hidden */
9-
export abstract class IgxListBase extends DisplayDensityBase {
9+
@Directive({
10+
selector: '[igxListBase]'
11+
})
12+
export class IgxListBase extends DisplayDensityBase {
1013
onItemClicked: EventEmitter<any>;
1114
allowLeftPanning: boolean;
1215
allowRightPanning: boolean;

0 commit comments

Comments
 (0)