-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
571f9b7
commit ee0170c
Showing
22 changed files
with
402 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
projects/design-angular-kit/src/lib/components/form/range/range.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<div class="d-flex justify-content-between align-items-center"> | ||
<label *ngIf="label" [for]="id" class="form-label">{{label}}</label> | ||
<ng-content></ng-content> | ||
</div> | ||
|
||
<input #slider | ||
[id]="id" | ||
type="range" | ||
[min]="min" | ||
[max]="max" | ||
[step]="step" | ||
class="form-range" | ||
[class.double-color]="!!leftColor && !!rightColor" | ||
[formControl]="control"> |
3 changes: 3 additions & 0 deletions
3
projects/design-angular-kit/src/lib/components/form/range/range.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.form-range.double-color::-webkit-slider-runnable-track { | ||
background: linear-gradient(to right, var(--range-left-color) var(--range-percentage), var(--range-right-color) var(--range-percentage)); | ||
} |
21 changes: 21 additions & 0 deletions
21
projects/design-angular-kit/src/lib/components/form/range/range.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { ItRangeComponent } from './range.component'; | ||
import { tb_base } from '../../../../test'; | ||
|
||
describe('ItRangeComponent', () => { | ||
let component: ItRangeComponent; | ||
let fixture: ComponentFixture<ItRangeComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule(tb_base).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(ItRangeComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
103 changes: 103 additions & 0 deletions
103
projects/design-angular-kit/src/lib/components/form/range/range.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
ElementRef, | ||
Input, | ||
OnChanges, | ||
OnDestroy, | ||
OnInit, | ||
SimpleChanges, | ||
ViewChild | ||
} from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { ItAbstractFormComponent } from '../../../abstracts/abstract-form.component'; | ||
import { ReactiveFormsModule } from '@angular/forms'; | ||
import { distinctUntilChanged, startWith, Subscription } from 'rxjs'; | ||
|
||
@Component({ | ||
selector: 'it-range', | ||
standalone: true, | ||
imports: [CommonModule, ReactiveFormsModule], | ||
templateUrl: './range.component.html', | ||
styleUrls: ['./range.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush | ||
}) | ||
export class ItRangeComponent extends ItAbstractFormComponent<number | null | undefined> implements OnInit, OnChanges, OnDestroy { | ||
|
||
/** | ||
* The max value | ||
*/ | ||
@Input() max?: number; | ||
|
||
/** | ||
* The min value | ||
*/ | ||
@Input() min?: number; | ||
|
||
/** | ||
* The step value | ||
*/ | ||
@Input() step?: number | 'any'; | ||
|
||
/** | ||
* The color on left of thumb [Require rightColor] | ||
* @example '#0d6efd' or 'var(--bs-primary)' | ||
* @default undefined ('var(--bs-gray-300)') | ||
*/ | ||
@Input() leftColor?: string; | ||
|
||
/** | ||
* The color on right of thumb [Require leftColor] | ||
* @example '#0d6efd' or 'var(--bs-primary)' | ||
* @default undefined ('var(--bs-gray-300)') | ||
*/ | ||
@Input() rightColor?: string; | ||
|
||
@ViewChild('slider', { static: true }) slider!: ElementRef<HTMLInputElement>; | ||
|
||
private subscription?: Subscription; | ||
|
||
override ngOnInit() { | ||
super.ngOnInit(); | ||
this.subscription = this.control.valueChanges.pipe( | ||
distinctUntilChanged(), | ||
startWith(undefined) | ||
).subscribe(() => this.updateSliderColor()); | ||
} | ||
|
||
ngOnChanges(changes: SimpleChanges) { | ||
if (changes['leftColor']) { | ||
this.slider.nativeElement.style.setProperty('--range-left-color', this.leftColor ?? null); | ||
} | ||
if (changes['rightColor']) { | ||
this.slider.nativeElement.style.setProperty('--range-right-color', this.rightColor ?? null); | ||
} | ||
} | ||
|
||
ngOnDestroy() { | ||
this.subscription?.unsubscribe(); | ||
} | ||
|
||
override writeValue(value: number | null | undefined) { | ||
super.writeValue(value); | ||
this.updateSliderColor(); | ||
} | ||
|
||
/** | ||
* Update the percentage of slider color | ||
* @private | ||
*/ | ||
private updateSliderColor(): void { | ||
if (!this.leftColor || !this.rightColor) { | ||
return; | ||
} | ||
|
||
const max = Number(this.slider.nativeElement.max) || 100; | ||
const min = Number(this.slider.nativeElement.min) || 0; | ||
|
||
// Calculate visible width | ||
const diff = max - min; | ||
const val = (((this.control.value ?? (diff / 2)) - min) * 100) / diff; | ||
this.slider.nativeElement.style.setProperty('--range-percentage', `${val}%`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/app/range/range-custom-colors/range-custom-colors.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<h3>Barra personalizzata</h3> | ||
<div class="bd-example"> | ||
|
||
<div class="row"> | ||
<div class="col"> | ||
<it-range leftColor="var(--bs-primary)" | ||
rightColor="var(--bs-gray-300)"></it-range> | ||
</div> | ||
|
||
<div class="col"> | ||
<it-range leftColor="var(--bs-warning)" | ||
rightColor="#ffdc73"></it-range> | ||
</div> | ||
</div> | ||
|
||
</div> |
21 changes: 21 additions & 0 deletions
21
src/app/range/range-custom-colors/range-custom-colors.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { RangeCustomColorsComponent } from './range-custom-colors.component'; | ||
|
||
describe('RangeCustomColorsComponent', () => { | ||
let component: RangeCustomColorsComponent; | ||
let fixture: ComponentFixture<RangeCustomColorsComponent>; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [RangeCustomColorsComponent] | ||
}); | ||
fixture = TestBed.createComponent(RangeCustomColorsComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
8 changes: 8 additions & 0 deletions
8
src/app/range/range-custom-colors/range-custom-colors.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'it-range-custom-colors', | ||
templateUrl: './range-custom-colors.component.html' | ||
}) | ||
export class RangeCustomColorsComponent { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<div class="bd-example"> | ||
<div class="row"> | ||
<div class="col"> | ||
<it-range label="Esempio ngModel" [(ngModel)]="rangeValue"> | ||
{{rangeValue}} % | ||
</it-range> | ||
</div> | ||
<div class="col"> | ||
<form [formGroup]="formGroup"> | ||
<it-range label="Esempio FormGroup" | ||
[min]="0" [max]="1000" [step]="2" formControlName="range"> | ||
Valore selezionato: {{formGroup.get('range').value}} | ||
</it-range> | ||
</form> | ||
</div> | ||
</div> | ||
</div> |
21 changes: 21 additions & 0 deletions
21
src/app/range/range-example/range-example.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { RangeExampleComponent } from './range-example.component'; | ||
|
||
describe('RangeExampleComponent', () => { | ||
let component: RangeExampleComponent; | ||
let fixture: ComponentFixture<RangeExampleComponent>; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [RangeExampleComponent] | ||
}); | ||
fixture = TestBed.createComponent(RangeExampleComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Component } from '@angular/core'; | ||
import { FormBuilder, FormGroup } from '@angular/forms'; | ||
|
||
@Component({ | ||
selector: 'it-range-example', | ||
templateUrl: './range-example.component.html' | ||
}) | ||
export class RangeExampleComponent { | ||
|
||
rangeValue = 50; | ||
|
||
formGroup: FormGroup; | ||
|
||
constructor( | ||
private readonly formBuilder: FormBuilder | ||
) { | ||
this.formGroup = this.formBuilder.group({ | ||
range: [null] | ||
}) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/app/range/range-examples/range-examples.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { RangeExamplesComponent } from './range-examples.component'; | ||
|
||
describe('RangeExamplesComponent', () => { | ||
let component: RangeExamplesComponent; | ||
let fixture: ComponentFixture<RangeExamplesComponent>; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [RangeExamplesComponent] | ||
}); | ||
fixture = TestBed.createComponent(RangeExamplesComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{% from "../../macro.template.njk" import sanitize as sanitize %} | ||
|
||
{% set html %} | ||
{% include "../range-example/range-example.component.html" %} | ||
{% endset %} | ||
|
||
{% set typescript %} | ||
{% include "../range-example/range-example.component.ts" %} | ||
{% endset %} | ||
|
||
<it-range-example></it-range-example> | ||
|
||
<it-source-display html="{$ sanitize(html) $}" typescript="{$ sanitize(typescript) $}"></it-source-display> | ||
|
||
|
||
{% set htmlCustomColors %} | ||
{% include "../range-custom-colors/range-custom-colors.component.html" %} | ||
{% endset %} | ||
|
||
{% set typescriptCustomColors %} | ||
{% include "../range-custom-colors/range-custom-colors.component.ts" %} | ||
{% endset %} | ||
|
||
<it-range-custom-colors></it-range-custom-colors> | ||
|
||
<it-source-display html="{$ sanitize(htmlCustomColors) $}" typescript="{$ sanitize(typescriptCustomColors) $}"></it-source-display> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'it-range-examples', | ||
templateUrl: './range-examples.component.html' | ||
}) | ||
export class RangeExamplesComponent { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<h1 class="bd-title">Range</h1> | ||
<p class="bd-lead"> | ||
Input di intervallo personalizzato per uno stile uniforme su tutti i browser e personalizzazione integrata. | ||
</p> | ||
|
||
<it-tab-container> | ||
<it-tab-item label="Esempi" active="true" class="pt-3"> | ||
<it-range-examples></it-range-examples> | ||
</it-tab-item> | ||
<it-tab-item label="API" class="pt-3"> | ||
<h3>ItRangeComponent</h3> | ||
<it-api-parameters [component]="component"></it-api-parameters> | ||
</it-tab-item> | ||
</it-tab-container> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { RangeIndexComponent } from './range-index.component'; | ||
|
||
describe('RangeIndexComponent', () => { | ||
let component: RangeIndexComponent; | ||
let fixture: ComponentFixture<RangeIndexComponent>; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [RangeIndexComponent] | ||
}); | ||
fixture = TestBed.createComponent(RangeIndexComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
Oops, something went wrong.