CookieMonster.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <div id="cookie_monster" :class="`print:hidden z-50 ${isOpen ? 'mix-blend-normal' : 'mix-blend-difference'}`">
  3. <div v-if="isOpen" class="fixed bottom-2 right-2 left-2 sm:w-10/12 max-w-screen-md sm:mx-auto">
  4. <div class="border-2 bg-white border-sky-700 px-4 pt-3 pb-4 overflow-scroll">
  5. <client-only><fa-icon :icon="['fas', 'circle-xmark']" class="text-error text-4xl float-right" @click="isOpen = false" /></client-only>
  6. <div class="pb-4">
  7. <p>I use <strong>cookies</strong> for <a href="/cookies">reasons</a>. Please read the reasons before setting your preferences.</p>
  8. <div class="sm:pl-4 pt-2 grid sm:grid-cols-12 grid-cols-6">
  9. <p><input type="checkbox" class="form-control toggle toggle-primary" v-model="consentStore.analytics" @change="(e: Event) => consentStore.analytics = (e.target as HTMLInputElement).checked" /></p>
  10. <p class="col-span-5 sm:col-span-11"><strong>Analytics</strong>: optional, but it'd be great if you agreed 😊</p>
  11. </div>
  12. <div class="sm:pl-4 pt-2 grid sm:grid-cols-12 grid-cols-6">
  13. <p><input type="checkbox" class="form-control toggle toggle-primary" v-model="consentStore.ads" @change="(e: Event) => consentStore.ads = (e.target as HTMLInputElement).checked" /></p>
  14. <p class="col-span-5 sm:col-span-11"><strong>Advertising</strong>: fully optional, feel free to skip this one.</p>
  15. </div>
  16. <p class="pt-2">You can read more on how I use cookies on <a href="/cookies">this page</a>.</p>
  17. </div>
  18. <div class="grid grid-cols-1 sm:grid-cols-3 gap-4">
  19. <button class="btn btn-error" @click="rejectAll">Reject all</button>
  20. <button class="btn btn-info btn-outline" @click="acceptAll">Accept all</button>
  21. <button class="btn btn-success" @click="acceptMyChoice">Accept my choice</button>
  22. </div>
  23. </div>
  24. </div>
  25. <div v-else @click="isOpen = true" class="fixed max-w-0 bottom-2 sm:right-16 right-11 cursor-pointer">
  26. <ClientOnly><fa-icon icon="fa-solid fa-cookie-bite" class="sm:text-6xl text-4xl text-sky-500" /></ClientOnly>
  27. </div>
  28. </div>
  29. </template>
  30. <script lang="ts" setup>
  31. import { useConsent } from '~~/store/consent';
  32. const consentStore = useConsent();
  33. const error = useError();
  34. const isOpen = useState('isOpen', () => !consentStore.preferenceGiven && error.value === undefined);
  35. const rejectAll = () => {
  36. consentStore.analytics = false;
  37. consentStore.ads = false;
  38. consentStore.preferenceGiven = true;
  39. isOpen.value = false;
  40. }
  41. const acceptAll = () => {
  42. consentStore.analytics = true;
  43. consentStore.ads = true;
  44. consentStore.preferenceGiven = true;
  45. isOpen.value = false;
  46. }
  47. const acceptMyChoice = () => {
  48. consentStore.preferenceGiven = true;
  49. isOpen.value = false;
  50. }
  51. </script>
  52. <style lang="pcss">
  53. #cookie_monster {
  54. div {
  55. width: 100%;
  56. }
  57. a {
  58. color: theme(colors.sky.700);
  59. text-decoration: underline;
  60. }
  61. }
  62. </style>