@engie-group/fluid-design-system-angular
Version:
Fluid Design System Angular
155 lines (128 loc) • 2.96 kB
text/typescript
import {CommonModule} from '@angular/common';
import {
Attribute,
ChangeDetectionStrategy,
Component,
HostBinding,
inject,
Input,
ViewEncapsulation
} from '@angular/core';
import {RouterLink} from '@angular/router';
import {IconComponent} from '../icon/icon.component';
import {LinkIconPosition, LinkSize, LinkVariant} from './link.model';
export class LinkComponent {
get tabIndex() {
return this.tabIndexAttribute ?? (this.routerLink ? '-1' : undefined);
}
private linkClass = 'nj-link';
private iconClass = 'nj-link-icon';
/**
* Link variant theme
*/
variant: LinkVariant = 'default';
/**
* Link size
*/
size: LinkSize;
/**
* Link target. Note when the target is `_blank`, an icon notifying the user is placed on the right of the link
*/
target: string;
/**
* Link href
*/
href: string;
/**
* Link rel
*/
rel: string;
/**
* If link opens in a new page, an icon notifying the user is placed on the right of the link
*/
isExternal = false;
externalLabel: string;
/**
* Whether link has icon
*/
hasIcon = false;
/**
* Link material icon
*/
icon: string;
/**
* Whether icon is before or after text
*/
iconPosition: LinkIconPosition = 'after';
/**
* Link title
*/
title: string;
/**
* Link id
*/
id: string;
/**
* Aria label, for accessibility reasons
*/
ariaLabel: string;
/**
* Aria labelled by, for accessibility reasons
*/
ariaLabelledBy: string;
protected readonly routerLink? = inject(RouterLink, {self: true, optional: true});
constructor( private readonly tabIndexAttribute: string|null|undefined) {
}
/**
* @ignore
*/
isExternalLink(): boolean {
return this.isExternal || this.target === '_blank';
}
/**
* @ignore
*/
getLinkVariantClass(): string {
if (!this.variant || this.variant === 'default') {
return '';
}
return `${this.linkClass}--${this.variant}`;
}
/**
* @ignore
*/
getIconClass(): string {
if (!this.hasIcon && !this.isExternalLink()) {
return '';
}
return this.iconClass;
}
/**
* @ignore
*/
getIconPositionClass(): string {
if (this.iconPosition !== 'before') {
return '';
}
return `${this.iconClass}--${this.iconPosition}`;
}
/**
* @ignore
*/
getSizeClass(): string {
if (!this.size) {
return '';
}
return `${this.linkClass}--${this.size}`;
}
}