Skip to content

Commit 4eaa9a8

Browse files
authored
Merge pull request #3 from Babali42/responsive
Responsive et factorisation des liens dans le menu
2 parents 1c23634 + 0ea0105 commit 4eaa9a8

6 files changed

+97
-33
lines changed

package-lock.json

+23-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"private": true,
1212
"dependencies": {
1313
"@angular/animations": "^14.0.0",
14+
"@angular/cdk": "^14.2.7",
1415
"@angular/common": "^14.0.0",
1516
"@angular/compiler": "^14.0.0",
1617
"@angular/core": "^14.0.0",

src/app/app.component.html

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
<div class="flex main-container">
2-
<div class="flex column left-menu">
1+
<div class="main-container" [ngClass]="{'flex': !isMobileDisplay}">
2+
<div class="flex column left-menu" *ngIf="!isMobileDisplay">
33
<div class="header"> DRUMS<br> PATTERN<br> LIBRARY</div>
44
<div class="flex menu">
5-
<a class="button" routerLink="/techno">Techno</a>
6-
<a class="button" routerLink="/drum-n-bass">Drum & Bass</a>
7-
<a class="button" routerLink="/garage">Garage - 2 step</a>
8-
<a class="button" routerLink="/psytrance">Psytrance</a>
9-
<a class="button" routerLink="/metal">Metal</a>
10-
<a class="button" routerLink="/rock">Rock</a>
11-
<a class="button" routerLink="/rock-variation">Rock variation</a>
12-
<a class="button" routerLink="/half-time-groove">Half time groove</a>
5+
<a class="button" [routerLink]="link.link" *ngFor="let link of links">{{ link.label }}</a>
6+
</div>
7+
</div>
8+
<div *ngIf="isMobileDisplay">
9+
<div class="header-mobile">DRUMS PATTERN LIBRARY</div>
10+
<div class="flex mobile-menu">
11+
<a class="item" [routerLink]="link.link" *ngFor="let link of links">{{ link.label }}</a>
1312
</div>
1413
</div>
15-
1614
<div class="content">
1715
<router-outlet></router-outlet>
1816
</div>

src/app/app.component.scss

+28
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,31 @@
2626
.left-menu {
2727
border-right: solid 1px black;
2828
}
29+
30+
.nowrap{
31+
white-space: nowrap;
32+
}
33+
34+
.mobile-menu {
35+
width: 100%;
36+
overflow-x: auto;
37+
gap: 5px;
38+
39+
a {
40+
all: unset;
41+
}
42+
43+
.item{
44+
white-space: nowrap;
45+
background-color: darkgrey;
46+
color: white;
47+
border-radius: 15px;
48+
padding: 10px;
49+
}
50+
}
51+
52+
.header-mobile{
53+
font-size: 30px;
54+
width: 100%;
55+
text-align: center;
56+
}

src/app/app.component.ts

+27-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,34 @@
1-
import { Component } from '@angular/core';
1+
import {Component, OnInit} from '@angular/core';
2+
import {BreakpointObserver, Breakpoints} from '@angular/cdk/layout';
3+
import {Link} from "./models/link";
24

35
@Component({
46
selector: 'app-root',
57
templateUrl: './app.component.html',
68
styleUrls: ['./app.component.scss']
79
})
8-
export class AppComponent {
9-
title = 'DrumsPatternLibrary';
10+
export class AppComponent implements OnInit {
11+
isMobileDisplay: boolean = true;
12+
links: Link[] = [
13+
new Link("Techno", "/techno"),
14+
new Link("Drum & Bass", "/drum-n-bass"),
15+
new Link("Garage - 2 step", "/garage"),
16+
new Link("Psytrance", "/psytrance"),
17+
new Link("Metal", "/metal"),
18+
new Link("Rock", "/rock"),
19+
new Link("Rock variation", "/rock-variation"),
20+
new Link("Half time groove", "/half-time-groove")
21+
]
22+
23+
constructor(private responsive: BreakpointObserver) {
24+
}
25+
26+
ngOnInit(): void {
27+
this.responsive.observe([
28+
Breakpoints.Web,
29+
])
30+
.subscribe(result => {
31+
this.isMobileDisplay = !result.matches;
32+
});
33+
}
1034
}

src/app/models/link.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export class Link {
2+
label: string;
3+
link: string;
4+
5+
constructor(label: string, link: string) {
6+
this.label = label;
7+
this.link = link;
8+
}
9+
}

0 commit comments

Comments
 (0)