Skip to content

Support keyframes and createGlobalStyle in "@linaria/react" #1427

Open

Description

@otomad

Describe the feature

These two functions come from Styled Components.

keyframes function will create a CSS keyframes with a unique name, to make sure that there are no naming conflicts.

You can even inline the declaration without having to think of a keyframes name:

div {
    animation: ${keyframes`
        from {
            opacity: 0;
        }
    `} ease-out 1s;
}

createGlobalStyle will create a global style for every components to use, without to write it in a single CSS file.

Motivation

This will make it easier to switch Styled Components to Linaria.

Activity

  1. KutnerUri commented on Dec 2, 2024

    @KutnerUri

    I agree, right now keyframes are preprocessed and it feels like dark magic.
    it would be nice to have a dedicated function for that

  2. alexamy commented on Dec 27, 2024

    @alexamy

    I turned off preprocessor for my use case and now I cannot use global() {}. Something like globalStyle (like in vanilla-extract) method would be helpful.

  3. LaggardNC commented on Aug 25, 2025

    @LaggardNC

    For anyone wants to use named keyframes, there is a way to do it. Bit hacky, but does its work:

    const animationHash = css`
      @keyframes progressAnimation {
        from {
          background-size: 0% 100%;
        }
        to {
          background-size: 100% 100%;
        }
      }
    `;
    
    export const ProgressIndicatorStyled = styled.div`
     ...
      animation-name: ${({ pending }) => (pending ? `progressAnimation-${animationHash}` : "none")};
    `
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature: proposal 💬New feature proposal that needs to be discussedneeds: triage 🏷Issue needs to be checked and prioritized

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions