Skip to content

Commit 2475539

Browse files
authored
Merge pull request #8031 from IgniteUI/amarinov/stringEnumsChange_master
fix(inputs): use full union types on all string @input properties - master
2 parents 411ebba + 92799b3 commit 2475539

22 files changed

+186
-153
lines changed

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

+16-13
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,24 @@ import {
1010
ViewChild
1111
} from '@angular/core';
1212
import { IgxIconModule } from '../icon/public_api';
13+
import { mkenum } from '../core/utils';
1314

1415
let NEXT_ID = 0;
15-
16-
export enum IgxAvatarSize {
17-
SMALL = 'small',
18-
MEDIUM = 'medium',
19-
LARGE = 'large'
20-
}
21-
22-
export enum IgxAvatarType {
23-
INITIALS = 'initials',
24-
IMAGE = 'image',
25-
ICON = 'icon',
26-
CUSTOM = 'custom',
27-
}
16+
export const IgxAvatarSize = mkenum({
17+
SMALL: 'small',
18+
MEDIUM: 'medium',
19+
LARGE: 'large'
20+
});
21+
export type IgxAvatarSize = (typeof IgxAvatarSize)[keyof typeof IgxAvatarSize];
22+
23+
export const IgxAvatarType = mkenum({
24+
INITIALS: 'initials',
25+
IMAGE: 'image',
26+
ICON: 'icon',
27+
CUSTOM: 'custom'
28+
});
29+
30+
export type IgxAvatarType = (typeof IgxAvatarType)[keyof typeof IgxAvatarType];
2831

2932
/**
3033
* Avatar provides a way to display an image, icon or initials to the user.

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

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import { CommonModule } from '@angular/common';
22
import { Component, HostBinding, Input, NgModule } from '@angular/core';
33
import { IgxIconModule } from '../icon/public_api';
4+
import { mkenum } from '../core/utils';
45

56
let NEXT_ID = 0;
67

78
/**
89
* Determines the igxBadge type
910
*/
10-
export enum IgxBadgeType {
11-
PRIMARY = 'primary',
12-
INFO = 'info',
13-
SUCCESS = 'success',
14-
WARNING = 'warning',
15-
ERROR = 'error'
16-
}
11+
export const IgxBadgeType = mkenum({
12+
PRIMARY: 'primary',
13+
INFO: 'info',
14+
SUCCESS: 'success',
15+
WARNING: 'warning',
16+
ERROR: 'error'
17+
});
18+
export type IgxBadgeType = (typeof IgxBadgeType)[keyof typeof IgxBadgeType];
1719
/**
1820
* Badge provides visual notifications used to decorate avatars, menus, etc.
1921
*

projects/igniteui-angular/src/lib/calendar/calendar-base.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ import { WEEKDAYS, Calendar, isDateInRanges, IFormattingOptions, IFormattingView
33
import { ControlValueAccessor } from '@angular/forms';
44
import { DateRangeDescriptor } from '../core/dates';
55
import { Subject } from 'rxjs';
6-
import { isDate } from '../core/utils';
6+
import { isDate, mkenum } from '../core/utils';
77
import { CalendarView } from './month-picker-base';
88

99
/**
10-
* Sets the selction type - single, multi or range.
10+
* Sets the selection type - single, multi or range.
1111
*/
12-
export enum CalendarSelection {
13-
SINGLE = 'single',
14-
MULTI = 'multi',
15-
RANGE = 'range'
16-
}
12+
export const CalendarSelection = mkenum({
13+
SINGLE: 'single',
14+
MULTI: 'multi',
15+
RANGE: 'range'
16+
});
17+
export type CalendarSelection = (typeof CalendarSelection)[keyof typeof CalendarSelection];
1718

1819
export enum ScrollMonth {
1920
PREV = 'prev',

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

+11-8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
SimpleChanges
1313
} from '@angular/core';
1414
import { IgxButtonModule } from '../directives/button/button.directive';
15+
import { mkenum } from '../core/utils';
1516

