-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #399 from newrelic/tg/cookies-dialog
feat: Add cookies dialog
- Loading branch information
Showing
8 changed files
with
256 additions
and
49 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
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,81 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Cookies from 'js-cookie'; | ||
import Button from './Button'; | ||
import cx from 'classnames'; | ||
import styles from './CookieApprovalDialog.module.scss'; | ||
import ExternalLink from './ExternalLink'; | ||
|
||
const gdprConsentCookieName = 'newrelic-gdpr-consent'; | ||
|
||
const CookieApprovalDialog = ({ className, setCookieConsent }) => { | ||
const [isCookieSet, setIsCookieSet] = useState(true); | ||
|
||
useEffect(() => { | ||
setIsCookieSet(Cookies.get(gdprConsentCookieName) !== undefined); | ||
}, []); | ||
|
||
function writeCookie(answer) { | ||
const currentEnvironment = | ||
process.env.ENV || process.env.NODE_ENV || 'development'; | ||
const options = { expires: 365 /* days */ }; | ||
if (currentEnvironment !== 'development') { | ||
options.domain = 'newrelic.com'; | ||
} | ||
|
||
Cookies.set(gdprConsentCookieName, String(!!answer), options); | ||
setIsCookieSet(true); | ||
answer && setCookieConsent(true); | ||
} | ||
|
||
if (isCookieSet) { | ||
return null; | ||
} | ||
return ( | ||
<div className={cx(styles.container, className)}> | ||
<div className={styles.content}> | ||
<div className={styles.primaryContent}> | ||
<h4 className={styles.heading}> | ||
This site uses cookies{' '} | ||
<span role="img" aria-label="Cookie emoji"> | ||
🍪 | ||
</span> | ||
</h4> | ||
<p className={styles.description}> | ||
We use cookies and other similar technologies ("Cookies") on our | ||
websites and services to enhance your experience and to provide you | ||
with relevant content. By using our websites and services you are | ||
agreeing to the use of cookies. You can read more{' '} | ||
<ExternalLink href="https://newrelic.com/termsandconditions/cookie-policy"> | ||
here | ||
</ExternalLink> | ||
. If you consent to our cookies, please click <strong>Yes</strong>. | ||
</p> | ||
</div> | ||
<div className={styles.buttonsContainer}> | ||
<Button | ||
className={styles.approveButton} | ||
variant={Button.VARIANT.PRIMARY} | ||
onClick={() => writeCookie(true)} | ||
> | ||
Yes | ||
</Button> | ||
<Button | ||
className={styles.rejectButton} | ||
variant={Button.VARIANT.NORMAL} | ||
onClick={() => writeCookie(false)} | ||
> | ||
No | ||
</Button> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
CookieApprovalDialog.propTypes = { | ||
className: PropTypes.string, | ||
setCookieConsent: PropTypes.func, | ||
}; | ||
|
||
export default CookieApprovalDialog; |
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,105 @@ | ||
.container { | ||
width: 100%; | ||
position: fixed; | ||
bottom: 0; | ||
z-index: 10000; | ||
background-color: rgba(28, 42, 47, 0.92); | ||
box-shadow: 0px -0.249053px 4.26158px rgba(12, 48, 57, 0.0421718), | ||
0px -0.598509px 10.2412px rgba(12, 48, 57, 0.0605839), | ||
0px -1.12694px 19.2832px rgba(12, 48, 57, 0.075), | ||
0px -2.01027px 34.3979px rgba(12, 48, 57, 0.0894161), | ||
0px -3.75998px 64.3375px rgba(12, 48, 57, 0.107828), | ||
0px -9px 154px rgba(12, 48, 57, 0.15); | ||
backdrop-filter: blur(5px); | ||
} | ||
|
||
.content { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
width: 1180px; | ||
margin: 0 auto; | ||
box-sizing: border-box; | ||
padding: 1.125rem 0; | ||
} | ||
|
||
.heading { | ||
color: #fff; | ||
margin-top: 0; | ||
margin-bottom: 2px; | ||
line-height: 21px; | ||
} | ||
|
||
.description { | ||
margin: 0 0 0px; | ||
font-size: 13px; | ||
line-height: 21px; | ||
color: var(--accent-text-color); | ||
} | ||
|
||
.buttonsContainer { | ||
margin-left: 1rem; | ||
flex-shrink: 0; | ||
} | ||
|
||
.approveButton { | ||
margin-right: 10px; | ||
padding: 0.625rem 1.75rem; | ||
} | ||
|
||
.rejectButton { | ||
padding: 0.625rem 1rem; | ||
} | ||
|
||
// ============================================================== | ||
// Responsive styles | ||
// ============================================================== | ||
@media screen and (max-width: 1200px) { | ||
.content { | ||
width: 100%; | ||
padding: 1.125rem 1.75rem; | ||
} | ||
|
||
.heading { | ||
margin-bottom: 0.375rem; | ||
} | ||
|
||
.description { | ||
line-height: 19px; | ||
} | ||
} | ||
|
||
@media screen and (max-width: 480px) { | ||
.content { | ||
flex-direction: column; | ||
align-items: flex-start; | ||
} | ||
|
||
.description { | ||
margin-bottom: 1rem; | ||
} | ||
|
||
.cta-container { | ||
margin: 0; | ||
} | ||
|
||
.approveButton { | ||
padding-top: 0.5rem; | ||
padding-bottom: 0.5rem; | ||
} | ||
|
||
.rejectButton { | ||
padding-top: 0.5rem; | ||
padding-bottom: 0.5rem; | ||
} | ||
} | ||
|
||
// ============================================================== | ||
// Dark mode | ||
// ============================================================== | ||
:global(.dark-mode) { | ||
.container { | ||
background-color: rgba(15, 25, 28, 0.92); | ||
box-shadow: 0 -1px 0 rgba(55, 72, 78, 0.4); | ||
} | ||
} |
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