Skip to content

Commit

Permalink
feat(filters): Attribute selector component
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipLeitner committed Nov 19, 2024
1 parent b053e0f commit 4c26d62
Showing 1 changed file with 63 additions and 0 deletions.
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;
}
}

0 comments on commit 4c26d62

Please sign in to comment.