Skip to content

Commit dbae8e0

Browse files
authored
Merge pull request #6503 from IgniteUI/types-refactoring
refactor(*): make type enumerators more consistent across components
2 parents e897902 + d2c2fee commit dbae8e0

26 files changed

+211
-132
lines changed

CHANGELOG.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ All notable changes for each version of this project will be documented in this
66

77
### General
88
- Added support for the Ivy renderer.
9-
- **Breaking Changes** The following classes have been renamed. Using `ng update` will apply automatically migrate your project to use the new names.
9+
- **Breaking Changes** The following classes and enumarators have been renamed. Using `ng update` will apply automatically migrate your project to use the new names.
1010
- `IgxDropDownBase` -> `IgxDropDownBaseDirective`
1111
- `IgxDropDownItemBase` -> `IgxDropDownItemBaseDirective`
1212
- `IgxGridBaseComponent` -> `IgxGridBaseDirective`
1313
- `IgxRowComponent` -> `IgxRowDirective`
1414
- `IgxHierarchicalGridBaseComponent` -> `IgxHierarchicalGridBaseDirective`
1515
- `IgxMonthPickerBase` -> `IgxMonthPickerBaseDirective`
16+
- `AvatarType` -> `IgxAvatarType`
17+
- `Size` -> `IgxAvatarSize`
18+
- `Type` -> `IgxBadgeType`
19+
- `SliderType` -> `IgxSliderType`
20+
- `TabsType` -> `IgxTabsType`
1621

1722
- **Breaking Changes** Due to a breaking change in Angular 9 with Ivy, Hammer providers are no longer included by default. You can find more information at: https://github.com/angular/angular/blob/master/CHANGELOG.md#breaking-changes-9 . Because of this change the following components require `HammerModule` to be imported in the root module of the application in order for user interactions to work as expected:
1823
- `IgxSlider`
@@ -41,6 +46,21 @@ All notable changes for each version of this project will be documented in this
4146
- `IgxCarousel`:
4247
- **Breaking Changes** -The carousel slides are no longer array, they are changed to QueryList.
4348
- **Behavioural change** - When slides are more than 5, a label is shown instead of the indicators. The count limit of visible indicators can be changed with the input `maximumIndicatorsCount`
49+
- `IgxAvatar`:
50+
- **Breaking Changes** - renamed the `default` enumeration member to `custom` in `IgxAvatarType`;
51+
- `IgxBadge`:
52+
- **Breaking Changes** - renamed the `default` enumeration member to `primary` in `IgxBadgeType`;
53+
- `IgxCard`:
54+
- **Breaking Changes** - renamed the `default` enumeration member to `elevated` in `IgxCardType`;
55+
- **Breaking Changes** - renamed the `default` enumeration member to `start` in `IgxCardActionsLayout`;
56+
- `IgxDivider`:
57+
- **Breaking Changes** - renamed the `default` enumeration member to `solid` in `IgxDividerType`;
58+
- **Breaking Changes** - renamed the `isDefault` getter to `isSolid`;
59+
- `IgxProgress`:
60+
- **Breaking Changes** - renamed the `danger` enumeration member to `error` in `IgxProgresType`;
61+
- **Breaking Changes** - renamed the `danger` getter to `error`;
62+
- `IgxTabs`:
63+
- **Breaking Changes** - The `tabsType` input property has been renamed to `type`. It should get renamed in your components via `ng update`;
4464
- `igxOverlay`:
4565
- **Behavioural Change** - `igxOverlay` - no longer persists element scrolling `out of the box`. In order to persist an element scroll position after attaching the element to an overlay, handle the exposed `onAppended` overlay event and manage/restore the scroll position.
4666

