Created
March 24, 2024 15:40
-
-
Save leemartin/d314b14f1817fd8075f49b98f613db08 to your computer and use it in GitHub Desktop.
A progress circle Vue component powered by CSS conic gradient
This file contains hidden or 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
<template> | |
<div class="h-full rounded-full w-full" :style="conicGradient"></div> | |
</template> | |
<script setup> | |
// Props | |
const props = defineProps({ | |
color: { | |
type: String, | |
default: '#000000' | |
}, | |
progress: { | |
type: Number, | |
default: 0.5 | |
}, | |
width: { | |
type: Number, | |
default: 3.8 | |
} | |
}) | |
// Conic gradient | |
// ---------- | |
const conicGradient = computed(() => { | |
return { | |
background: `conic-gradient(${props.color} 0deg, ${props.color} ${props.progress * 360}deg, transparent ${props.progress * 360}deg)`, | |
maskImage: `radial-gradient(transparent ${71 - props.width}%, white ${71 - props.width}%)` | |
} | |
}) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment