Is there a way to have an dynamically colored svg as a cursor? I want to have a prop that changes the fill
value and then reflect that on the cursor.
I saw this post and followed their example and not getting the same results.
How to change CSS cursor dynamically vuejs
I made a CodeSandbox to test this out, but currently it's not working. What am I doing wrong here?
If anyone has any tips or advice I would really appreciate it!
Cheers
NOTE: I use this to get the URL code from the svg
https://codepen.io/yoksel/details/MWKeKK
App.vue
<template>
<CustomSVG :style="{ cursor: customCursor }" :fill="fill" />
</template>
<script>
import CustomSVG from "./components/CustomSVG.vue";
import { defineComponent, ref } from "vue";
export default defineComponent({
name: "MyComponent",
props: {},
setup(props) {
const fill = ref("red");
const customCursor = `url("data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 20 20' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M10.7071 10.7071C10.3166 11.0976 9.68342 11.0976 9.29289 10.7071C8.90237 10.3166 8.90237 9.68342 9.29289 9.29289L15.2929 3.29289C15.6834 2.90237 16.3166 2.90237 16.7071 3.29289C17.0976 3.68342 17.0976 4.31658 16.7071 4.70711L10.7071 10.7071Z' fill='${fill.value}'/%3E%3Cpath d='M15 15V11.5C15 10.9477 15.4477 10.5 16 10.5C16.5523 10.5 17 10.9477 17 11.5V16C17 16.5523 16.5523 17 16 17H4C3.44772 17 3 16.5523 3 16V4C3 3.44772 3.44772 3 4 3H8.5C9.05228 3 9.5 3.44772 9.5 4C9.5 4.55228 9.05228 5 8.5 5H5V15H15Z' fill='${fill.value}'/%3E%3Cpath d='M17 8C17 8.55228 16.5523 9 16 9C15.4477 9 15 8.55228 15 8V4C15 3.44772 15.4477 3 16 3C16.5523 3 17 3.44772 17 4V8Z' fill='${fill.value}'/%3E%3Cpath d='M12 5C11.4477 5 11 4.55228 11 4C11 3.44772 11.4477 3 12 3H16C16.5523 3 17 3.44772 17 4C17 4.55228 16.5523 5 16 5H12Z' fill='${fill.value}'/%3E%3C/svg%3E")`;
return { fill, customCursor };
},
components: { CustomSVG },
});
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>