Files
kirjs d6f4b104e3 docs(docs-infra): Drop standalone: true (#58914)
This is now the default value, so safe to remove

PR Close #58914
2024-11-28 09:43:28 +01:00

51 lines
1.2 KiB
TypeScript

/*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {Directive, ElementRef, Input, inject, signal} from '@angular/core';
import {Highlightable} from '@angular/cdk/a11y';
import {SearchResult} from '../../interfaces/search-results';
@Directive({
selector: '[docsSearchItem]',
host: {
'[class.active]': 'isActive',
},
})
export class SearchItem implements Highlightable {
@Input() item?: SearchResult;
@Input() disabled = false;
private readonly elementRef = inject(ElementRef<HTMLLIElement>);
private _isActive = signal(false);
protected get isActive() {
return this._isActive();
}
setActiveStyles(): void {
this._isActive.set(true);
}
setInactiveStyles(): void {
this._isActive.set(false);
}
getLabel(): string {
if (!this.item?.hierarchy) {
return '';
}
const {hierarchy} = this.item;
return `${hierarchy.lvl0}${hierarchy.lvl1}${hierarchy.lvl2}`;
}
scrollIntoView(): void {
this.elementRef?.nativeElement.scrollIntoView({block: 'nearest'});
}
}