-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Cezar Sampaio
committed
May 22, 2020
1 parent
77a6335
commit f30ef29
Showing
3 changed files
with
77 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import styled from '@emotion/styled'; | ||
import WhiteContainer from './white-container'; | ||
|
||
const Banner = styled(WhiteContainer)` | ||
position: fixed; | ||
bottom: 20px; | ||
left: 15%; | ||
right: 15%; | ||
z-index: 9999; | ||
display: grid; | ||
grid-template-columns: 1fr auto; | ||
column-gap: 20px; | ||
padding: 30px; | ||
align-items: center; | ||
@media screen and (max-width: 768px) { | ||
display: block; | ||
left: 10px; | ||
right: 10px; | ||
padding: 20px 25px; | ||
} | ||
`; | ||
|
||
const Text = styled.p` | ||
margin: 0; | ||
`; | ||
|
||
const Button = styled.button` | ||
display: inline-block; | ||
padding: 7px 15px; | ||
color: #3072be; | ||
border: 0; | ||
background: none; | ||
cursor: pointer; | ||
@media screen and (max-width: 768px) { | ||
display: block; | ||
margin-top: 20px; | ||
padding: 7px 0; | ||
text-align: left; | ||
} | ||
`; | ||
|
||
export default function CookieConsent() { | ||
const [hasAgreed, setHasAgreed] = useState( | ||
localStorage.getItem('cookie-consent') === 'yes' | ||
); | ||
|
||
function handleOnClick(event) { | ||
event.preventDefault(); | ||
|
||
setHasAgreed(true); | ||
localStorage.setItem('cookie-consent', 'yes'); | ||
} | ||
|
||
if (hasAgreed) return null; | ||
|
||
return ( | ||
<Banner> | ||
<Text> | ||
This website may store data such as cookies to enable analytics | ||
functionalities. | ||
</Text> | ||
<Button onClick={handleOnClick}>Accept and close</Button> | ||
</Banner> | ||
); | ||
} |
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