Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit 82b0fe3

Browse files
committed
ajout des composants drawer et backdrop
1 parent 6ad7f19 commit 82b0fe3

File tree

5 files changed

+136
-2
lines changed

5 files changed

+136
-2
lines changed

src/app/shared/components/buttons/primary.component.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { Observable } from 'rxjs';
77
<button
88
[type]="type"
99
[disabled]="loading$ | async"
10-
class="relative inline-flex items-center px-4 py-2 text-sm font-medium text-white bg-primary-600 border border-transparent rounded-md shadow-md hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500 disabled:opacity-50 disabled:cursor-not-allowed transition ease-in-out duration-150"
11-
[ngClass]="class"
10+
class="relative inline-flex items-center px-4 py-2 text-sm font-medium text-white border border-transparent rounded-md shadow-md focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed transition ease-in-out duration-150"
11+
[ngClass]="class + this.themeClass()"
1212
matRipple
1313
matRippleColor="primary">
1414
<span *ngIf="loading$ | async">
@@ -39,4 +39,21 @@ export class ButtonPrimaryComponent {
3939
@Input() loading$!: Observable<boolean>;
4040

4141
@Input() class!: string;
42+
43+
@Input() theme: string = 'primary';
44+
45+
public themeClass(theme: string): string {
46+
switch (theme) {
47+
case 'primary':
48+
return 'bg-primary-600 hover:bg-primary-700 focus:ring-primary-500';
49+
case 'secondary':
50+
return 'bg-secondary-600 hover:bg-secondary-700 focus:ring-secondary-500';
51+
case 'success':
52+
return 'bg-green-600 hover:bg-green-700 focus:ring-green-500';
53+
case 'danger':
54+
return 'bg-red-600 hover:bg-red-700 focus:ring-red-500';
55+
default:
56+
return 'bg-transparent hover:bg-slate-50 focus:ring-slate-900';
57+
}
58+
}
4259
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'drawer-button',
5+
template: `
6+
<button type="button" class="inline-flex items-center text-sm leading-5">
7+
<ng-content></ng-content>
8+
</button>
9+
`,
10+
})
11+
export class ButtonDrawerComponent {}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<cosna-drawer-button (click)="open()">
2+
<ng-content select="[slot=button]"></ng-content>
3+
</cosna-drawer-button>
4+
5+
<mat-sidenav-container
6+
getElementRef
7+
hasBackdrop="true"
8+
(backdropClick)="sidenav.close()"
9+
>
10+
<mat-sidenav
11+
fixedBottomGap="10"
12+
position="end"
13+
mode="over"
14+
#sidenav
15+
disableClose
16+
[ngClass]="class"
17+
[(opened)]="opened"
18+
>
19+
<div class="flex flex-col h-full py-6 overflow-y-scroll bg-white shadow-xl">
20+
<div class="px-4 sm:px-6">
21+
<div class="flex items-start justify-between">
22+
<h2 class="text-lg font-medium text-slate-900" id="slide-over-title">{{ title }}</h2>
23+
<div class="flex items-center ml-3 h-7">
24+
<button (click)="sidenav.close()" type="button" class="bg-white rounded-md text-slate-400 hover:text-slate-500 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2">
25+
<span class="sr-only">Close panel</span>
26+
<svg class="w-6 h-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true">
27+
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12"/>
28+
</svg>
29+
</button>
30+
</div>
31+
</div>
32+
</div>
33+
<div class="relative flex-1 px-4 mt-6 sm:px-6">
34+
<ng-content></ng-content>
35+
</div>
36+
</div>
37+
</mat-sidenav>
38+
</mat-sidenav-container>
39+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {
2+
Component,
3+
EventEmitter,
4+
Input,
5+
Output,
6+
ViewChild,
7+
} from '@angular/core';
8+
import { MatSidenav } from '@angular/material/sidenav';
9+
10+
@Component({
11+
selector: 'simple-drawer',
12+
templateUrl: './simple-drawer.component.html',
13+
})
14+
export class SimpleDrawerComponent {
15+
@ViewChild('sidenav') sidenav!: MatSidenav;
16+
17+
@Input() title!: string;
18+
19+
@Input() class!: string;
20+
21+
@Input() value?: any;
22+
23+
@Output() dispatchOnLoad: EventEmitter<any> = new EventEmitter<any>();
24+
25+
opened: boolean = false;
26+
27+
public open() {
28+
this.sidenav.open();
29+
30+
if (this.value) {
31+
this.dispatchOnLoad.emit(this.value);
32+
}
33+
}
34+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Component, Input } from '@angular/core';
2+
import { Observable } from 'rxjs';
3+
4+
@Component({
5+
selector: 'backdrop-loader',
6+
template: `
7+
<div
8+
*ngIf="loading$ | async"
9+
class="absolute inset-0 z-50 flex items-center justify-center rounded-lg backdrop-blur-sm bg-white/30">
10+
<span>
11+
<svg
12+
class="w-5 h-5 mr-3 -ml-1 text-primary-500 animate-spin"
13+
fill="none"
14+
viewBox="0 0 24 24">
15+
<circle
16+
class="opacity-25"
17+
cx="12"
18+
cy="12"
19+
r="10"
20+
stroke="currentColor"
21+
stroke-width="4" />
22+
<path
23+
class="opacity-75"
24+
fill="currentColor"
25+
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" />
26+
</svg>
27+
</span>
28+
</div>
29+
`,
30+
})
31+
export class BackdropLoaderComponent {
32+
@Input() loading$!: Observable<boolean>;
33+
}

0 commit comments

Comments
 (0)