-
-
Notifications
You must be signed in to change notification settings - Fork 767
/
Copy pathcookie-consent.tsx
81 lines (68 loc) · 1.92 KB
/
cookie-consent.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import React, { FC, useCallback, useEffect, useState } from "react";
import { useCookies } from "react-cookie";
import styled from "styled-components";
import { Dialog, DialogButton, DialogContainer, LearnMoreLink } from "./dialog";
const COOKIE_NAME = "chillicream_website_cookie_consent_shown";
export const CookieConsent: FC = () => {
const [cookies, setCookie] = useCookies([COOKIE_NAME]);
const [show, setShow] = useState(false);
const clickDismiss = useCallback(() => {
const expires = new Date();
expires.setFullYear(expires.getFullYear() + 1);
setCookie(COOKIE_NAME, true, {
path: "/",
expires,
sameSite: "lax",
});
setShow(false);
}, [setCookie, setShow]);
useEffect(() => {
setShow(!cookies[COOKIE_NAME]);
}, [cookies, setShow]);
return show ? (
<Dialog
role="dialog"
aria-live="polite"
aria-label="cookieconsent"
aria-describedby="cookieconsent:desc"
show
>
<Container>
<Message id="cookieconsent:desc">
This website uses cookies to ensure you get the best experience on our
website.{" "}
<LearnMoreLink prefetch={false} to="/legal/cookie-policy.html">
Learn more
</LearnMoreLink>
</Message>
<DialogButton
aria-label="dismiss cookie message"
role="button"
onClick={clickDismiss}
>
Got it!
</DialogButton>
</Container>
</Dialog>
) : null;
};
const Container = styled(DialogContainer)`
justify-content: space-between;
@media only screen and (min-width: 400px) {
flex-direction: row;
${DialogButton} {
flex: 0 0 160px;
}
}
`;
const Message = styled.div`
flex: 0 1 auto;
padding-bottom: 20px;
font-size: var(--font-size);
line-height: 1.667em;
color: #0b0722;
@media only screen and (min-width: 400px) {
padding-bottom: initial;
padding-right: 20px;
}
`;