1+ <!-- CookieBanner.vue -->
2+ <template >
3+ <div class =" cookie-banner" >
4+ <!-- Cookie banner content -->
5+ 🍪 Do you want milk with your cookies?
6+ <button @click =" handleConsent" class =" accept-button" >Accept Cookies</button >
7+ <button @click =" handleReject" class =" reject-button" >Reject Cookies</button >
8+
9+ </div >
10+ </template >
11+
12+ <script lang="ts">
13+ import useCookies from ' ../useCookies' ;
14+ import { defineComponent , getCurrentInstance } from ' vue' ;
15+
16+ export default defineComponent ({
17+ setup() {
18+ const instance = getCurrentInstance ();
19+ const gtag = instance ?.appContext .config .globalProperties .$gtag ;
20+
21+ const { allowCookies } = useCookies (gtag );
22+
23+ const handleConsent = () => {
24+ allowCookies .value = true ;
25+ if (gtag ) {
26+ gtag .optIn ();
27+ }
28+ };
29+
30+ const handleReject = () => {
31+ allowCookies .value = false ;
32+ if (gtag ) {
33+ gtag .optOut ();
34+ }
35+ };
36+
37+ return { handleConsent , handleReject };
38+ }
39+ });
40+ </script >
41+
42+ <style scoped>
43+ .cookie-banner {
44+ position : fixed ;
45+ left : 0 ;
46+ right : 0 ;
47+ bottom : 0 ;
48+ background-color : #fff ; /* Or any color you prefer */
49+ color : #000 ;
50+ padding : 8px ;
51+ box-shadow : 0px -2px 10px rgba (0 , 0 , 0 , 0.1 );
52+ animation : slideUp 0.5s ease-out ;
53+
54+ /* Artistic Border */
55+ border : 2px solid #000 ; /* Basic solid border, change as needed */
56+ border-radius : 10px ; /* Rounded corners */
57+ /* You can add more artistic styles like border-image or box-shadow for more effects */
58+
59+ }
60+
61+ @keyframes slideUp {
62+ from {
63+ transform : translateY (100% );
64+ }
65+ to {
66+ transform : translateY (0 );
67+ }
68+ }
69+
70+ .accept-button {
71+ background-color : green ;
72+ color : white ;
73+ border : none ;
74+ padding : 10px 20px ;
75+ margin : 5px ;
76+ cursor : pointer ;
77+ }
78+
79+ .reject-button {
80+ background-color : grey ;
81+ color : white ;
82+ border : none ;
83+ padding : 10px 20px ;
84+ margin : 5px ;
85+ cursor : pointer ;
86+ }
87+
88+ /* Optional: Add hover effects */
89+ .accept-button :hover {
90+ background-color : darkgreen ;
91+ }
92+
93+ .reject-button :hover {
94+ background-color : darkgrey ;
95+ }
96+ </style >
0 commit comments