-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(filters): Attribute selector component
- Loading branch information
1 parent
b053e0f
commit 4c26d62
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
...ayers/common/filters/comparison-filter/attribute-selector/attribute-selector.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,63 @@ | ||
import {Component, forwardRef, input} from '@angular/core'; | ||
import { | ||
ControlValueAccessor, | ||
FormsModule, | ||
NG_VALUE_ACCESSOR, | ||
ReactiveFormsModule, | ||
} from '@angular/forms'; | ||
import {TranslateCustomPipe} from 'hslayers-ng/services/language'; | ||
|
||
@Component({ | ||
selector: 'hs-attribute-selector', | ||
standalone: true, | ||
imports: [FormsModule, ReactiveFormsModule, TranslateCustomPipe], | ||
providers: [ | ||
{ | ||
provide: NG_VALUE_ACCESSOR, | ||
// eslint-disable-next-line no-use-before-define | ||
useExisting: forwardRef(() => HsAttributeSelectorComponent), | ||
multi: true, | ||
}, | ||
], | ||
template: ` | ||
<select | ||
class="form-control form-select hs-comparison-filter-attribute h-100 border-end-0" | ||
[(ngModel)]="value" | ||
(ngModelChange)="onChange($event)" | ||
(blur)="onTouched()" | ||
[disabled]="disabled" | ||
> | ||
<option [ngValue]="null" [disabled]="true" hidden> | ||
{{ 'FILTERS.pickAnAttribute' | translateHs }} | ||
</option> | ||
@for (attr of attributes(); track attr) { | ||
<option [ngValue]="attr">{{ attr }}</option> | ||
} | ||
</select> | ||
`, | ||
}) | ||
export class HsAttributeSelectorComponent implements ControlValueAccessor { | ||
attributes = input.required<string[]>(); | ||
|
||
value: string = null; | ||
disabled = false; | ||
|
||
onChange: (value: string) => void = () => {}; | ||
onTouched: () => void = () => {}; | ||
|
||
writeValue(value: string): void { | ||
this.value = value; | ||
} | ||
|
||
registerOnChange(fn: (value: string) => void): void { | ||
this.onChange = fn; | ||
} | ||
|
||
registerOnTouched(fn: () => void): void { | ||
this.onTouched = fn; | ||
} | ||
|
||
setDisabledState(isDisabled: boolean): void { | ||
this.disabled = isDisabled; | ||
} | ||
} |