Skip to content

Commit 7c4c030

Browse files
authored
Merge pull request #5715 from IgniteUI/slider-label-ie11-master
feat(slider): exposing the label as a separate component
2 parents f1c517f + d5ccb93 commit 7c4c030

File tree

8 files changed

+185
-51
lines changed

8 files changed

+185
-51
lines changed

projects/igniteui-angular/src/lib/core/styles/components/slider/_slider-component.scss

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@
3434
@include e(thumb-#{$t}) {
3535
@extend %igx-thumb-display !optional;
3636

37-
.label {
38-
@extend %igx-thumb-label !optional;
39-
}
40-
4137
.dot {
4238
@extend %igx-thumb-dot !optional;
4339
}
@@ -46,12 +42,24 @@
4642
@include e(thumb-#{$t}, $m: active) {
4743
@extend %igx-thumb--active !optional;
4844

45+
.dot {
46+
@extend %igx-thumb-dot--active !optional;
47+
}
48+
}
49+
50+
@include e(label-#{$t}) {
51+
@extend %igx-label-display !optional;
52+
4953
.label {
50-
@extend %igx-thumb-label--active !optional;
54+
@extend %igx-thumb-label !optional;
5155
}
56+
}
5257

53-
.dot {
54-
@extend %igx-thumb-dot--active !optional;
58+
@include e(label-#{$t}, $m: active) {
59+
@extend %igx-thumb--active !optional;
60+
61+
.label {
62+
@extend %igx-thumb-label--active !optional;
5563
}
5664
}
5765
}
@@ -91,10 +99,6 @@
9199
@extend %igx-thumb-display !optional;
92100
@extend %igx-thumb--disabled !optional;
93101

94-
.label {
95-
@extend %igx-thumb-label !optional;
96-
}
97-
98102
.dot {
99103
@extend %igx-thumb-dot--disabled !optional;
100104
}

projects/igniteui-angular/src/lib/core/styles/components/slider/_slider-theme.scss

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,26 @@
219219
}
220220
}
221221

222-
%igx-thumb-label {
222+
%igx-label-display {
223223
position: absolute;
224224
display: flex;
225+
justify-content: center;
226+
align-items: center;
227+
flex-direction: column;
228+
height: $slider-thumb-height;
229+
outline-style: none;
230+
top: -#{rem($slider-thumb-radius)};
231+
margin: 0 auto;
232+
}
233+
234+
%igx-thumb-label {
235+
position: relative;
236+
display: flex;
225237
align-items: center;
226238
justify-content: center;
227239
flex: 0 0 auto;
228-
top: -#{rem($slider-thumb-height - 6px)};
240+
top: -#{rem($slider-thumb-height - 4px)};
241+
left: -50%;
229242
pointer-events: none;
230243
min-width: rem($slider-label-width);
231244
height: rem($slider-label-height);
@@ -234,7 +247,7 @@
234247
margin: 0 auto;
235248
font-size: $slider-label-font-size;
236249
font-weight: $slider-label-font-weight;
237-
line-height: 1;
250+
line-height: rem(18px);
238251
color: --var($theme, 'label-text-color');
239252
background: --var($theme, 'label-background-color');
240253
opacity: 0;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div class="label">
2+
<ng-container *ngTemplateOutlet="templateRef ? templateRef : thumbFromDefaultTemplate; context: context"></ng-container>
3+
</div>
4+
5+
<ng-template #thumbFromDefaultTemplate>
6+
{{ value }}
7+
</ng-template>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { Component, NgModule, Input, TemplateRef, HostBinding, ElementRef } from '@angular/core';
2+
import { SliderHandle } from '../slider.common';
3+
4+
@Component({
5+
selector: 'igx-thumb-label',
6+
templateUrl: 'thumb-label.component.html'
7+
})
8+
export class IgxThumbLabelComponent {
9+
private _active: boolean;
10+
11+
@Input()
12+
public value: number;
13+
14+
@Input()
15+
public templateRef: TemplateRef<any>;
16+
17+
@Input()
18+
public context: any;
19+
20+
@Input()
21+
public type: SliderHandle;
22+
23+
@Input()
24+
public continuous: boolean;
25+
26+
@HostBinding('class.igx-slider__label-from')
27+
public get thumbFromClass() {
28+
return this.type === SliderHandle.FROM;
29+
}
30+
31+
@HostBinding('class.igx-slider__label-to')
32+
public get thumbToClass() {
33+
return this.type === SliderHandle.TO;
34+
}
35+
36+
@HostBinding('class.igx-slider__label-from--active')
37+
public get thumbFromActiveClass() {
38+
return this.type === SliderHandle.FROM && this.active;
39+
}
40+
41+
@HostBinding('class.igx-slider__label-to--active')
42+
public get thumbToActiveClass() {
43+
return this.type === SliderHandle.TO && this.active;
44+
}
45+
46+
constructor(private _elementRef: ElementRef) { }
47+
48+
public get nativeElement() {
49+
return this._elementRef.nativeElement;
50+
}
51+
52+
public get active() {
53+
return this._active;
54+
}
55+
56+
public set active(val: boolean) {
57+
if (this.continuous) {
58+
return;
59+
}
60+
61+
this._active = val;
62+
}
63+
}

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
<div #ticks class="igx-slider__track-ticks"></div>
44
</div>
55
<div class="igx-slider__thumbs">
6-
<igx-thumb *ngIf="isRange"
6+
<igx-thumb-label
7+
*ngIf="isRange"
8+
[type]="0"
9+
[value]="value"
10+
[templateRef]="thumbFromTemplateRef"
11+
[continuous]="continuous"
12+
[context]="context"></igx-thumb-label>
13+
14+
<igx-thumb *ngIf="isRange"
715
#thumbFrom
816
[type]="0"
917
[value]="lowerLabel"
@@ -17,7 +25,15 @@
1725
(onChange)="onThumbChange()"
1826
(onHoverChange)="onHoverChange($event)"
1927
[thumbLabelVisibilityDuration]="thumbLabelVisibilityDuration"></igx-thumb>
20-
<igx-thumb
28+
29+
<igx-thumb-label
30+
[value]="value"
31+
[type]="1"
32+
[templateRef]="thumbToTemplateRef"
33+
[continuous]="continuous"
34+
[context]="context"></igx-thumb-label>
35+
36+
<igx-thumb
2137
#thumbTo
2238
[type]="1"
2339
[value]="upperLabel"
@@ -31,4 +47,5 @@
3147
(onChange)="onThumbChange()"
3248
(onHoverChange)="onHoverChange($event)"
3349
[thumbLabelVisibilityDuration]="thumbLabelVisibilityDuration"></igx-thumb>
50+
3451
</div>

0 commit comments

Comments
 (0)