projects/igniteui-angular/migrations/update-9_0_0/changes/classes.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@
2828
{
2929
"name": "IgxBaseExporter",
3030
"replaceWith": "IgxBaseExporterDirective"
31+
},
32+
{
33+
"name": "AvatarType",
34+
"replaceWith": "IgxAvatarType"
35+
},
36+
{
37+
"name": "Size",
38+
"replaceWith": "IgxAvatarSize"
39+
},
40+
{
41+
"name": "Type",
42+
"replaceWith": "IgxBadgeType"
43+
},
44+
{
45+
"name": "SliderType",
46+
"replaceWith": "IgxSliderType"
47+
},
48+
{
49+
"name": "TabsType",
50+
"replaceWith": "IgxTabsType"
3151
}
3252
]
3353
}

projects/igniteui-angular/migrations/update-9_0_0/changes/inputs.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
"selector": "igx-slider",
99
"type": "component"
1010
}
11+
},
12+
{
13+
"name": "tabsType",
14+
"replaceWith": "type",
15+
"owner": {
16+
"selector": "igx-tabs",
17+
"type": "component"
18+
}
1119
}
1220
]
1321
}

projects/igniteui-angular/migrations/update-9_0_0/index.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,32 @@ describe('Update 9.0.0', () => {
4343
`);
4444
done();
4545
});
46+
47+
it('should update Enum names.', done => {
48+
appTree.create(
49+
'/testSrc/appPrefix/component/enum.component.ts',
50+
`import { AvatarType, Size, Type, SliderType } from 'igniteui-angular';
51+
`);
52+
53+
const tree = schematicRunner.runSchematic('migration-13', {}, appTree);
54+
expect(tree.readContent('/testSrc/appPrefix/component/enum.component.ts'))
55+
.toEqual(
56+
`import { IgxAvatarType, IgxAvatarSize, IgxBadgeType, IgxSliderType } from 'igniteui-angular';
57+
`);
58+
done();
59+
});
60+
61+
it('should update input prop from tabsType to type', done => {
62+
appTree.create(
63+
'/testSrc/appPrefix/component/tabs.component.html',
64+
'<igx-tabs tabsType="fixed"></igx-tabs>'
65+
);
66+
67+
const tree = schematicRunner.runSchematic('migration-13', {}, appTree);
68+
69+
expect(tree.readContent('/testSrc/appPrefix/component/tabs.component.html'))
70+
.toEqual('<igx-tabs type="fixed"></igx-tabs>');
71+
72+
done();
73+
});
4674
});

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

Lines changed: 10 additions & 13 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

@@ -14,7 +14,6 @@ describe('Avatar', () => {
1414
const baseClass = 'igx-avatar';
1515

1616
const classes = {
17-
default: `${baseClass}--default`,
1817
round: `${baseClass}--rounded`,
1918
small: `${baseClass}--small`,
2019
medium: `${baseClass}--medium`,
@@ -76,22 +75,22 @@ describe('Avatar', () => {
7675
const instance = fixture.componentInstance.avatar;
7776
const hostEl = fixture.debugElement.query(By.css(baseClass)).nativeElement;
7877

79-
expect(instance.size).toEqual(Size.SMALL);
78+
expect(instance.size).toEqual(IgxAvatarSize.SMALL);
8079
expect(hostEl.classList).toContain(classes.small);
8180

82-
instance.size = Size.MEDIUM;
81+
instance.size = IgxAvatarSize.MEDIUM;
8382
fixture.detectChanges();
84-
expect(instance.size).toEqual(Size.MEDIUM);
83+
expect(instance.size).toEqual(IgxAvatarSize.MEDIUM);
8584
expect(hostEl.classList).not.toContain(classes.medium);
8685

87-
instance.size = Size.LARGE;
86+
instance.size = IgxAvatarSize.LARGE;
8887
fixture.detectChanges();
89-
expect(instance.size).toEqual(Size.LARGE);
88+
expect(instance.size).toEqual(IgxAvatarSize.LARGE);
9089
expect(hostEl.classList).not.toContain(classes.large);
9190

9291
instance.size = 'nonsense';
9392
fixture.detectChanges();
94-
expect(instance.size).toEqual(Size.SMALL);
93+
expect(instance.size).toEqual(IgxAvatarSize.SMALL);
9594
expect(hostEl.classList).toContain(classes.small);
9695
});
9796

@@ -102,13 +101,11 @@ describe('Avatar', () => {
102101
const instance = fixture.componentInstance.avatar;
103102
const hostEl = fixture.debugElement.query(By.css(baseClass)).nativeElement;
104103

105-
expect(instance.type).toEqual(AvatarType.DEFAULT);
106104
expect(instance.initials).toBeUndefined();
107105
expect(instance.src).toBeUndefined();
108106
expect(instance.icon).toBeUndefined();
109107

110108
expect(hostEl.textContent).toEqual('TEST');
111-
expect(hostEl.classList).toContain(classes.default);
112109
});
113110

114111

@@ -119,7 +116,7 @@ describe('Avatar', () => {
119116
const instance = fixture.componentInstance.avatar;
120117
const hostEl = fixture.debugElement.query(By.css(baseClass)).nativeElement;
121118

122-
expect(instance.type).toEqual(AvatarType.INITIALS);
119+
expect(instance.type).toEqual(IgxAvatarType.INITIALS);
123120
expect(instance.initials).toEqual('ZK');
124121
expect(hostEl.querySelector('span').textContent).toEqual('ZK');
125122
expect(hostEl.classList).toContain(classes.initials);
@@ -131,7 +128,7 @@ describe('Avatar', () => {
131128
const instance = fixture.componentInstance.avatar;
132129
const hostEl = fixture.debugElement.query(By.css(baseClass)).nativeElement;
133130

134-
expect(instance.type).toEqual(AvatarType.ICON);
131+
expect(instance.type).toEqual(IgxAvatarType.ICON);
135132
expect(instance.icon).toBeTruthy();
136133
expect(hostEl.classList).toContain(classes.icon);
137134
});
@@ -142,7 +139,7 @@ describe('Avatar', () => {
142139
const instance = fixture.componentInstance.avatar;
143140
const hostEl = fixture.debugElement.query(By.css(baseClass)).nativeElement;
144141

145-
expect(instance.type).toEqual(AvatarType.IMAGE);
142+
expect(instance.type).toEqual(IgxAvatarType.IMAGE);
146143
expect(instance.image).toBeTruthy();
147144
expect(instance.image.nativeElement.style.backgroundImage).toBeDefined();
148145

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

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ 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',
27-
ICON = 'icon'
26+
ICON = 'icon',
27+
CUSTOM = 'custom',
2828
}
2929

3030
/**
@@ -118,22 +118,25 @@ export class IgxAvatarComponent implements OnInit, AfterViewInit {
118118

119119
/**
120120
* Returns the type of the avatar.
121-
* The avatar can be: `"initials type avatar"`, `"icon type avatar"` or `"image type avatar"`.
121+
* The avatar can be:
122+
* - `"initials type avatar"`
123+
* - `"icon type avatar"`
124+
* - `"image type avatar"`.
125+
* - `"custom type avatar"`.
122126
*
123127
* ```typescript
124128
* let avatarDescription = this.avatar.roleDescription;
125129
* ```
126130
*
127131
* @memberof IgxAvatarComponent
128132
*/
129-
130133
@HostBinding('attr.aria-roledescription')
131134
public roleDescription: string;
132135

133136
/**
134137
* @hidden
135138
*/
136-
private _size: string | Size = 'small';
139+
private _size: string | IgxAvatarSize = IgxAvatarSize.SMALL;
137140

138141
/**
139142
* Sets the `id` of the avatar. If not set, the first avatar component will have `id` = `"igx-avatar-0"`.
@@ -237,7 +240,7 @@ export class IgxAvatarComponent implements OnInit, AfterViewInit {
237240
* @memberof IgxAvatarComponent
238241
*/
239242
@Input()
240-
public get size(): string | Size {
243+
public get size(): string | IgxAvatarSize {
241244
return this._size;
242245
}
243246

@@ -251,7 +254,7 @@ export class IgxAvatarComponent implements OnInit, AfterViewInit {
251254
*
252255
* @memberof IgxAvatarComponent
253256
*/
254-
public set size(value: string | Size) {
257+
public set size(value: string | IgxAvatarSize) {
255258
switch (value) {
256259
case 'small':
257260
case 'medium':
@@ -272,20 +275,20 @@ export class IgxAvatarComponent implements OnInit, AfterViewInit {
272275
*
273276
* @memberof IgxAvatarComponent
274277
*/
275-
get type(): AvatarType {
278+
get type(): IgxAvatarType {
276279
if (this.src) {
277-
return AvatarType.IMAGE;
280+
return IgxAvatarType.IMAGE;
278281
}
279282

280283
if (this.icon) {
281-
return AvatarType.ICON;
284+
return IgxAvatarType.ICON;
282285
}
283286

284287
if (this.initials) {
285-
return AvatarType.INITIALS;
288+
return IgxAvatarType.INITIALS;
286289
}
287290

288-
return AvatarType.DEFAULT;
291+
return IgxAvatarType.CUSTOM;
289292
}
290293

291294
/**
@@ -299,11 +302,11 @@ export class IgxAvatarComponent implements OnInit, AfterViewInit {
299302
*/
300303
get template(): TemplateRef<any> {
301304
switch (this.type) {
302-
case AvatarType.IMAGE:
305+
case IgxAvatarType.IMAGE:
303306
return this.imageTemplate;
304-
case AvatarType.INITIALS:
307+
case IgxAvatarType.INITIALS:
305308
return this.initialsTemplate;
306-
case AvatarType.ICON:
309+
case IgxAvatarType.ICON:
307310
return this.iconTemplate;
308311
default:
309312
return this.defaultTemplate;
@@ -323,20 +326,23 @@ export class IgxAvatarComponent implements OnInit, AfterViewInit {
323326
*@hidden
324327
*/
325328
public ngAfterViewInit() {
326-
this.elementRef.nativeElement.classList
327-
.add(`igx-avatar--${this._size}`, `igx-avatar--${this.type}`);
329+
if (this.type !== IgxAvatarType.CUSTOM) {
330+
this.elementRef.nativeElement.classList.add(`igx-avatar--${this.type}`);
331+
}
332+
333+
this.elementRef.nativeElement.classList.add(`igx-avatar--${this._size}`);
328334
}
329335

330336
/**
331337
* @hidden
332338
*/
333339
private getRole(): string {
334340
switch (this.type) {
335-
case AvatarType.IMAGE:
341+
case IgxAvatarType.IMAGE:
336342
return 'image avatar';
337-
case AvatarType.ICON:
343+
case IgxAvatarType.ICON:
338344
return 'icon avatar';
339-
case AvatarType.INITIALS:
345+
case IgxAvatarType.INITIALS:
340346
return 'initials avatar';
341347
default:
342348
return 'custom avatar';

projects/igniteui-angular/src/lib/badge/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ A walkthrough of how to get started can be found [here](https://www.infragistics
1313
| Name | Type | Description |
1414
|:----------|:-------------:|:------|
1515
| `id` | string | Unique identifier of the component. If not provided it will be automatically generated.|
16-
| `type` | string | Set the type of the badge to either `default`, `info`, `success`, `warning`, or `error`. This will change the background color of the badge according to the values set in the default theme. |
16+
| `type` | string | Set the type of the badge to either `primary`, `info`, `success`, `warning`, or `error`. This will change the background color of the badge according to the values set in the default theme. |
1717
| `position` | string | Set the position of the badge relative to its parent container to either `top-right`, `top-left`, `bottom-right`, or `bottom-left`. |
1818
| `value` | string | Set the value to be displayed inside the badge. |
1919
| `icon` | string | Set an icon for the badge from the material icons set. Will not be displayed if `value` for the badge is already set. |

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();

0 commit comments

Comments
 (0)