-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: display core web vitals results (#3)
- Loading branch information
Showing
13 changed files
with
483 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<script setup lang="ts"> | ||
const props = defineProps({ | ||
value: { | ||
type: Object as () => { | ||
caption?: string | number | ||
segments: number[] | ||
}, | ||
required: false | ||
}, | ||
caption: { | ||
type: String, | ||
required: false | ||
}, | ||
size: { | ||
type: String as () => 'large' | 'normal', | ||
default: 'large' | ||
}, | ||
showP75: { | ||
type: Boolean, | ||
default: false | ||
} | ||
}) | ||
const radius = props.size === 'large' ? 132 : 75 | ||
const stroke = props.size === 'large' ? 14 : 9 | ||
const normalizedRadius = radius - stroke * 2 | ||
const circumference = normalizedRadius * 2 * Math.PI | ||
const colours = [ | ||
'#ef4444', | ||
'#fbbf24', | ||
'#23c55e' | ||
] | ||
const p75Color = computed(() => { | ||
let count = 0 | ||
for (const [index, segment] of props.value?.segments?.entries() || []) { | ||
count += segment | ||
if (count >= 75) { | ||
return colours[colours.length - index - 1] | ||
} | ||
} | ||
return '#6b7280' | ||
}) | ||
</script> | ||
|
||
<template> | ||
<span class="flex flex-col items-center" :class="size === 'large' ? 'gap-10' : 'gap-4'"> | ||
<span class="relative rounded-full flex items-center justify-center" :class="[size === 'large' ? 'text-7xl h-60 w-60' : 'text-3xl h-36 w-36']"> | ||
<svg class="absolute -right-0 -bottom-0" :height="radius * 2" :width="radius * 2" :class="{ 'animate-spin': !value }"> | ||
<circle | ||
v-for="segment, index of [...value?.segments || [80]].reverse()" | ||
:stroke="value ? colours[index] : '#6b7280'" | ||
fill="transparent" | ||
class="transform-origin-center" | ||
:stroke-dasharray="circumference + ' ' + circumference" | ||
:style="{ | ||
strokeDashoffset: circumference - segment / 100 * circumference, | ||
transform: `rotate(270deg)`, | ||
}" | ||
:stroke-width="stroke" | ||
:r="normalizedRadius" | ||
:cx="radius" | ||
:cy="radius" | ||
/> | ||
<circle v-if="value && showP75" :fill="p75Color" stroke="#fff" stroke-width="5" cx="20" cy="20" r="10" style="transform: translateX(-2px) translateY(calc(50% - 20px))"></circle> | ||
</svg> | ||
<slot> | ||
<span v-if="value?.caption" class="flex flex-row items-baseline gap-1"> | ||
<span :class="size === 'large' ? 'text-6xl' : 'text-3xl'">{{ value.caption.replace(/m?s/, '') }}</span> | ||
<span v-if="value.caption.match(/m?s/)" :class="size === 'large' ? 'text-4xl' : 'text-lg'">{{ value.caption.match(/m?s/)![0] }}</span> | ||
</span> | ||
</slot> | ||
</span> | ||
<span :class="size === 'large' ? 'text-4xl' : 'text-2xl'">{{ caption }}</span> | ||
</span> | ||
</template> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.