ember-css-modules icon indicating copy to clipboard operation
ember-css-modules copied to clipboard

Breaks when using `animation` and `@keyframes`

Open luxzeitlos opened this issue 7 years ago • 5 comments

If I do this:

.foo {
  animation: 0.8s bigsign, 1s wobblesign 1s infinite;
}

@keyframes foo {
  ...
}

I get this error:

Invalid CSS after "...animation: 0.8s": expected "}", was ":local(bigsign), 1s"

luxzeitlos avatar Jan 14 '18 01:01 luxzeitlos

This is a problem with the underlying postcss plugin. I'm only on mobile, otherwise I'd link the issue.

Basically just use the animation-name property instead of or in addition to the shorthand and it'll work.

buschtoens avatar Jan 14 '18 05:01 buschtoens

Thanks! I wasn't able to find something here, and I'm a bit confused where which issues are tracked. However I think it would be good for this issue to stay open so people find it. Maybe with the upstream label?

luxzeitlos avatar Jan 14 '18 16:01 luxzeitlos

https://github.com/css-modules/css-modules/issues/141#issuecomment-243011699

.active {
  :global {
    animation: slideInFromRight 0.35s ease-in-out;
  }
}

https://github.com/css-modules/css-modules/issues/141#issuecomment-293092109

.fadein {
  animation-duration: 300ms;
  animation-name: fadein;
  animation-fill-mode: forwards;
}

@keyframes fadein {
  from {
    opacity: 0
  }
}

This is still very broken in upstream, even though the upstream issue is closed.

buschtoens avatar Jan 15 '18 09:01 buschtoens

Still very broken...

My original code was

  @keyframes rotate {
    from {
      -webkit-transform: rotate(0deg);
      -o-transform: rotate(0deg);
      transform: rotate(0deg);
    }
    to {
      -webkit-transform: rotate(360deg);
      -o-transform: rotate(360deg);
      transform: rotate(360deg);
    }
  }

  @mixin rotation {
    animation: rotate 2s linear infinite;
  }

Based on the advice above

  @keyframes rotate {
    from {
      -webkit-transform: rotate(0deg);
      -o-transform: rotate(0deg);
      transform: rotate(0deg);
    }
    to {
      -webkit-transform: rotate(360deg);
      -o-transform: rotate(360deg);
      transform: rotate(360deg);
    }
  }

  @mixin rotation {
    animation-name: rotate;
    animation: 2s linear infinite;
  }

Based on advice elsewhere that adding global will make it work...

:global {
  @keyframes rotate {
    from {
      -webkit-transform: rotate(0deg);
      -o-transform: rotate(0deg);
      transform: rotate(0deg);
    }
    to {
      -webkit-transform: rotate(360deg);
      -o-transform: rotate(360deg);
      transform: rotate(360deg);
    }
  }

  @mixin rotation {
    animation-name: rotate;
    animation: 2s linear infinite;
  }
}

ALL of them fail with syntax errors in the compiled css during build.

  1. What's the correct workaround?
  2. What's the link to the issue in the upstream? Where would I go to fix this?

BryanCrotaz avatar Nov 29 '20 22:11 BryanCrotaz

Requires the following in package.json (with yarn)

resolutions: {
  "postcss-modules-scope": "^3.0.0",
  "postcss": "^8.0.0",
  "broccoli-css-modules": "fpauser/broccoli-css-modules#migrate-to-postcss-8",
  "postcss-scss": "^3.0.0"
}

BryanCrotaz avatar Nov 30 '20 14:11 BryanCrotaz