Skip to content

Commit c13e300

Browse files
authored
Merge pull request #8788 from IgniteUI/slider-enum-string-types
feat(slider): update slider enums as a string union types
2 parents cd3d0bb + 28ec88f commit c13e300

File tree

5 files changed

+36
-32
lines changed

5 files changed

+36
-32
lines changed

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

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Directive } from '@angular/core';
2-
import { IBaseEventArgs } from '../core/utils';
2+
import { IBaseEventArgs, mkenum } from '../core/utils';
33

44
/**
55
* Template directive that allows you to set a custom template representing the lower label value of the {@link IgxSliderComponent}
@@ -53,36 +53,40 @@ export interface ISliderValueChangeEventArgs {
5353
value: number | IRangeSliderValue;
5454
}
5555

56-
export enum IgxSliderType {
56+
export const IgxSliderType = mkenum({
5757
/**
5858
* Slider with single thumb.
5959
*/
60-
SLIDER,
60+
SLIDER: 'slider',
6161
/**
6262
* Range slider with multiple thumbs, that can mark the range.
6363
*/
64-
RANGE
65-
}
64+
RANGE: 'range'
65+
});
66+
export type IgxSliderType = (typeof IgxSliderType)[keyof typeof IgxSliderType];
6667

67-
export enum SliderHandle {
68-
FROM,
69-
TO
70-
}
68+
export const SliderHandle = mkenum({
69+
FROM: 'from',
70+
TO: 'to'
71+
});
72+
export type SliderHandle = (typeof SliderHandle)[keyof typeof SliderHandle];
7173

7274
/**
7375
* Slider Tick labels Orientation
7476
*/
75-
export enum TickLabelsOrientation {
76-
Horizontal,
77-
TopToBottom,
78-
BottomToTop
79-
}
77+
export const TickLabelsOrientation = mkenum({
78+
Horizontal: 'horizontal',
79+
TopToBottom: 'toptobottom',
80+
BottomToTop: 'bottomtotop'
81+
});
82+
export type TickLabelsOrientation = (typeof TickLabelsOrientation)[keyof typeof TickLabelsOrientation];
8083

8184
/**
8285
* Slider Ticks orientation
8386
*/
84-
export enum TicksOrientation {
85-
Top,
86-
Bottom,
87-
Mirror
88-
}
87+
export const TicksOrientation = mkenum({
88+
Top: 'top',
89+
Bottom: 'bottom',
90+
Mirror: 'mirror'
91+
});
92+
export type TicksOrientation = (typeof TicksOrientation)[keyof typeof TicksOrientation];

projects/igniteui-angular/src/lib/slider/slider.component.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="igx-slider__track">
22
<igx-ticks
33
*ngIf="showTicks && showTopTicks"
4-
[ticksOrientation]="0"
4+
ticksOrientation="top"
55
[primaryTicks]="primaryTicks"
66
[secondaryTicks]="secondaryTicks"
77
[primaryTickLabels]="primaryTickLabels"
@@ -18,7 +18,7 @@
1818

1919
<igx-ticks
2020
*ngIf="showTicks && showBottomTicks"
21-
[ticksOrientation]="1"
21+
ticksOrientation="bottom"
2222
[primaryTicks]="primaryTicks"
2323
[secondaryTicks]="secondaryTicks"
2424
[primaryTickLabels]="primaryTickLabels"
@@ -33,7 +33,7 @@
3333
<div class="igx-slider__thumbs">
3434
<igx-thumb-label
3535
*ngIf="isRange"
36-
[type]="0"
36+
type="from"
3737
[value]="lowerLabel"
3838
[templateRef]="thumbFromTemplateRef"
3939
[continuous]="continuous"
@@ -44,7 +44,7 @@
4444
<igx-thumb
4545
*ngIf="isRange"
4646
#thumbFrom
47-
[type]="0"
47+
type="from"
4848
[value]="lowerLabel"
4949
[disabled]="disabled"
5050
[continuous]="continuous"
@@ -60,7 +60,7 @@
6060

6161
<igx-thumb-label
6262
[value]="upperLabel"
63-
[type]="1"
63+
type="to"
6464
[templateRef]="thumbToTemplateRef"
6565
[continuous]="continuous"
6666
[context]="context"
@@ -69,7 +69,7 @@
6969

7070
<igx-thumb
7171
#thumbTo
72-
[type]="1"
72+
type="to"
7373
[value]="upperLabel"
7474
[disabled]="disabled"
7575
[continuous]="continuous"

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

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

16571657
return new Promise((resolve, reject) => {
16581658
Simulator.gestures.pan(element, panOptions, () => {
1659-
resolve();
1659+
resolve(null);
16601660
});
16611661
});
16621662
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ export class IgxSliderComponent implements
242242
*/
243243
@Input()
244244
public get type() {
245-
return this._type;
245+
return this._type as IgxSliderType;
246246
}
247247

248248
/**
@@ -1096,7 +1096,7 @@ export class IgxSliderComponent implements
10961096
/**
10971097
* @hidden
10981098
*/
1099-
public thumbChanged(value: number, thumbType: number) {
1099+
public thumbChanged(value: number, thumbType: string) {
11001100
const oldValue = this.value;
11011101

11021102
let newVal: IRangeSliderValue;
@@ -1401,7 +1401,7 @@ export class IgxSliderComponent implements
14011401
return value;
14021402
}
14031403

1404-
private subscribeTo(thumb: IgxSliderThumbComponent, callback: (a: number, b: number) => void) {
1404+
private subscribeTo(thumb: IgxSliderThumbComponent, callback: (a: number, b: string) => void) {
14051405
if (!thumb) {
14061406
return;
14071407
}

src/app/slider/slider.sample.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ <h4 class="sample-title">Range label slider</h4>
2424
<article class="sample-column" class="flex-row">
2525
<h4 class="sample-title">Range label slider</h4>
2626
<span class="outer-label">{{getLowerVal}}</span>
27-
<igx-slider style="width: 60%;" #slider2 [type]="sliderType" (onValueChange)="valueChange($event)"
27+
<igx-slider style="width: 60%;" #slider2 type="range" (onValueChange)="valueChange($event)"
2828
[labels]="labels" [continuous]="true">
2929
</igx-slider>
3030
<span class="outer-label">{{getUpperVal}}</span>
@@ -90,7 +90,7 @@ <h4>Slider ticks</h4>
9090
<button igxButton="outlined" (click)="primaryTickLabels = !primaryTickLabels">show/hide primary labels</button>
9191
<button igxButton="outlined" (click)="secondaryTickLabels = !secondaryTickLabels">show/hide secondary labels</button>
9292
<button igxButton="outlined" (click)="changeLabels()">change labels</button>
93-
<button igxButton="outlined" (click)="sliderType = sliderType === 0 ? 1 : 0">change type</button>
94-
<button igxButton="outlined" (click)="sliderType = sliderType === 0 ? 1 : 0">change step</button>
93+
<button igxButton="outlined" (click)="sliderType = sliderType === 'slider' ? 'range' : 'slider'">change type</button>
94+
<button igxButton="outlined" (click)="sliderType = sliderType === 'slider' ? 'range' : 'slider'">change step</button>
9595
</div>
9696
</section>

0 commit comments

Comments
 (0)