Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sequential-links): add sequential links component #18

Merged
merged 4 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions packages/sdg/src/lib/sequential-links/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './sequential-links.component';
export * from './sequential-links.interface';
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<div class="container">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Est-ce qu'on pourrait utiliser le host comme container, au lieu d'ajouter un div?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pas certain de comprendre ce que tu veux dire? Ça serait <sdg-sequential-links> qui contiendrait direct les deux et faire le scss de cet élément dans la démo?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On ajoute parfois un div intermédiaire entre le host et le contenu de la composante pour ajouté du style ou des classes. Par exemple, ton <div class="container"> ce situe entre le deux, il est utilisé seulement pour ajouté une classe mais ce style ou cette classe pourrait se retrouver sur le host de la composante.

On peut styler le host de la composante via le fichier SCSS et la balise :host {}
ou
Ajouter un HostBinding @HostBinding('class.container') containerClass = true; qui permet d'ajouter la classe container <sdg-sequential-links class="container">

@if (previous()) {
<div class="link" (click)="goToLink(previous()!.url)">

Check warning on line 3 in packages/sdg/src/lib/sequential-links/sequential-links.component.html

View workflow job for this annotation

GitHub Actions / build

click must be accompanied by either keyup, keydown or keypress event for accessibility

Check warning on line 3 in packages/sdg/src/lib/sequential-links/sequential-links.component.html

View workflow job for this annotation

GitHub Actions / build

Elements with interaction handlers must be focusable
<mat-icon class="arrow">arrow_left_alt</mat-icon>
<div class="content">
<p><b>Précédent</b></p>
<p class="text">{{ previous()?.text }}</p>
</div>
</div>
}
@if (next()) {
<div class="link" (click)="goToLink(next()!.url)">

Check warning on line 12 in packages/sdg/src/lib/sequential-links/sequential-links.component.html

View workflow job for this annotation

GitHub Actions / build

click must be accompanied by either keyup, keydown or keypress event for accessibility
<mat-icon class="arrow">arrow_right_alt</mat-icon>
<div class="content">
<p><b>Suivant</b></p>
<p class="text">{{ next()?.text }}</p>
</div>
</div>
}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
@use 'sass:map';
@use '../core/theme/colors';

.container {
display: flex;
flex-flow: column;
min-height: 88px;
}

.arrow {
font-variation-settings: 'wght' 350;
}

.link {
display: flex;
padding: 16px 16px 16px 8px;
column-gap: 8px;
border-top: 1px solid colors.$grey-light;
cursor: pointer;

&:hover {
background-color: colors.$grey-pale;

.text {
text-decoration: underline;
}
}

&:focus {
outline: solid 2px colors.$blue-light;
outline-offset: 0;
}

&:last-of-type {
border-bottom: 1px solid colors.$grey-light;
}
}

.content {
display: flex;
flex-flow: column;
row-gap: 8px;
}

.text {
color: colors.$blue-piv;
}

p {
margin: 0px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { TEST_CONFIG } from '../../test-config';
import { SequentialLinksComponent } from './sequential-links.component';

describe('SequentialLinksComponent', () => {
let component: SequentialLinksComponent;
let fixture: ComponentFixture<SequentialLinksComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [SequentialLinksComponent],
providers: [...TEST_CONFIG.providers!]
}).compileComponents();

fixture = TestBed.createComponent(SequentialLinksComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { NgFor, NgIf } from '@angular/common';
import { ChangeDetectionStrategy, Component, input } from '@angular/core';
import { MatIconModule } from '@angular/material/icon';
import { ActivatedRoute, Router, RouterLink } from '@angular/router';

import { SequentialLink } from './sequential-links.interface';

@Component({
selector: 'sdg-sequential-links',
standalone: true,
imports: [NgIf, NgFor, MatIconModule, RouterLink],
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: './sequential-links.component.html',
styleUrls: ['./sequential-links.component.scss']
})
export class SequentialLinksComponent {
constructor(
private router: Router,
private activatedRoute: ActivatedRoute
) {}

previous = input<SequentialLink>();
next = input<SequentialLink>();
isHandset = input<boolean>();

goToLink(url: string) {
console.log(url);
this.router.navigate(['../', url], { relativeTo: this.activatedRoute });
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface SequentialLink {
text: string;
url: string;
}
1 change: 1 addition & 0 deletions packages/sdg/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './lib/alert';
export * from './lib/notice';
export * from './lib/tile';
export * from './lib/consult';
export * from './lib/sequential-links';
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<p>
<span
>Les <b>liens séquentiels</b> sont des liens permettant de naviguer vers une
page de contenu suivante ou précédente. Pour plus d'information, voir les
</span>
<span
><app-external-link
title="Liens séquentiels"
link="https://design.quebec.ca/design/composants/navigation/liens-sequentiels"
/></span>
<span>du Système de design gouvernemental.</span>
</p>

<app-example-viewer
title="Liens séquentiels"
configFolder="sequential-links"
codeFolder="sequential-links"
>
<sdg-sequential-links
[previous]="previous"
[next]="next"
[isHandset]="isHandset()"
></sdg-sequential-links>
</app-example-viewer>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { TEST_CONFIG } from 'projects/demo/src/test-config';

import { SequentialLinksDemoComponent } from './sequential-links.component';

describe('SequentialLinksDemoComponent', () => {
let component: SequentialLinksDemoComponent;
let fixture: ComponentFixture<SequentialLinksDemoComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [SequentialLinksDemoComponent],
providers: [...TEST_CONFIG.providers!]
}).compileComponents();

fixture = TestBed.createComponent(SequentialLinksDemoComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Component, Signal } from '@angular/core';

import { NoticeComponent, SequentialLink } from '@igo2/sdg';

import { SequentialLinksComponent } from '../../../../../../../../packages/sdg/src/lib/sequential-links/sequential-links.component';
import { AppService } from '../../../../app.service';
import { ExampleViewerComponent } from '../../../../components/example-viewer/example-viewer.component';
import { ExternalLinkComponent } from '../../../../components/external-link/external-link.component';

@Component({
selector: 'app-sequential-links',
standalone: true,
imports: [
ExampleViewerComponent,
ExternalLinkComponent,
NoticeComponent,
SequentialLinksComponent
],
templateUrl: './sequential-links.component.html',
styleUrl: './sequential-links.component.scss'
})
export class SequentialLinksDemoComponent {
constructor(private appService: AppService) {}

previous: SequentialLink = {
text: "Fil d'Ariane",
url: 'fil-ariane'
};

next: SequentialLink = {
text: 'Tuile',
url: 'tuile'
};

get isHandset(): Signal<boolean> {
return this.appService.isHandset;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ export const routes: INavigationRoutes = [
(m) => m.BreadcrumbDemoComponent
)
},
{
path: 'liens-sequentiels',
title: 'Liens séquentiels',
loadComponent: () =>
import('./sequential-links/sequential-links.component').then(
(m) => m.SequentialLinksDemoComponent
)
},
{
path: 'tuile',
title: 'Tuile',
Expand Down
Loading