/*
* Deepkit Framework
* Copyright (C) 2021 Deepkit UG, Marc J. Schmidt
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the MIT License.
*
* You should have received a copy of the MIT License along with this program.
*/
import { ChangeDetectionStrategy, Component, HostListener, booleanAttribute, inject, input } from '@angular/core';
import { RouterLinkActive } from '@angular/router';
import { ValueAccessorBase, ngValueAccessor } from '../../core/form';
@Component({
selector: 'dui-tab-button',
template: ` `,
host: {
'[attr.tabindex]': '1',
'[class.active]': 'isActive()',
},
styleUrls: ['./tab-button.component.scss'],
hostDirectives: [{ directive: RouterLinkActive, inputs: ['routerLinkActiveOptions'] }],
changeDetection: ChangeDetectionStrategy.Eager,
providers: [ngValueAccessor(TabButtonComponent)],
})
export class TabButtonComponent extends ValueAccessorBase {
/**
* Whether the button is active (pressed).
*
* Use alternatively form API, e.g.
*/
active = input(false, { transform: booleanAttribute });
routerLinkActive = inject(RouterLinkActive);
@HostListener('click')
protected onClick() {
const value = this.value();
if (value === undefined) return;
this.setValue(value);
}
protected isActive() {
return this.routerLinkActive.isActive || this.active();
}
}