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

createGlobalStyle and keyframes are not getting formatted - styled-components #11196

Closed
erfanasbari opened this issue Jul 12, 2021 · 4 comments
Closed

Comments

@erfanasbari
Copy link

erfanasbari commented Jul 12, 2021

Prettier 2.3.2
Playground link

--parser babel

Input:

import { createGlobalStyle } from "styled-components";

const GlobalStyle = styled.createGlobalStyle`
  body {
    margin: 0;
          padding: 0;
       box-sizing: border-box;
  }
`;

const GlobalStyle = createGlobalStyle`
  body {
    margin: 0;
         padding: 0;
       box-sizing: border-box;
  }
`;

export default GlobalStyle;

Output:

import { createGlobalStyle } from "styled-components";

const GlobalStyle = styled.createGlobalStyle`
  body {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }
`;

const GlobalStyle = createGlobalStyle`
  body {
    margin: 0;
         padding: 0;
       box-sizing: border-box;
  }
`;

export default GlobalStyle;

Expected behavior:

Prettier does not format the css styles passed to createGlobalStyle and keyframes functions from styled-components.

This issue exist for a long time but is not yet fixed.

There are some workarounds but fixing this should not be a big deal because Prettier already supports formatting for styled-components functions line css.

@sosukesuzuki
Copy link
Member

We cannot support such a format, at least not currently. It may be supported in the future using --embedded-language-formatting. See #9025 and #5588.

@ibqn
Copy link

ibqn commented Oct 26, 2021

As a workaround, I would like to propose something like this

import { createGlobalStyle } from 'styled-components'

const styled = { createGlobalStyle }

const GlobalStyle = styled.createGlobalStyle`
  body {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }
  ...
`

export default GlobalStyle

I have previously mentioned it here, styled-components/vscode-styled-components#175

@HanSeokSeo
Copy link

As a workaround, I would like to propose something like this

import { createGlobalStyle } from 'styled-components'

const styled = { createGlobalStyle }

const GlobalStyle = styled.createGlobalStyle`
  body {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }
  ...
`

export default GlobalStyle

I have previously mentioned it here, styled-components/vscode-styled-components#175

you genius!

@kachkaev
Copy link
Member

kachkaev commented Nov 4, 2022

@HanSeokSeo you can also do use css`...` which is a bit less hacky: #9025 (comment)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants