Change stroke color of svg icons on different background

Viewed 69

I Want to change my svg icon into different colors depending on their background I am using this star icon that has this code:

<svg width="33" height="33" viewBox="0 0 33 33" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M16.5344 5.82104L19.7321 12.087L26.6796 13.1919L21.7084 18.1694L22.8045 25.1183L16.5344 21.9286L10.2644 25.1183L11.3604 18.1694L6.38928 13.1919L13.3367 12.087L16.5344 5.82104Z" stroke="black" stroke-width="2"/>
</svg>

when it has white background it looks like this and have black stoke and that is fine as below image:

enter image description here

And when I add the same star svg icon to the button component then it should have white stroke and not black stroke, have tried with

 svg { fill: currentColor) // then it's invisible on white background, because of its whiteness.

like below, How can I achieve the white star without black stoke ?

enter image description here

instead of having the star with black stokes enter image description here

After following the suggestion where I was sending this two props: scgStroke and svgFill, now in my white background I am getting star with black fill and in button as below: enter image description here enter image description here

I want the outside stroke to show not the white fill (fill = "white") something like below image: enter image description here

1 Answers

You can create component and pass props with colors:

Vue.component('icon', {
  template: `
  <svg width="33" height="33" viewBox="0 0 33 33"  xmlns="http://www.w3.org/2000/svg" >
    <path fill="none" d="M16.4206 26.7218H5.75391V12.722L16.4206 4.39893L27.0872 12.722V26.7218H16.4206ZM16.4206 26.7218V18.7218" :stroke="svgStroke" :stroke-width="strokeWidth"/>
  </svg>`,
  props: {
    svgStroke: {default: 'black'},
    strokeWidth: {default: 2}
  }
})

new Vue({
  el: '#demo',
})
.btn {
  background-color: #2f76fd;
  color: white;
  display: flex;
  align-items: center;
  border: none;
  padding: .5em 1em;
}
.btn-text {
  margin-right: .5em;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="demo">
  <icon></icon>
  <button class="btn">
    <span class="btn-text">Primary</span>
    <icon svg-stroke="white" stroke-width="2"></icon>
  </button>
</div>

Related