vscode-styled-components icon indicating copy to clipboard operation
vscode-styled-components copied to clipboard

No syntax and highlight when using template string with string interpolation

Open xristosNSK opened this issue 2 years ago • 6 comments

I'm currently using @mui/material which includes emotion/react. The following syntax doesn't seem to work.

image

Any suggestions?

xristosNSK avatar Dec 22 '22 22:12 xristosNSK

Just like with styled-components, return the css template string function instead of a plain template literal. This'll not only fix syntax highlighting, but also CSS linters in case you're using those 😄

import { css, styled } from '@mui/material';

export const PropertyWrapper = styled('div')(
  ({ theme: { palette } }) => css`
    border-radius: 25px;
    border: 1px solid ${palette.divider};
  `
);

oscarvz avatar Jan 14 '23 09:01 oscarvz

@oscarvz I don't believe this works the way you think it does. When I tried it, I got errors about trying to stringify the object that MUI's css function produces.

Twipped avatar Jan 17 '23 19:01 Twipped

@Twipped this sandbox demonstrates the difference in syntax highlighting. I've been using this approach for basically every project (albeit mostly with styled-components and only once with MUI) as otherwise linting & syntax highlighting won't work.

Do those errors you mention pop up when building your project?

oscarvz avatar Jan 17 '23 20:01 oscarvz

@oscarvz they were popping up when running jest tests, so it may actually be an issue with emotion's interactions with JSDOM

Twipped avatar Jan 17 '23 20:01 Twipped

Can I use this functional with styled.div instead styled('div')? I use import from @emotion/styled.

It is wished variant of usage, but I don't see syntax highlight in Header component: Screenshot 2024-04-12 at 14 25 41

When I try to use import from @mui/material I get error, that "Property 'div' does not exist on type 'CreateMUIStyled<Theme>'": Screenshot 2024-04-12 at 14 26 24

I can fix it, if I use import from emotion and material at the same time: Screenshot 2024-04-12 at 14 29 59

Do it have any methods of usage to fix it without extra imports?

aleksandrjet avatar Apr 12 '24 07:04 aleksandrjet

I got hit by this today:

https://github.com/styled-components/vscode-styled-components/assets/3165635/06b5e83c-087f-497b-8a48-2d302b072873

What seems strange is that there seems to be a test case for it:

https://github.com/styled-components/vscode-styled-components/blob/52e29eba6676d73075aada3a5e09c935786ec3e2/src/tests/suite/colorize-fixtures/theme-function.js#L1-L4

It feels like this issue is a continuation of https://github.com/styled-components/vscode-styled-components/issues/194. It's an edge case that was overlooked.

oliviertassinari avatar May 28 '24 14:05 oliviertassinari