-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Accept cookies banner with link to privacy page. #103.
- Loading branch information
Fran McDade
authored and
Fran McDade
committed
Jul 19, 2021
1 parent
e2c252b
commit 10922b9
Showing
6 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* JXTX Foundation | ||
* https://www.jxtxfoundation.org | ||
* | ||
* JXTX cookies banner component. | ||
*/ | ||
|
||
// Core dependencies | ||
import Link from "gatsby-link"; | ||
import Cookies from "js-cookie"; | ||
import React, { useEffect, useState } from "react"; | ||
|
||
// App dependencies | ||
import Button from "../button/button"; | ||
import { ButtonType } from "../button/button-type.model"; | ||
|
||
// Styles | ||
import * as compStyles from "./banner-cookies.module.css"; | ||
|
||
function BannerCookies() { | ||
const [showBanner, setShowBanner] = useState(false); | ||
|
||
/** | ||
* Sets cookie and closes banner. | ||
*/ | ||
const closeBanner = () => { | ||
/* Set cookie and hide banner. */ | ||
Cookies.set("cookiesAccepted", true, { expires: new Date(2300, 1, 1) }); | ||
setShowBanner(false); | ||
}; | ||
|
||
/* useEffect - componentDidMount/componentWillUnmount. */ | ||
useEffect(() => { | ||
/* Grab the cookie "cookiesAccepted". */ | ||
const cookie = Cookies.get("cookiesAccepted"); | ||
|
||
/* Show the banner if the cookie has not been accepted. */ | ||
if (cookie === undefined) { | ||
setShowBanner(true); | ||
} | ||
|
||
/* Hide the banner if the cookie has been accepted. */ | ||
if (Cookies.get("cookiesAccepted") === true) { | ||
setShowBanner(false); | ||
} | ||
}, []); | ||
|
||
return showBanner ? ( | ||
<div className={compStyles.banner}> | ||
<p className={compStyles.banner__text}> | ||
This website uses cookies for security and analytics purposes. By using | ||
this site, you agree to these uses.{" "} | ||
<Link className={compStyles.banner__link} to={"/privacy"}> | ||
Learn more here. | ||
</Link> | ||
</p> | ||
<Button buttonAction={() => closeBanner()} buttonType={ButtonType.TEXT}> | ||
Ok | ||
</Button> | ||
</div> | ||
) : null; | ||
} | ||
|
||
export default BannerCookies; |
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,51 @@ | ||
/* | ||
* JXTX Foundation | ||
* https://www.jxtxfoundation.org | ||
* | ||
* Style definitions specific to JXTX banner cookies component. | ||
*/ | ||
|
||
/* Banner. */ | ||
.banner { | ||
align-items: flex-start; | ||
background-color: var(--accent-pink); | ||
bottom: 0; | ||
display: flex; | ||
flex-direction: column; | ||
left: 0; | ||
margin: 0 auto; | ||
max-width: var(--maximum); | ||
padding: 40px; | ||
position: sticky; | ||
width: 100vw; | ||
z-index: 10; | ||
} | ||
|
||
/* Banner text. */ | ||
.banner__text { | ||
margin: 0; | ||
padding: 20px 0; | ||
} | ||
|
||
/* Banner link. */ | ||
.banner__link { | ||
color: inherit; | ||
white-space: nowrap; | ||
} | ||
|
||
/** | ||
* 1240px - Medium (laptop). | ||
*/ | ||
@media screen and (min-width: 1240px) { | ||
/* Banner. */ | ||
.banner { | ||
align-items: center; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
} | ||
|
||
/* Banner text. */ | ||
.banner__text { | ||
margin-right: var(--vu___60); | ||
} | ||
} |
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