How to change color of icon in Editable Svg Icons system in vuejs cookbook?
I'm trying to use the system proposed by vuejs cookbook for keeping svg icons (https://vuejs.org/v2/cookbook/editable-svg-icons.html)
So I have 2 components: IconBase and IconArrowUp. I need to change color of arrow icon on hover (also css transition should be applied).
In the article they have iconColor property. But I didn't manage to change the color using css, and it's not that convenient to use events like onmouseenter.
Here is the code of two components:
IconBase.vue:
<template>
<svg xmlns="http://www.w3.org/2000/svg"
:width="width"
:height="height"
viewBox="0 0 100 100"
role="presentation"
@click="$emit('click')">
<g :fill="iconColor">
<slot />
</g>
</svg>
</template>
<script>
export default {
props: {
width: {
type: [Number, String],
default: 18
},
height: {
type: [Number, String],
default: 18
},
iconColor: {
type: String,
default: 'currentColor'
}
}
}
</script>
And IconArrowUp.vue:
<template>
<path d="m12.398 40.102 13.402 13.5 14.699-14.801v58.699h19v-58.699l14.699 14.801 13.402-13.5-37.602-37.602z"/>
</template>
So this is how I use them (another component ScrollToTop.vue):
<template>
<div class="scroll-to-top">
<icon-base class="icon-arrow-up"
width="20"
height="20"
icon-color="#949494">
<icon-arrow-up/>
</icon-base>
</div>
</template>
How can I change to color of icon on hover? I want to keep IconArrowUp component clean though, so that if I need I use it without color change
css svg vue.js vuejs2
add a comment |
I'm trying to use the system proposed by vuejs cookbook for keeping svg icons (https://vuejs.org/v2/cookbook/editable-svg-icons.html)
So I have 2 components: IconBase and IconArrowUp. I need to change color of arrow icon on hover (also css transition should be applied).
In the article they have iconColor property. But I didn't manage to change the color using css, and it's not that convenient to use events like onmouseenter.
Here is the code of two components:
IconBase.vue:
<template>
<svg xmlns="http://www.w3.org/2000/svg"
:width="width"
:height="height"
viewBox="0 0 100 100"
role="presentation"
@click="$emit('click')">
<g :fill="iconColor">
<slot />
</g>
</svg>
</template>
<script>
export default {
props: {
width: {
type: [Number, String],
default: 18
},
height: {
type: [Number, String],
default: 18
},
iconColor: {
type: String,
default: 'currentColor'
}
}
}
</script>
And IconArrowUp.vue:
<template>
<path d="m12.398 40.102 13.402 13.5 14.699-14.801v58.699h19v-58.699l14.699 14.801 13.402-13.5-37.602-37.602z"/>
</template>
So this is how I use them (another component ScrollToTop.vue):
<template>
<div class="scroll-to-top">
<icon-base class="icon-arrow-up"
width="20"
height="20"
icon-color="#949494">
<icon-arrow-up/>
</icon-base>
</div>
</template>
How can I change to color of icon on hover? I want to keep IconArrowUp component clean though, so that if I need I use it without color change
css svg vue.js vuejs2
add a comment |
I'm trying to use the system proposed by vuejs cookbook for keeping svg icons (https://vuejs.org/v2/cookbook/editable-svg-icons.html)
So I have 2 components: IconBase and IconArrowUp. I need to change color of arrow icon on hover (also css transition should be applied).
In the article they have iconColor property. But I didn't manage to change the color using css, and it's not that convenient to use events like onmouseenter.
Here is the code of two components:
IconBase.vue:
<template>
<svg xmlns="http://www.w3.org/2000/svg"
:width="width"
:height="height"
viewBox="0 0 100 100"
role="presentation"
@click="$emit('click')">
<g :fill="iconColor">
<slot />
</g>
</svg>
</template>
<script>
export default {
props: {
width: {
type: [Number, String],
default: 18
},
height: {
type: [Number, String],
default: 18
},
iconColor: {
type: String,
default: 'currentColor'
}
}
}
</script>
And IconArrowUp.vue:
<template>
<path d="m12.398 40.102 13.402 13.5 14.699-14.801v58.699h19v-58.699l14.699 14.801 13.402-13.5-37.602-37.602z"/>
</template>
So this is how I use them (another component ScrollToTop.vue):
<template>
<div class="scroll-to-top">
<icon-base class="icon-arrow-up"
width="20"
height="20"
icon-color="#949494">
<icon-arrow-up/>
</icon-base>
</div>
</template>
How can I change to color of icon on hover? I want to keep IconArrowUp component clean though, so that if I need I use it without color change
css svg vue.js vuejs2
I'm trying to use the system proposed by vuejs cookbook for keeping svg icons (https://vuejs.org/v2/cookbook/editable-svg-icons.html)
So I have 2 components: IconBase and IconArrowUp. I need to change color of arrow icon on hover (also css transition should be applied).
In the article they have iconColor property. But I didn't manage to change the color using css, and it's not that convenient to use events like onmouseenter.
Here is the code of two components:
IconBase.vue:
<template>
<svg xmlns="http://www.w3.org/2000/svg"
:width="width"
:height="height"
viewBox="0 0 100 100"
role="presentation"
@click="$emit('click')">
<g :fill="iconColor">
<slot />
</g>
</svg>
</template>
<script>
export default {
props: {
width: {
type: [Number, String],
default: 18
},
height: {
type: [Number, String],
default: 18
},
iconColor: {
type: String,
default: 'currentColor'
}
}
}
</script>
And IconArrowUp.vue:
<template>
<path d="m12.398 40.102 13.402 13.5 14.699-14.801v58.699h19v-58.699l14.699 14.801 13.402-13.5-37.602-37.602z"/>
</template>
So this is how I use them (another component ScrollToTop.vue):
<template>
<div class="scroll-to-top">
<icon-base class="icon-arrow-up"
width="20"
height="20"
icon-color="#949494">
<icon-arrow-up/>
</icon-base>
</div>
</template>
How can I change to color of icon on hover? I want to keep IconArrowUp component clean though, so that if I need I use it without color change
css svg vue.js vuejs2
css svg vue.js vuejs2
edited Nov 26 '18 at 2:53
tony19
25.4k44378
25.4k44378
asked Nov 26 '18 at 0:11
VictorVictor
1,95244074
1,95244074
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You could make the fill conditional on a local Boolean that changes based on mouseover/mouseout events:
In
IconBase.vue, define a local data variable (e.g., namedisHover) to track the hover state, and apropto set the color during the hover state:
props: [
// ...
iconHoverColor: {
type: String,
default: "currentColor"
}
],
data() {
return {
isHover: false
}
}
Edit
IconBase.vue's template to makefillconditional onisHover, and setisHoverbased onmouseover/mouseoutevents:
<g :fill="isHover ? iconHoverColor : iconColor"
@mouseover="isHover = true"
@mouseout="isHover = false">
To set the color transition, use CSS in
IconBase.vueon a class applied to<g>:
<style scoped>
/* <g class="icon" ...> */
.icon {
transition: fill .4s ease;
}
</style>
In
ScrollToTop.vue, edit the usage ofIconBaseto set the hover color:
<icon-base icon-hover-color="#ff0000" ...>
demo
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53473292%2fhow-to-change-color-of-icon-in-editable-svg-icons-system-in-vuejs-cookbook%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could make the fill conditional on a local Boolean that changes based on mouseover/mouseout events:
In
IconBase.vue, define a local data variable (e.g., namedisHover) to track the hover state, and apropto set the color during the hover state:
props: [
// ...
iconHoverColor: {
type: String,
default: "currentColor"
}
],
data() {
return {
isHover: false
}
}
Edit
IconBase.vue's template to makefillconditional onisHover, and setisHoverbased onmouseover/mouseoutevents:
<g :fill="isHover ? iconHoverColor : iconColor"
@mouseover="isHover = true"
@mouseout="isHover = false">
To set the color transition, use CSS in
IconBase.vueon a class applied to<g>:
<style scoped>
/* <g class="icon" ...> */
.icon {
transition: fill .4s ease;
}
</style>
In
ScrollToTop.vue, edit the usage ofIconBaseto set the hover color:
<icon-base icon-hover-color="#ff0000" ...>
demo
add a comment |
You could make the fill conditional on a local Boolean that changes based on mouseover/mouseout events:
In
IconBase.vue, define a local data variable (e.g., namedisHover) to track the hover state, and apropto set the color during the hover state:
props: [
// ...
iconHoverColor: {
type: String,
default: "currentColor"
}
],
data() {
return {
isHover: false
}
}
Edit
IconBase.vue's template to makefillconditional onisHover, and setisHoverbased onmouseover/mouseoutevents:
<g :fill="isHover ? iconHoverColor : iconColor"
@mouseover="isHover = true"
@mouseout="isHover = false">
To set the color transition, use CSS in
IconBase.vueon a class applied to<g>:
<style scoped>
/* <g class="icon" ...> */
.icon {
transition: fill .4s ease;
}
</style>
In
ScrollToTop.vue, edit the usage ofIconBaseto set the hover color:
<icon-base icon-hover-color="#ff0000" ...>
demo
add a comment |
You could make the fill conditional on a local Boolean that changes based on mouseover/mouseout events:
In
IconBase.vue, define a local data variable (e.g., namedisHover) to track the hover state, and apropto set the color during the hover state:
props: [
// ...
iconHoverColor: {
type: String,
default: "currentColor"
}
],
data() {
return {
isHover: false
}
}
Edit
IconBase.vue's template to makefillconditional onisHover, and setisHoverbased onmouseover/mouseoutevents:
<g :fill="isHover ? iconHoverColor : iconColor"
@mouseover="isHover = true"
@mouseout="isHover = false">
To set the color transition, use CSS in
IconBase.vueon a class applied to<g>:
<style scoped>
/* <g class="icon" ...> */
.icon {
transition: fill .4s ease;
}
</style>
In
ScrollToTop.vue, edit the usage ofIconBaseto set the hover color:
<icon-base icon-hover-color="#ff0000" ...>
demo
You could make the fill conditional on a local Boolean that changes based on mouseover/mouseout events:
In
IconBase.vue, define a local data variable (e.g., namedisHover) to track the hover state, and apropto set the color during the hover state:
props: [
// ...
iconHoverColor: {
type: String,
default: "currentColor"
}
],
data() {
return {
isHover: false
}
}
Edit
IconBase.vue's template to makefillconditional onisHover, and setisHoverbased onmouseover/mouseoutevents:
<g :fill="isHover ? iconHoverColor : iconColor"
@mouseover="isHover = true"
@mouseout="isHover = false">
To set the color transition, use CSS in
IconBase.vueon a class applied to<g>:
<style scoped>
/* <g class="icon" ...> */
.icon {
transition: fill .4s ease;
}
</style>
In
ScrollToTop.vue, edit the usage ofIconBaseto set the hover color:
<icon-base icon-hover-color="#ff0000" ...>
demo
edited Nov 26 '18 at 3:00
answered Nov 26 '18 at 2:53
tony19tony19
25.4k44378
25.4k44378
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53473292%2fhow-to-change-color-of-icon-in-editable-svg-icons-system-in-vuejs-cookbook%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown