Skip to content

Commit cebd167

Browse files
committed
refactor(*): make type enumerators more consistent across components
1 parent b4806b5 commit cebd167

File tree

16 files changed

+102
-111
lines changed

16 files changed

+102
-111
lines changed

projects/igniteui-angular/src/lib/avatar/avatar.component.spec.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from '@angular/core/testing';
66
import { By } from '@angular/platform-browser';
77
import { IgxIconModule } from '../icon/index';
8-
import { IgxAvatarComponent, AvatarType, Size } from './avatar.component';
8+
import { IgxAvatarComponent, IgxAvatarType, IgxAvatarSize } from './avatar.component';
99

1010
import { configureTestSuite } from '../test-utils/configure-suite';
1111

@@ -76,22 +76,22 @@ describe('Avatar', () => {
7676
const instance = fixture.componentInstance.avatar;
7777
const hostEl = fixture.debugElement.query(By.css(baseClass)).nativeElement;
7878

79-
expect(instance.size).toEqual(Size.SMALL);
79+
expect(instance.size).toEqual(IgxAvatarSize.SMALL);
8080
expect(hostEl.classList).toContain(classes.small);
8181

82-
instance.size = Size.MEDIUM;
82+
instance.size = IgxAvatarSize.MEDIUM;
8383
fixture.detectChanges();
84-
expect(instance.size).toEqual(Size.MEDIUM);
84+
expect(instance.size).toEqual(IgxAvatarSize.MEDIUM);
8585
expect(hostEl.classList).not.toContain(classes.medium);
8686

87-
instance.size = Size.LARGE;
87+
instance.size = IgxAvatarSize.LARGE;
8888
fixture.detectChanges();
89-
expect(instance.size).toEqual(Size.LARGE);
89+
expect(instance.size).toEqual(IgxAvatarSize.LARGE);
9090
expect(hostEl.classList).not.toContain(classes.large);
9191

9292
instance.size = 'nonsense';
9393
fixture.detectChanges();
94-
expect(instance.size).toEqual(Size.SMALL);
94+
expect(instance.size).toEqual(IgxAvatarSize.SMALL);
9595
expect(hostEl.classList).toContain(classes.small);
9696
});
9797

