Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@keyframes :global() selector not properly handled in CSS modules - Unexpected token Colon #863

Closed
jantimon opened this issue Dec 3, 2024 · 6 comments

Comments

@jantimon
Copy link

jantimon commented Dec 3, 2024

When using the :global() selector with @keyframes the animation name cannot be parsed and LightningCSS throws a syntax error Unexpected token Colon

Example CSS

@keyframes :global(foo) {
  to {
    opacity: 1
  }
}

Current Behavior

Unexpected token Colon

Expected Behavior

Same result as PostCSS (Stackblitz Demo):

@keyframes foo {
  to {
    opacity: 1
  }
}
@devongovett
Copy link
Member

Duplicate of #825. This syntax is not supported.

@jantimon
Copy link
Author

Okay - I really like the idea of @global - do you think it makes sense to start working on a @global pr?

What about using global keyframes?
That's not possible with @global

postcss supports the following syntax:

animation: global(animation-name);

postcss allows mixing it with non global animation names in the same declaration

@devongovett
Copy link
Member

The "referencing an identifier" section of the proposal has a more general way to do that which would allow importing names from other files in addition to the global namespace.

@jantimon
Copy link
Author

jantimon commented Dec 18, 2024

okay so instead of

animation: global(animation-name);

you would prefer

animation: import(animation-name from global);

do you think we could already implement import(XXX from global)?
in that case I would create an issue and a pr

@devongovett
Copy link
Member

Not sure. It was just a proposal. I was hoping to get consensus between implementations. Sounds like postcss implemented global() recently? Do they have a way to use an animation name defined in another file?

@jantimon
Copy link
Author

That's correct - it was added last month

shot-r5arj7bq@2x

Right now it's not possible in postcss to import an identifier from another file so the only solution is defining it global either in a non css module or using :global() like this:

@keyframes :global(fade-in) {
  
}

once defined it can be consume with global() from another file:

animation: global(animation-name);

global() also allows using pre defined keyframes from libraries like https://animate.style/ or open-props

and global() also allows using page wide defined animations which can be used in different islands

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants