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

No color highlighting when using function that returns code

Open Jerome1337 opened this issue 3 years ago • 6 comments

Describe the bug (including copyable syntax) No color highlighting when using function inside a styled component.

Example:

${({ $currentStep, theme }) => {
  if ($currentStep > 0) {
    return `
      padding: 10px 8px 10px 25px;

      @media (min-width: ${theme.breakpoints.md}) {
        padding: 10px 18px;
      }
    `;
  }
}}

Screenshot Screenshot 2022-03-11 at 7 55 52 AM

To Reproduce To reproduce, simply add a function that returns some css code into a styled component and no color highlighting will be shown.

Expected behavior CSS code should be color highlighted.

Build environment (please complete the following information):

  • OS: MacOS 12.2.1 (M1 chip)
  • VSCode Version: 1.65.2
  • Extension Version 1.7.3

Additional context Maybe related to this issue https://github.com/styled-components/vscode-styled-components/issues/358

Jerome1337 avatar Mar 11 '22 07:03 Jerome1337

it's not even just the colour highlighting, it's also lacking autocompletion and suggestions.

pzi avatar Mar 30 '22 07:03 pzi

Came to see if this was an issue for anyone else. I have to wrap in css to get syntax highlighting to work.

Does this work for you? I'm in react-native.

import styled, { css } from 'styled-components/native';

export const ModalHandle = styled.View(
  ({ theme }) => css`
    flex-direction: row;
    align-self: center;
    height: 5px;
    width: 40px;
    border-radius: 5px;
    margin-bottom: 16px;
    background-color: ${theme.colors.modal.handle};
  `
)

For your example...

${({ $currentStep, theme }) => {
  if ($currentStep > 0) {
            👇
    return css`
      padding: 10px 8px 10px 25px;

      @media (min-width: ${theme.breakpoints.md}) {
        padding: 10px 18px;
      }
    `;
  }
}}

GollyJer avatar Apr 13 '22 04:04 GollyJer

@GollyJer yeah, it does work, but I think the point is that we shouldn't have to use that. The code will compile fine (I am in web land) but you just don't have the completion and highlighting in vscode.

pzi avatar Apr 13 '22 08:04 pzi

Yeah. Would be awesome not to have to use it.

GollyJer avatar Apr 13 '22 14:04 GollyJer

Yeah, it would be great if this issue could get a fix. I frequently use a function pattern similar to that in the OP, and I really miss the syntax highlighting, linting and autocompletion.

caffeinated-pixels avatar Oct 31 '22 17:10 caffeinated-pixels

Still experiencing this on vscode

techdan-to avatar Apr 22 '23 10:04 techdan-to