-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Due to legal requirements we have to have a cookie disclaimer popup. It is always shown until the user agrees to it. After the user has agreed, the popup won't be shown on subsequent sessions. Fixes #22746.
- Loading branch information
Showing
8 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
<app-cookie-popup></app-cookie-popup> | ||
<app-navbar class="mat-elevation-z6"></app-navbar> | ||
<router-outlet></router-outlet> |
21 changes: 21 additions & 0 deletions
21
material.angular.io/src/app/shared/cookie-popup/_cookie-popup-theme.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
@use 'sass:map'; | ||
@use '~@angular/material' as mat; | ||
|
||
@mixin theme($theme) { | ||
$primary: map.get($theme, primary); | ||
$accent: map.get($theme, accent); | ||
$warn: map.get($theme, warn); | ||
$background: map.get($theme, background); | ||
$foreground: map.get($theme, foreground); | ||
$is-dark-theme: map.get($theme, is-dark); | ||
|
||
app-cookie-popup { | ||
.popup { | ||
color: if($is-dark-theme, | ||
map.get(map.get(mat.$grey-palette, contrast), 50), | ||
map.get(mat.$dark-theme-foreground-palette, secondary-text) | ||
); | ||
background: if($is-dark-theme, map.get(mat.$grey-palette, 50), #252525); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
material.angular.io/src/app/shared/cookie-popup/cookie-popup-module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {NgModule} from '@angular/core'; | ||
import {CommonModule} from '@angular/common'; | ||
import {MatButtonModule} from '@angular/material/button'; | ||
import {CookiePopup} from './cookie-popup'; | ||
|
||
@NgModule({ | ||
imports: [CommonModule, MatButtonModule], | ||
declarations: [CookiePopup], | ||
exports: [CookiePopup] | ||
}) | ||
export class CookiePopupModule {} |
13 changes: 13 additions & 0 deletions
13
material.angular.io/src/app/shared/cookie-popup/cookie-popup.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div class="popup" *ngIf="!hasAccepted"> | ||
This site uses cookies from Google to deliver its services and to analyze traffic. | ||
|
||
<div class="buttons"> | ||
<a | ||
href="https://policies.google.com/technologies/cookies" | ||
mat-button | ||
color="accent" | ||
target="_blank" | ||
rel="noopener">More details</a> | ||
<button mat-button color="accent" (click)="accept()">Ok, Got it</button> | ||
</div> | ||
</div> |
26 changes: 26 additions & 0 deletions
26
material.angular.io/src/app/shared/cookie-popup/cookie-popup.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
@use '~@angular/cdk' as cdk; | ||
@use '~@angular/material' as mat; | ||
|
||
$_inner-spacing: 16px; | ||
|
||
.popup { | ||
@include mat.elevation(6); | ||
position: fixed; | ||
bottom: 0; | ||
left: 0; | ||
margin: 24px; | ||
max-width: 430px; | ||
z-index: cdk.$overlay-container-z-index + 1; | ||
padding: $_inner-spacing $_inner-spacing $_inner-spacing / 2; | ||
border-radius: 4px; | ||
} | ||
|
||
.buttons { | ||
display: flex; | ||
justify-content: flex-end; | ||
margin: $_inner-spacing $_inner-spacing / -2 0 0; | ||
|
||
.mat-button { | ||
text-transform: uppercase; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
material.angular.io/src/app/shared/cookie-popup/cookie-popup.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import {ChangeDetectionStrategy, Component} from '@angular/core'; | ||
|
||
const STORAGE_KEY = 'docs-cookies'; | ||
|
||
@Component({ | ||
selector: 'app-cookie-popup', | ||
templateUrl: './cookie-popup.html', | ||
styleUrls: ['./cookie-popup.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush | ||
}) | ||
export class CookiePopup { | ||
/** Whether the user has accepted the cookie disclaimer. */ | ||
hasAccepted: boolean; | ||
|
||
constructor() { | ||
// Needs to be in a try/catch, because some browsers will | ||
// throw when using `localStorage` in private mode. | ||
try { | ||
this.hasAccepted = localStorage.getItem(STORAGE_KEY) === 'true'; | ||
} catch { | ||
this.hasAccepted = false; | ||
} | ||
} | ||
|
||
/** Accepts the cookie disclaimer. */ | ||
accept() { | ||
try { | ||
localStorage.setItem(STORAGE_KEY, 'true'); | ||
} catch {} | ||
|
||
this.hasAccepted = true; | ||
} | ||
} |