@@ -102,7 +102,6 @@ describe('Avatar', () => {
102102
const instance = fixture.componentInstance.avatar;
103103
const hostEl = fixture.debugElement.query(By.css(baseClass)).nativeElement;
104104

105-
expect(instance.type).toEqual(AvatarType.DEFAULT);
106105
expect(instance.initials).toBeUndefined();
107106
expect(instance.src).toBeUndefined();
108107
expect(instance.icon).toBeUndefined();
@@ -119,7 +118,7 @@ describe('Avatar', () => {
119118
const instance = fixture.componentInstance.avatar;
120119
const hostEl = fixture.debugElement.query(By.css(baseClass)).nativeElement;
121120

122-
expect(instance.type).toEqual(AvatarType.INITIALS);
121+
expect(instance.type).toEqual(IgxAvatarType.INITIALS);
123122
expect(instance.initials).toEqual('ZK');
124123
expect(hostEl.querySelector('span').textContent).toEqual('ZK');
125124
expect(hostEl.classList).toContain(classes.initials);
@@ -131,7 +130,7 @@ describe('Avatar', () => {
131130
const instance = fixture.componentInstance.avatar;
132131
const hostEl = fixture.debugElement.query(By.css(baseClass)).nativeElement;
133132

134-
expect(instance.type).toEqual(AvatarType.ICON);
133+
expect(instance.type).toEqual(IgxAvatarType.ICON);
135134
expect(instance.icon).toBeTruthy();
136135
expect(hostEl.classList).toContain(classes.icon);
137136
});
@@ -142,7 +141,7 @@ describe('Avatar', () => {
142141
const instance = fixture.componentInstance.avatar;
143142
const hostEl = fixture.debugElement.query(By.css(baseClass)).nativeElement;
144143

145-
expect(instance.type).toEqual(AvatarType.IMAGE);
144+
expect(instance.type).toEqual(IgxAvatarType.IMAGE);
146145
expect(instance.image).toBeTruthy();
147146
expect(instance.image.nativeElement.style.backgroundImage).toBeDefined();
148147

projects/igniteui-angular/src/lib/avatar/avatar.component.ts

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ import { IgxIconModule } from '../icon/index';
1414

1515
let NEXT_ID = 0;
1616

17-
export enum Size {
17+
export enum IgxAvatarSize {
1818
SMALL = 'small',
1919
MEDIUM = 'medium',
2020
LARGE = 'large'
2121
}
2222

23-
export enum AvatarType {
24-
DEFAULT = 'default',
23+
export enum IgxAvatarType {
2524
INITIALS = 'initials',
2625
IMAGE = 'image',
2726
ICON = 'icon'
@@ -133,7 +132,7 @@ export class IgxAvatarComponent implements OnInit, AfterViewInit {
133132
/**
134133
* @hidden
135134
*/
136-
private _size: string | Size = 'small';
135+
private _size: string | IgxAvatarSize = IgxAvatarSize.SMALL;
137136

138137
/**
139138
* Sets the `id` of the avatar. If not set, the first avatar component will have `id` = `"igx-avatar-0"`.
@@ -237,7 +236,7 @@ export class IgxAvatarComponent implements OnInit, AfterViewInit {
237236
* @memberof IgxAvatarComponent
238237
*/
239238
@Input()
240-
public get size(): string | Size {
239+
public get size(): string | IgxAvatarSize {
241240
return this._size;
242241
}
243242

@@ -251,7 +250,7 @@ export class IgxAvatarComponent implements OnInit, AfterViewInit {
251250
*
252251
* @memberof IgxAvatarComponent
253252
*/
254-
public set size(value: string | Size) {
253+
public set size(value: string | IgxAvatarSize) {
255254
switch (value) {
256255
case 'small':
257256
case 'medium':
@@ -272,20 +271,18 @@ export class IgxAvatarComponent implements OnInit, AfterViewInit {
272271
*
273272
* @memberof IgxAvatarComponent
274273
*/
275-
get type(): AvatarType {
274+
get type(): IgxAvatarType {
276275
if (this.src) {
277-
return AvatarType.IMAGE;
276+
return IgxAvatarType.IMAGE;
278277
}
279278

280279
if (this.icon) {
281-
return AvatarType.ICON;
280+
return IgxAvatarType.ICON;
282281
}
283282

284283
if (this.initials) {
285-
return AvatarType.INITIALS;
284+
return IgxAvatarType.INITIALS;
286285
}
287-
288-
return AvatarType.DEFAULT;
289286
}
290287

291288
/**
@@ -299,11 +296,11 @@ export class IgxAvatarComponent implements OnInit, AfterViewInit {
299296
*/
300297
get template(): TemplateRef<any> {
301298
switch (this.type) {
302-
case AvatarType.IMAGE:
299+
case IgxAvatarType.IMAGE:
303300
return this.imageTemplate;
304-
case AvatarType.INITIALS:
301+
case IgxAvatarType.INITIALS:
305302
return this.initialsTemplate;
306-
case AvatarType.ICON:
303+
case IgxAvatarType.ICON:
307304
return this.iconTemplate;
308305
default:
309306
return this.defaultTemplate;
@@ -332,11 +329,11 @@ export class IgxAvatarComponent implements OnInit, AfterViewInit {
332329
*/
333330
private getRole(): string {
334331
switch (this.type) {
335-
case AvatarType.IMAGE:
332+
case IgxAvatarType.IMAGE:
336333
return 'image avatar';
337-
case AvatarType.ICON:
334+
case IgxAvatarType.ICON:
338335
return 'icon avatar';
339-
case AvatarType.INITIALS:
336+
case IgxAvatarType.INITIALS:
340337
return 'initials avatar';
341338
default:
342339
return 'custom avatar';

projects/igniteui-angular/src/lib/badge/badge.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from '@angular/core/testing';
66
import { By } from '@angular/platform-browser';
77
import { IgxIconModule } from '../icon/index';
8-
import { IgxBadgeComponent, IgxBadgeModule } from './badge.component';
8+
import { IgxBadgeComponent, IgxBadgeType } from './badge.component';
99

1010
import { configureTestSuite } from '../test-utils/configure-suite';
1111

@@ -74,7 +74,7 @@ describe('Badge', () => {
7474
const badge = fixture.componentInstance.badge;
7575

7676
expect(badge.icon === 'person').toBeTruthy();
77-
expect(badge.type === 'info').toBeTruthy();
77+
expect(badge.type === IgxBadgeType.INFO).toBeTruthy();
7878
expect(badge.value === '').toBeTruthy();
7979

8080
expect(fixture.debugElement.query(By.css('.igx-badge__circle'))).toBeTruthy();

projects/igniteui-angular/src/lib/badge/badge.component.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { IgxIconModule } from '../icon/index';
44

55
let NEXT_ID = 0;
66

7-
export enum Type {
8-
DEFAULT = 'default',
7+
export enum IgxBadgeType {
98
INFO = 'info',
109
SUCCESS = 'success',
1110
WARNING = 'warning',
@@ -60,7 +59,7 @@ export class IgxBadgeComponent {
6059
* ```
6160
*/
6261
@Input()
63-
public type: string | Type = 'default';
62+
public type: string | IgxBadgeType = '';
6463

6564
/**
6665
* An @Input property that sets the value to be displayed inside the badge.
@@ -126,7 +125,7 @@ export class IgxBadgeComponent {
126125
* Defines a human-readable, accessor, author-localized description for the `type` and the `icon` or `value` of the element.
127126
*/
128127
get roleDescription() {
129-
let message;
128+
let message: string;
130129

131130
// tslint:disable-next-line:prefer-conditional-expression
132131
if (this.icon) {
@@ -148,32 +147,31 @@ export class IgxBadgeComponent {
148147
public setClasses() {
149148
let classes = {};
150149

151-
switch (Type[this.type.toUpperCase()]) {
152-
case Type.DEFAULT:
153-
classes = {
154-
[`${this.cssClass}__circle--default`]: true
155-
};
156-
break;
157-
case Type.INFO:
150+
switch (IgxBadgeType[this.type.toUpperCase()]) {
151+
case IgxBadgeType.INFO:
158152
classes = {
159153
[`${this.cssClass}__circle--info`]: true
160154
};
161155
break;
162-
case Type.SUCCESS:
156+
case IgxBadgeType.SUCCESS:
163157
classes = {
164158
[`${this.cssClass}__circle--success`]: true
165159
};
166160
break;
167-
case Type.WARNING:
161+
case IgxBadgeType.WARNING:
168162
classes = {
169163
[`${this.cssClass}__circle--warning`]: true
170164
};
171165
break;
172-
case Type.ERROR:
166+
case IgxBadgeType.ERROR:
173167
classes = {
174168
[`${this.cssClass}__circle--error`]: true
175169
};
176170
break;
171+
default:
172+
classes = {
173+
[`${this.cssClass}__circle--default`]: true
174+
};
177175
}
178176

179177
return classes;
@@ -189,5 +187,4 @@ export class IgxBadgeComponent {
189187
exports: [IgxBadgeComponent],
190188
imports: [CommonModule, IgxIconModule]
191189
})
192-
export class IgxBadgeModule {
193-
}
190+
export class IgxBadgeModule { }

projects/igniteui-angular/src/lib/card/card.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export class IgxCardFooterDirective {
193193
*/
194194

195195
export enum IgxCardType {
196-
DEFAULT = 'default',
196+
ELEVATED = 'elevated',
197197
OUTLINED = 'outlined'
198198
}
199199

@@ -238,7 +238,7 @@ export class IgxCardComponent {
238238
*/
239239
@HostBinding('class.igx-card')
240240
@Input()
241-
public type: IgxCardType | string = IgxCardType.DEFAULT;
241+
public type: IgxCardType | string = IgxCardType.ELEVATED;
242242

243243
/**
244244
* A getter which will return true if the card type is `outlined`.
@@ -262,7 +262,7 @@ export class IgxCardComponent {
262262
}
263263

264264
export enum IgxCardActionsLayout {
265-
DEFAULT = 'default',
265+
LEFT = 'left',
266266
JUSTIFY = 'justify',
267267
}
268268

@@ -292,7 +292,7 @@ export class IgxCardActionsComponent implements OnInit, OnChanges {
292292
*/
293293
@HostBinding('class.igx-card-actions')
294294
@Input()
295-
public layout: IgxCardActionsLayout | string = 'default';
295+
public layout: IgxCardActionsLayout | string = IgxCardActionsLayout.LEFT;
296296

297297
/**
298298
* An @Input property that sets the vertical attribute of the actions.

projects/igniteui-angular/src/lib/card/card.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
IgxCardModule,
99
IgxCardComponent,
1010
IgxCardType,
11-
IgxCardActionsLayout,
1211
IgxCardThumbnailDirective,
1312
IgxCardHeaderTitleDirective,
1413
IgxCardHeaderSubtitleDirective,

projects/igniteui-angular/src/lib/directives/divider/divider.directive.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Directive, HostBinding, NgModule, Input } from '@angular/core';
22

33
export enum IgxDividerType {
4-
DEFAULT = 'default',
4+
SOLID = 'solid',
55
DASHED = 'dashed'
66
}
77

@@ -54,7 +54,7 @@ export class IgxDividerDirective {
5454
*/
5555
@HostBinding('class.igx-divider')
5656
@Input()
57-
public type: IgxDividerType | string = IgxDividerType.DEFAULT;
57+
public type: IgxDividerType | string = IgxDividerType.SOLID;
5858

5959
@HostBinding('class.igx-divider--dashed')
6060
get isDashed() {
@@ -79,8 +79,8 @@ export class IgxDividerDirective {
7979
* const isDefault = this.divider.isDefault;
8080
* ```
8181
*/
82-
get isDefault() {
83-
return this.type === IgxDividerType.DEFAULT;
82+
get isSolid() {
83+
return this.type === IgxDividerType.SOLID;
8484
}
8585

8686
/**

projects/igniteui-angular/src/lib/directives/divider/divider.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('Divider', () => {
3232

3333
it('should initialize default divider', () => {
3434
const divider = fixture.debugElement.query(By.css('igx-divider'));
35-
fixture.componentInstance.type = IgxDividerType.DEFAULT;
35+
fixture.componentInstance.type = IgxDividerType.SOLID;
3636
fixture.detectChanges();
3737

3838
expect(divider.nativeElement).toBeDefined();

projects/igniteui-angular/src/lib/progressbar/progressbar.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export enum IgxTextAlign {
2828
}
2929

3030
export enum IgxProgressType {
31-
DANGER = 'danger',
31+
ERROR = 'error',
3232
INFO = 'info',
3333
WARNING = 'warning',
3434
SUCCESS = 'success'
@@ -446,7 +446,7 @@ export class IgxLinearProgressBarComponent extends BaseProgress {
446446
*/
447447
@HostBinding('class.igx-linear-bar--danger')
448448
public get danger() {
449-
return this.type === IgxProgressType.DANGER;
449+
return this.type === IgxProgressType.ERROR;
450450
}
451451

452452
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export interface ISliderValueChangeEventArgs {
5353
value: number | IRangeSliderValue;
5454
}
5555

56-
export enum SliderType {
56+
export enum IgxSliderType {
5757
/**
5858
* Slider with single thumb.
5959
*/

0 commit comments

Comments
 (0)