-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/design
- Loading branch information
Showing
6 changed files
with
90 additions
and
9 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
src/app/components/slider-with-value/slider-with-value.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,4 @@ | ||
<div class="flex"> | ||
<input type="range" [min]="min()" [max]="max()" [step]="step()" [value]="value()" (input)="value.set(Number(input1.value))" class="form-control" [id]="inputId()" #input1 /> | ||
<input type="number" [min]="min()" [max]="max()" [step]="step()" class="form-control" [value]="value()" (input)="value.set(Number(input2.value))" #input2 /> | ||
</div> |
9 changes: 9 additions & 0 deletions
9
src/app/components/slider-with-value/slider-with-value.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,9 @@ | ||
div > input { | ||
&:first-child { | ||
flex: 85% 1 1; | ||
margin-right: 1vw; | ||
} | ||
&:last-child { | ||
flex: 15% 1 1; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/app/components/slider-with-value/slider-with-value.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,64 @@ | ||
import {Component, effect, input, signal, WritableSignal} from '@angular/core'; | ||
import {ControlValueAccessor, NG_VALUE_ACCESSOR, ReactiveFormsModule} from "@angular/forms"; | ||
import {OnChange, OnTouched} from "../../types/value-accessor"; | ||
|
||
@Component({ | ||
selector: 'app-slider-with-value', | ||
standalone: true, | ||
imports: [ | ||
ReactiveFormsModule | ||
], | ||
templateUrl: './slider-with-value.component.html', | ||
styleUrl: './slider-with-value.component.scss', | ||
providers: [ | ||
{ | ||
provide: NG_VALUE_ACCESSOR, | ||
multi: true, | ||
useExisting: SliderWithValueComponent, | ||
}, | ||
] | ||
}) | ||
export class SliderWithValueComponent implements ControlValueAccessor { | ||
protected readonly Number = Number; | ||
|
||
private onChange: WritableSignal<OnChange<number> | null> = signal(null); | ||
private onTouched: WritableSignal<OnTouched | null> = signal(null); | ||
|
||
public inputId = input<string>(); | ||
public required = input(false); | ||
public min = input<number | null>(null); | ||
public max = input<number | null>(null); | ||
public step = input<number | null>(null); | ||
|
||
public disabled = signal(false); | ||
|
||
public value = signal(0); | ||
|
||
constructor() { | ||
effect(() => { | ||
if (this.onChange() === null) { | ||
return; | ||
} | ||
(this.onChange()!)(this.value()); | ||
if (this.onTouched() !== null) { | ||
(this.onTouched()!)(); | ||
} | ||
}); | ||
} | ||
|
||
public registerOnChange(fn: OnChange<number>): void { | ||
this.onChange.set(fn); | ||
} | ||
|
||
public registerOnTouched(fn: OnTouched): void { | ||
this.onTouched.set(fn); | ||
} | ||
|
||
public setDisabledState(isDisabled: boolean): void { | ||
this.disabled.set(isDisabled); | ||
} | ||
|
||
public writeValue(obj: number): void { | ||
this.value.set(obj); | ||
} | ||
} |
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
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