Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions projects/canopy-test-app/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<aside lg-card-group lgMarginBottom="xl">
<lg-card>
<lg-card-header>
<lg-card-navigation-title title="The title" link="https://www.landg.com" [headingLevel]="2"></lg-card-navigation-title>
<lg-card-navigation-title title="The title" link="/foo" [headingLevel]="2"></lg-card-navigation-title>
</lg-card-header>
<lg-card-content>
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Expand All @@ -115,7 +115,7 @@
</lg-card>
<lg-card>
<lg-card-header>
<lg-card-navigation-title title="The title" link="https://www.landg.com" headingLevel="2"></lg-card-navigation-title>
<lg-card-navigation-title title="The title" link="/boo" headingLevel="2"></lg-card-navigation-title>
</lg-card-header>
<lg-card-content>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Expand All @@ -131,7 +131,7 @@
</lg-card>
<lg-card>
<lg-card-header>
<lg-card-navigation-title title="The title" link="https://www.landg.com" headingLevel="2"></lg-card-navigation-title>
<lg-card-navigation-title title="The title" link="/test" headingLevel="2"></lg-card-navigation-title>
</lg-card-header>
<lg-card-content>
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<lg-heading [level]="headingLevel" *ngIf="link && title && headingLevel">
<a *ngIf="externalLink" [href]="link" (click)="linkClicked()">
<a *ngIf="externalLink" [href]="link" (click)="linkClicked()" target="_blank">
<ng-container [ngTemplateOutlet]="linkContent"></ng-container>
</a>
<a *ngIf="!externalLink" [routerLink]="[link]" [queryParams]="queryParams" [queryParamsHandling]="queryParamsHandling" (click)="linkClicked()">
Expand All @@ -9,5 +9,5 @@

<ng-template #linkContent>
{{title}}
<lg-icon name="arrow-right"></lg-icon>
<lg-icon [name]="externalLink ? 'link-external' : 'arrow-right'"></lg-icon>
</ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
background: var(--link-color);
border-radius: 50%;
color: var(--color-white);

> svg {
padding: 0.125rem;
}
}

a {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ describe('LgCardNavigationTitleComponent', () => {
});

it('should know whether the link is external or internal', () => {
expect(component.link).toBe('http://www.landg.com');
expect(component['externalLink']).toBeTrue();
let anchorEL = fixture.debugElement.query(By.css('a'));

expect(anchorEL.nativeElement.getAttribute('target')).toBe('_blank');

fixture = MockRender(
`
Expand All @@ -99,6 +103,10 @@ describe('LgCardNavigationTitleComponent', () => {
component = debugElement.children[0].componentInstance;

expect(component['externalLink']).toBeFalse();
expect(component.link).toBe('/test-path');
anchorEL = fixture.debugElement.query(By.css('a'));

expect(anchorEL.nativeElement.getAttribute('target')).toBeNull();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ import {
Component,
EventEmitter,
Input,
OnChanges,
OnInit,
Output,
SimpleChanges,
ViewEncapsulation, OnChanges,
ViewEncapsulation,
} from '@angular/core';
import { Params, QueryParamsHandling, RouterLink } from '@angular/router';
import { NgIf, NgTemplateOutlet } from '@angular/common';

import type { HeadingLevel } from '../../heading';
import { LgHeadingComponent } from '../../heading';
import isExternalURL from '../../utils/external-links';
import { LgIconComponent } from '../../icon';
import isExternalURL from '../../utils/external-links';

@Component({
selector: 'lg-card-navigation-title',
Expand All @@ -38,14 +39,13 @@ export class LgCardNavigationTitleComponent implements OnInit, OnChanges {

ngOnInit(): void {
if (!(this.headingLevel && this.title && this.link)) {

console.error('headingLevel, title and link must be set');
}
}

ngOnChanges({ link }: SimpleChanges): void {
if (link?.currentValue) {
this.externalLink = isExternalURL(link?.currentValue);
this.externalLink = isExternalURL(link?.currentValue as string);
}
}

Expand Down
6 changes: 3 additions & 3 deletions projects/canopy/src/lib/card/docs/card/card.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ const cardGroupTemplate = `
<aside lg-card-group>
<lg-card>
<lg-card-header>
<lg-card-navigation-title title="The title" link="https://www.landg.com"
<lg-card-navigation-title title="Internal link title" link="/foo"
[headingLevel]="2"></lg-card-navigation-title>
</lg-card-header>
<lg-card-content>
Expand All @@ -332,7 +332,7 @@ const cardGroupTemplate = `
</lg-card>
<lg-card *ngFor="let i of [].constructor(additionalCards)">
<lg-card-header>
<lg-card-navigation-title title="The title" link="https://www.landg.com"
<lg-card-navigation-title title="External link title" link="https://www.landg.com"
headingLevel="2"></lg-card-navigation-title>
</lg-card-header>
<lg-card-content>
Expand Down Expand Up @@ -453,7 +453,7 @@ export const DefaultCard = {
export const NavigationCard = {
name: 'Card navigation',
args: {
link: 'https://www.landg.com',
link: '/foo',
queryParams: null,
queryParamsHandling: null,
headingLevel: 2,
Expand Down
1 change: 1 addition & 0 deletions projects/canopy/src/lib/card/docs/card/guide.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ This is where the main title should be provided. It should be located inside the
### LgCardNavigationTitleComponent

This is where the main title and link should be provided. It should be located inside the card content.
The `target` attribute and icon for the link will be automatically determined based on the `link` input.

#### Inputs

Expand Down
Loading