File tree Expand file tree Collapse file tree 8 files changed +109
-0
lines changed Expand file tree Collapse file tree 8 files changed +109
-0
lines changed Original file line number Diff line number Diff line change 1212@use ' ./app/shared/footer/footer-theme' ;
1313@use ' ./app/shared/navbar/navbar-theme' ;
1414@use ' ./app/shared/table-of-contents/table-of-contents-theme' ;
15+ @use ' ./app/shared/cookie-popup/cookie-popup-theme' ;
1516@use ' ./styles/api-theme' ;
1617@use ' ./styles/markdown-theme' ;
1718@use ' ./styles/svg-theme' ;
7071 @include not-found-theme .theme ($theme );
7172 @include navbar-theme .theme ($theme );
7273 @include table-of-contents-theme .theme ($theme );
74+ @include cookie-popup-theme .theme ($theme );
7375}
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import {RouterModule} from '@angular/router';
77import { MaterialDocsApp } from './material-docs-app' ;
88import { MATERIAL_DOCS_ROUTES } from './routes' ;
99import { NavBarModule } from './shared/navbar' ;
10+ import { CookiePopupModule } from './shared/cookie-popup/cookie-popup-module' ;
1011
1112@NgModule ( {
1213 imports : [
@@ -18,6 +19,7 @@ import {NavBarModule} from './shared/navbar';
1819 relativeLinkResolution : 'corrected'
1920 } ) ,
2021 NavBarModule ,
22+ CookiePopupModule ,
2123 ] ,
2224 declarations : [ MaterialDocsApp ] ,
2325 providers : [ { provide : LocationStrategy , useClass : PathLocationStrategy } ] ,
Original file line number Diff line number Diff line change 1+ < app-cookie-popup > </ app-cookie-popup >
12< app-navbar class ="mat-elevation-z6 "> </ app-navbar >
23< router-outlet > </ router-outlet >
Original file line number Diff line number Diff line change 1+ @use ' sass:map' ;
2+ @use ' ~@angular/material' as mat ;
3+
4+ @mixin theme ($theme ) {
5+ $primary : map .get ($theme , primary );
6+ $accent : map .get ($theme , accent );
7+ $warn : map .get ($theme , warn );
8+ $background : map .get ($theme , background );
9+ $foreground : map .get ($theme , foreground );
10+ $is-dark-theme : map .get ($theme , is-dark );
11+
12+ app-cookie-popup {
13+ .popup {
14+ color : if ($is-dark-theme ,
15+ map .get (map .get (mat .$grey-palette , contrast ), 50 ),
16+ map .get (mat .$dark-theme-foreground-palette , secondary-text )
17+ );
18+ background : if ($is-dark-theme , map .get (mat .$grey-palette , 50 ), #252525 );
19+ }
20+ }
21+ }
Original file line number Diff line number Diff line change 1+ import { NgModule } from '@angular/core' ;
2+ import { CommonModule } from '@angular/common' ;
3+ import { MatButtonModule } from '@angular/material/button' ;
4+ import { CookiePopup } from './cookie-popup' ;
5+
6+ @NgModule ( {
7+ imports : [ CommonModule , MatButtonModule ] ,
8+ declarations : [ CookiePopup ] ,
9+ exports : [ CookiePopup ]
10+ } )
11+ export class CookiePopupModule { }
Original file line number Diff line number Diff line change 1+ < div class ="popup " *ngIf ="!hasAccepted ">
2+ This site uses cookies from Google to deliver its services and to analyze traffic.
3+
4+ < div class ="buttons ">
5+ < a
6+ href ="https://policies.google.com/technologies/cookies "
7+ mat-button
8+ color ="accent "
9+ target ="_blank "
10+ rel ="noopener "> More details</ a >
11+ < button mat-button color ="accent " (click) ="accept() "> Ok, Got it</ button >
12+ </ div >
13+ </ div >
Original file line number Diff line number Diff line change 1+ @use ' ~@angular/cdk' as cdk ;
2+ @use ' ~@angular/material' as mat ;
3+
4+ $_inner-spacing : 16px ;
5+
6+ .popup {
7+ @include mat .elevation (6 );
8+ position : fixed ;
9+ bottom : 0 ;
10+ left : 0 ;
11+ margin : 24px ;
12+ max-width : 430px ;
13+ z-index : cdk .$overlay-container-z-index + 1 ;
14+ padding : $_inner-spacing $_inner-spacing $_inner-spacing / 2 ;
15+ border-radius : 4px ;
16+ }
17+
18+ .buttons {
19+ display : flex ;
20+ justify-content : flex-end ;
21+ margin : $_inner-spacing $_inner-spacing / -2 0 0 ;
22+
23+ .mat-button {
24+ text-transform : uppercase ;
25+ }
26+ }
Original file line number Diff line number Diff line change 1+ import { ChangeDetectionStrategy , Component } from '@angular/core' ;
2+
3+ const STORAGE_KEY = 'docs-cookies' ;
4+
5+ @Component ( {
6+ selector : 'app-cookie-popup' ,
7+ templateUrl : './cookie-popup.html' ,
8+ styleUrls : [ './cookie-popup.scss' ] ,
9+ changeDetection : ChangeDetectionStrategy . OnPush
10+ } )
11+ export class CookiePopup {
12+ /** Whether the user has accepted the cookie disclaimer. */
13+ hasAccepted : boolean ;
14+
15+ constructor ( ) {
16+ // Needs to be in a try/catch, because some browsers will
17+ // throw when using `localStorage` in private mode.
18+ try {
19+ this . hasAccepted = localStorage . getItem ( STORAGE_KEY ) === 'true' ;
20+ } catch {
21+ this . hasAccepted = false ;
22+ }
23+ }
24+
25+ /** Accepts the cookie disclaimer. */
26+ accept ( ) {
27+ try {
28+ localStorage . setItem ( STORAGE_KEY , 'true' ) ;
29+ } catch { }
30+
31+ this . hasAccepted = true ;
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments