i'm wondering if it's possible to call the css variable inside an animation mixin in sass to have a dynamic animaction color based.
I've tried a lot about interpolation in Sass,but it never succeed. the version of the mixin without de dynamic color is working but not with the dynamic css variable.
So i'm wondering if it's possible and how to achieve it?
I'm using node-sass (version: 1.22.9).
View
<ion-button class="pulse pulse-danger"></ion-button>
SCSS
# Var
--ion-color-primary: #FFFFFF;
--ion-color-danger: #000000;
/**
* Pulse Animation
*/
@mixin animation-pulse($duration, $color-name) {
$name: animation-pulse-#{$color-name};
@keyframes #{$name} {
0% {
-moz-box-shadow: 0 0 0 0 #{"rgba(--ion-color-#{$color-name}, 0.4)"};
box-shadow: 0 0 0 0 #{"rgba(--ion-color-#{$color-name}, 0.4)"};
}
70% {
-moz-box-shadow: 0 0 0 10px #{"rgba(--ion-color-#{$color-name}, 0)"};
box-shadow: 0 0 0 10px #{"rgba(--ion-color-#{$color-name}, 0)"};
}
100% {
-moz-box-shadow: 0 0 0 0 #{"rgba(--ion-color-#{$color-name}, 0)"};
box-shadow: 0 0 0 0 #{"rgba(--ion-color-#{$color-name}, 0)"};
}
}
@-webkit-keyframes #{$name} {
0% {
-webkit-box-shadow: 0 0 0 0 #{"rgba(--ion-color-#{$color-name}, 0.4)"};
}
70% {
-webkit-box-shadow: 0 0 0 10px #{"rgba(--ion-color-#{$color-name}, 0)"};
}
100% {
-webkit-box-shadow: 0 0 0 0 #{"rgba(--ion-color-#{$color-name}, 0)"};
}
}
animation-name: $name;
animation-duration: $duration;
animation-iteration-count: infinite;
}
.pulse {
&:hover {
animation: none;
}
&.pulse-primary {
background: var(--ion-color-primary);
box-shadow: 0 0 0 rgba(var(--ion-color-primary), 0.4);
@include animation-pulse(2s, primary);
}
&.pulse-danger {
background: var(--ion-color-danger);
box-shadow: 0 0 0 rgba(var(--ion-color-danger), 0.4);
@include animation-pulse(2s, danger);
}
}
Actual result is not showing the pulse animation probably cause the css var is not properly set in the mixin.
If i replace in the mixin animation-pulse the color by a static value, the pulse animation is working.