Skip to content

Commit

Permalink
add browser detection plugin and disable Glow in Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
bdrtsky committed May 15, 2023
1 parent bc0679e commit 79c10ae
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
10 changes: 9 additions & 1 deletion .docs/components/landing/Glow.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script setup lang="ts">
import type { PropType } from 'vue'
const { isFirefox } = useUserAgent()
const props = defineProps({
width: {
type: String,
Expand Down Expand Up @@ -59,10 +61,16 @@ const props = defineProps({
default: 'color'
}
})
const show = ref(false)
onMounted(() => {
show.value = isFirefox.value ? false : true
})
</script>

<template>
<div class="glow" :class="{noise}">
<div v-if="show" class="glow" :class="{noise}">
<svg v-if="noise">
<filter id="f">
<feTurbulence type="fractalNoise" baseFrequency="7.5" />
Expand Down
2 changes: 1 addition & 1 deletion .docs/tokens.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default defineTheme({
wrapper: {
backgroundImage: {
initial: 'linear-gradient(180deg, rgba({temp.color.gray.100}, 0.3), rgba({temp.color.gray.100}, 0.6))',
dark: 'linear-gradient(180deg, rgba({temp.color.gray.900}, 0.3), rgba({temp.color.gray.900}, 0.6))',
dark: 'linear-gradient(180deg, rgba({temp.color.gray.800}, 0.3), rgba({temp.color.gray.900}, 0.6))',
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions composables/useUserAgent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const useUserAgent = () => {
const { $userAgent } = useNuxtApp()

return $userAgent
}
31 changes: 31 additions & 0 deletions plugins/user-agent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export default defineNuxtPlugin(() => {
const isMobile = ref(false)
const isSafari = ref(false)
const isFirefox = ref(false)
const isChrome = ref(false)
const isEdge = ref(false)

const refresh = () => {
const ua = navigator.userAgent

isMobile.value = /iPhone|iPad|iPod|Android/i.test(ua)
isFirefox.value = /Firefox/i.test(ua)
isChrome.value = /Chrome/i.test(ua) && !/Edg/i.test(ua)
isSafari.value = /Safari/i.test(ua) && !/Chrome/i.test(ua)
isEdge.value = /Edg/i.test(ua)
}

if (process.client) { refresh() }

return {
provide: {
userAgent: {
isMobile,
isSafari,
isFirefox,
isChrome,
isEdge
}
}
}
})

0 comments on commit 79c10ae

Please sign in to comment.