0

I'm using angular material and have 3 different themes. I'm attempting to make a "pulse" animation and I'm using colors of the theme's primary to pulse the

Now from what I read it appears that angular doesn't scope keyframes to components and instead they are declared globally. So it appears that wherever my last declared theme is, it's overriding the previous and in the end the color of the kyframes is the same for all themes.

I created custom component and I added the keyframes and animation as shown below. However, the color doesn't change when I change each theme.

What is the proper way to do this and still use the theme's primary color?

@import '~@angular/material/theming';

@mixin atrh-rating-component-theme($theme) {
  $primary: map-get($theme, primary);

  .bar {
    background-color: mat-color($primary, 200);

    &--selected {
      background-color: mat-color($primary);
    }

    &--highlighted {
      background-color: mat-color($primary, 800);
      animation: pulse 1.3s;
      animation-iteration-count: 4;
    }
  }

  @keyframes pulse {
    0% {
        background-color: mat-color($primary, 900)
    }

    50% {
        background-color: mat-color($primary, 700)
    }

    100% {
        background-color: mat-color($primary, 900)
    }
  }
}

1 Answer 1

2

Add to your themes a name to be used for the keyframes, and use that instead of the common 'pulse'. For example:

$theme: map-merge(mat-light-theme(...), ('keyframes': 'pulse1'));

...

@mixin atrh-rating-component-theme($theme) {

  $keyframes-name: map-get($theme, keyframes);

  .bar {
    ...

    &--highlighted {
      ...
      animation: $keyframes-name 1.3s;
      ...
    }
  }

  @keyframes #{$keyframes-name} {
    ...
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.