1617
let NEXT_ID = 0;
1718

@@ -200,10 +201,11 @@ export class IgxCardFooterDirective {
200201
* ```
201202
*/
202203

203-
export enum IgxCardType {
204-
ELEVATED = 'elevated',
205-
OUTLINED = 'outlined'
206-
}
204+
export const IgxCardType = mkenum({
205+
ELEVATED: 'elevated',
206+
OUTLINED: 'outlined'
207+
});
208+
export type IgxCardType = (typeof IgxCardType)[keyof typeof IgxCardType];
207209

208210
@Component({
209211
selector: 'igx-card',
@@ -276,10 +278,11 @@ export class IgxCardComponent {
276278
public horizontal = false;
277279
}
278280

279-
export enum IgxCardActionsLayout {
280-
START = 'start',
281-
JUSTIFY = 'justify',
282-
}
281+
export const IgxCardActionsLayout = mkenum({
282+
START: 'start',
283+
JUSTIFY: 'justify'
284+
});
285+
export type IgxCardActionsLayout = (typeof IgxCardActionsLayout)[keyof typeof IgxCardActionsLayout];
283286

284287
/**
285288
* IgxCardActions is container for the card actions.

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

+13-11
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
Injectable
2222
} from '@angular/core';
2323
import { IgxIconModule } from '../icon/public_api';
24-
import { IBaseEventArgs, PlatformUtil } from '../core/utils';
24+
import { IBaseEventArgs, mkenum, PlatformUtil } from '../core/utils';
2525
import { Subject, merge } from 'rxjs';
2626
import { takeUntil } from 'rxjs/operators';
2727
import { IgxCarouselIndicatorDirective, IgxCarouselNextButtonDirective, IgxCarouselPrevButtonDirective } from './carousel.directives';
@@ -34,16 +34,18 @@ import { HammerGestureConfig, HAMMER_GESTURE_CONFIG } from '@angular/platform-br
3434

3535
let NEXT_ID = 0;
3636

37-
export enum CarouselIndicatorsOrientation {
38-
bottom = 'bottom',
39-
top = 'top'
40-
}
41-
42-
export enum CarouselAnimationType {
43-
none = 'none',
44-
slide = 'slide',
45-
fade = 'fade'
46-
}
37+
export const CarouselIndicatorsOrientation = mkenum({
38+
bottom: 'bottom',
39+
top: 'top'
40+
});
41+
export type CarouselIndicatorsOrientation = (typeof CarouselIndicatorsOrientation)[keyof typeof CarouselIndicatorsOrientation];
42+
43+
export const CarouselAnimationType = mkenum({
44+
none: 'none',
45+
slide: 'slide',
46+
fade: 'fade'
47+
});
48+
export type CarouselAnimationType = (typeof CarouselAnimationType)[keyof typeof CarouselAnimationType];
4749

4850
export interface CarouselAnimationSettings {
4951
enterAnimation: AnimationReferenceMetadata;

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import {
1313
} from '@angular/core';
1414
import { CheckboxRequiredValidator, ControlValueAccessor, NG_VALIDATORS, NG_VALUE_ACCESSOR } from '@angular/forms';
1515
import { IgxRippleModule } from '../directives/ripple/ripple.directive';
16-
import { isIE, IBaseEventArgs } from '../core/utils';
16+
import { isIE, IBaseEventArgs, mkenum } from '../core/utils';
1717
import { EditorProvider } from '../core/edit-provider';
1818

19-
export enum LabelPosition {
20-
BEFORE = 'before',
21-
AFTER = 'after'
22-
}
19+
export const LabelPosition = mkenum({
20+
BEFORE: 'before',
21+
AFTER: 'after'
22+
});
23+
export type LabelPosition = (typeof LabelPosition)[keyof typeof LabelPosition];
2324

2425
export interface IChangeCheckboxEventArgs extends IBaseEventArgs {
2526
checked: boolean;

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { InjectionToken, Input, Output, EventEmitter, DoCheck, OnInit, Directive, NgModule, Optional, Inject } from '@angular/core';
2-
import { IBaseEventArgs } from './utils';
3-
2+
import { IBaseEventArgs, mkenum } from './utils';
43

54
/**
6-
* Defines the posible values of the components' display density.
5+
* Defines the possible values of the components' display density.
76
*/
8-
export enum DisplayDensity {
9-
comfortable = 'comfortable',
10-
cosy = 'cosy',
11-
compact = 'compact'
12-
}
7+
export const DisplayDensity = mkenum({
8+
comfortable: 'comfortable',
9+
cosy: 'cosy',
10+
compact: 'compact'
11+
});
12+
export type DisplayDensity = (typeof DisplayDensity)[keyof typeof DisplayDensity];
1313

1414
/**
1515
* Describes the object used to configure the DisplayDensity in Angular DI.

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

+2
Original file line numberDiff line numberDiff line change
@@ -449,3 +449,5 @@ export function yieldingLoop(count: number, chunkSize: number, callback: (index:
449449
};
450450
chunk();
451451
}
452+
453+
export function mkenum<T extends { [index: string]: U }, U extends string>(x: T) { return x; }

projects/igniteui-angular/src/lib/data-operations/data-util.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,20 @@ import { IGroupingState } from './groupby-state.interface';
1212
import { ISortingExpression } from './sorting-expression.interface';
1313
import { FilteringStrategy } from './filtering-strategy';
1414
import { ITreeGridRecord } from '../grids/tree-grid/public_api';
15-
import { cloneValue, mergeObjects } from '../core/utils';
15+
import { cloneValue, mergeObjects, mkenum } from '../core/utils';
1616
import { Transaction, TransactionType, HierarchicalTransaction } from '../services/transaction/transaction';
1717
import { getHierarchy, isHierarchyMatch } from './operations';
1818

1919
/**
2020
* @hidden
2121
*/
22-
export enum DataType {
23-
String = 'string',
24-
Number = 'number',
25-
Boolean = 'boolean',
26-
Date = 'date'
27-
}
22+
export const DataType = mkenum({
23+
String: 'string',
24+
Number: 'number',
25+
Boolean: 'boolean',
26+
Date: 'date'
27+
});
28+
export type DataType = (typeof DataType)[keyof typeof DataType];
2829

2930
/**
3031
* @hidden

projects/igniteui-angular/src/lib/date-picker/date-picker.component.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import {
5656
} from './date-picker.utils';
5757
import { DatePickerDisplayValuePipe, DatePickerInputValuePipe } from './date-picker.pipes';
5858
import { IDatePicker } from './date-picker.common';
59-
import { KEYS, CancelableBrowserEventArgs, isIE, isEqual, IBaseEventArgs } from '../core/utils';
59+
import { KEYS, CancelableBrowserEventArgs, isIE, isEqual, IBaseEventArgs, mkenum } from '../core/utils';
6060
import { IgxDatePickerTemplateDirective, IgxDatePickerActionsDirective } from './date-picker.directives';
6161
import { IgxCalendarContainerComponent } from './calendar-container.component';
6262
import { InteractionMode } from '../core/enums';
@@ -109,12 +109,13 @@ export interface IFormatOptions {
109109
* 'longDate': equivalent to 'MMMM d, y' (June 15, 2015).
110110
* 'fullDate': equivalent to 'EEEE, MMMM d, y' (Monday, June 15, 2015).
111111
*/
112-
export enum PredefinedFormatOptions {
113-
ShortDate = 'shortDate',
114-
MediumDate = 'mediumDate',
115-
LongDate = 'longDate',
116-
FullDate = 'fullDate'
117-
}
112+
export const PredefinedFormatOptions = mkenum({
113+
ShortDate: 'shortDate',
114+
MediumDate: 'mediumDate',
115+
LongDate: 'longDate',
116+
FullDate: 'fullDate'
117+
});
118+
export type PredefinedFormatOptions = (typeof PredefinedFormatOptions)[keyof typeof PredefinedFormatOptions];
118119

119120
const noop = () => { };
120121

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { Directive, HostBinding, NgModule, Input } from '@angular/core';
2+
import { mkenum } from '../../core/utils';
23

3-
export enum IgxDividerType {
4-
SOLID = 'solid',
5-
DASHED = 'dashed'
6-
}
4+
export const IgxDividerType = mkenum({
5+
SOLID: 'solid',
6+
DASHED: 'dashed'
7+
});
8+
export type IgxDividerType = (typeof IgxDividerType)[keyof typeof IgxDividerType];
79

810
let NEXT_ID = 0;
911

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

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CancelableEventArgs, CancelableBrowserEventArgs, IBaseEventArgs } from '../core/utils';
1+
import { CancelableEventArgs, CancelableBrowserEventArgs, IBaseEventArgs, mkenum } from '../core/utils';
22
import { IgxDropDownItemBaseDirective } from './drop-down-item.base';
33
import { IToggleView } from '../core/navigation/IToggleView';
44
import { EventEmitter, InjectionToken } from '@angular/core';
@@ -11,11 +11,12 @@ export enum Navigate {
1111
}
1212

1313
/** Key actions that have designated handlers in IgxDropDownComponent */
14-
export enum DropDownActionKey {
15-
ESCAPE = 'escape',
16-
ENTER = 'enter',
17-
SPACE = 'space'
18-
}
14+
export const DropDownActionKey = mkenum({
15+
ESCAPE: 'escape',
16+
ENTER: 'enter',
17+
SPACE: 'space'
18+
});
19+
export type DropDownActionKey = (typeof DropDownActionKey)[keyof typeof DropDownActionKey];
1920

2021
/**
2122
* Interface that encapsulates onSelection event arguments - old selection, new selection and cancel selection.

projects/igniteui-angular/src/lib/expansion-panel/expansion-panel-header.component.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ import {
1313
} from '@angular/core';
1414
import { IgxExpansionPanelIconDirective } from './expansion-panel.directives';
1515
import { IExpansionPanelEventArgs, IGX_EXPANSION_PANEL_COMPONENT, IgxExpansionPanelBase } from './expansion-panel.common';
16+
import { mkenum } from '../core/utils';
1617

1718
/**
1819
* @hidden
1920
*/
20-
export enum ICON_POSITION {
21-
LEFT = 'left',
22-
NONE = 'none',
23-
RIGHT = 'right'
24-
}
21+
export const ICON_POSITION = mkenum({
22+
LEFT: 'left',
23+
NONE: 'none',
24+
RIGHT: 'right'
25+
});
26+
export type ICON_POSITION = (typeof ICON_POSITION)[keyof typeof ICON_POSITION];
2527

2628

2729
@Component({

projects/igniteui-angular/src/lib/grids/column-actions/column-actions.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export class IgxColumnActionsComponent implements DoCheck {
167167
/**
168168
* @hidden @internal
169169
*/
170-
private _columnDisplayOrder = ColumnDisplayOrder.DisplayOrder;
170+
private _columnDisplayOrder: ColumnDisplayOrder = ColumnDisplayOrder.DisplayOrder;
171171
/**
172172
* Gets the display order of the columns.
173173
* @example

projects/igniteui-angular/src/lib/grids/column-chooser-base.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export abstract class ColumnChooserBaseDirective implements OnDestroy {
205205
/**
206206
* @hidden
207207
*/
208-
private _columnDisplayOrder = ColumnDisplayOrder.DisplayOrder;
208+
private _columnDisplayOrder: ColumnDisplayOrder = ColumnDisplayOrder.DisplayOrder;
209209
/**
210210
* @hidden
211211
*/

0 commit comments

Comments
 (0)