-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathAddToBrowserCTA.vue
More file actions
65 lines (56 loc) · 2.03 KB
/
AddToBrowserCTA.vue
File metadata and controls
65 lines (56 loc) · 2.03 KB
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
<script setup lang="ts">
import { computed, ref, onMounted } from 'vue';
import AddToChromeButton from '@/components/ui/AddToChromeButton.vue';
import AddToFirefoxButton from '@/components/ui/AddToFirefoxButton.vue';
import Button from '@/components/ui/Button.vue';
const props = withDefaults(
defineProps<{
showFreeBadge?: boolean;
userAgent?: string; // for testing if true, show AddTo button even on mobile/tablet */
ctaLink: string;
label: string;
}>(),
{
showFreeBadge: true,
userAgent: undefined,
},
);
const userAgent = computed(() => (props.userAgent ?? navigator.userAgent).toLowerCase());
const isFirefox = computed(() => userAgent.value.includes('firefox'));
const isMobileOrTablet = ref(false);
onMounted(() => {
const hasTouch = navigator.maxTouchPoints > 0 || 'ontouchstart' in window;
const isMobileUserAgent = /android|iphone|ipad|ipod|mobile|tablet/.test(userAgent.value);
isMobileOrTablet.value = hasTouch && isMobileUserAgent;
});
const submit = (event?: Event) => {
event?.preventDefault();
const params = new URLSearchParams({
redirect_to: 'https://elliotforwater.com/',
});
window.open(`${props.ctaLink}?${params.toString()}`, '_blank');
};
</script>
<template>
<!-- Mobile/Tablet -->
<div v-if="isMobileOrTablet" class="w-full">
<slot name="mobileHint" />
<div class="flex items-start gap-2 md:gap-6 justify-center">
<Button variant="secondary" class="text-sm sm:text-base" @click="submit">
{{ props.label }}
</Button>
<slot name="secondCta" />
</div>
</div>
<!-- Desktop View -->
<div v-else class="flex items-start gap-2 md:gap-6 justify-center">
<div class="relative">
<AddToChromeButton v-if="!isFirefox" />
<AddToFirefoxButton v-else />
<div v-if="showFreeBadge" class="max-w-[70px] md:max-w-[100px] lg:max-w-[172px] w-full -translate-x-[40%] sm:-translate-x-[98%] sm:-translate-y-[2%]">
<img src="/icons/free-icon.svg" alt="free-icon" />
</div>
</div>
<slot name="secondCta" />
</div>
</template>