question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hightlighting doesn't work with nested template string and with css helper.

See original GitHub issue
  1. Doesn’t highlight code if I use a tagged template inside the template string (see middle image) (#254 ).
  2. The above problem (1) can be solved by using css helper before the tagged template.
  3. The above solution (2) cause highlight not to work further down (see right screenshot)

(The solution does work well on codesandbox but not in vscode - see here)

Screenshot image

Code for left & middle screenshots:

const box1 = styled.div`
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-column: 6/11;
  color: ${myColor};
  color: red;
  ${
    setMediaQuery('big')`
      display: grid;
      color: ${myColor};
      color: red;
      grid-column: 6/11;
      grid-template-columns: repeat(9, 1fr);
    `
  }

  ${
    setMediaQuery('medium')`
      display: grid;
      grid-template-columns: repeat(9, 1fr);
      grid-column: 6/11;
      color: red;
    `
  }
`;

const box2 = styled.div`
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-column: 6/11;
  color: ${myColor};
`;

export default {
  box1,
  box2,
};

Code for the right screenshot:

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

const myColor = '#333';

export const setMediaQuery = (breakpoint) => {
  switch (breakpoint) {
    case 'small':
      return (style) => `@media (max-width: 800px) { ${style} }`;
    case 'medium':
      return (style) => `@media (min-width: 801px) (max-width: 1200) { ${style} }`;

    default:
      return (style) => `@media (min-width: 1201px) { ${style} }`;
  }
};

const box1 = styled.div`
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-column: 6/11;
  color: ${myColor};
  color: red;
  ${
    setMediaQuery('big')(css`
      display: grid;
      color: ${myColor};
      color: red;
      grid-column: 6/11;
      grid-template-columns: repeat(9, 1fr);
    `)
  }

  ${
    setMediaQuery('medium')(css`
      display: grid;
      grid-template-columns: repeat(9, 1fr);
      grid-column: 6/11;
      color: red;
    `)
  }
`;

const box2 = styled.div`
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-column: 6/11;
  color: ${myColor};
`;

export default {
  box1,
  box2,
};
  • OS: Win 10
  • VSCode Version: 1.52.0
  • Extension Version 1.4.1

Thanks!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:10

github_iconTop GitHub Comments

1reaction
Avivhdrcommented, Aug 12, 2021

Hi @ndeviant,

See https://github.com/styled-components/vscode-styled-components/issues/304 or this codepen.

TLDR: You can pass your styles to the built-in css helper:

import styled, { css } from "styled-components";

const TextSmall = styled(Typography)(css`
   font-size: 0.75 rem;
   margin-bottom: 12pc;
`)
1reaction
Avivhdrcommented, Dec 14, 2020

Thanks @stg101

Read more comments on GitHub >

github_iconTop Results From Across the Web

Highlighting nested Markdown, and within JavaScript template ...
I'm curious if there is a better way to do this. CodeMirror 6 handles it quite well, though, so mostly I'd just like...
Read more >
VSCODE Javascript template string become white and lost ...
In some cases, apparently random, when using JavaScript string templates, the text editor loses becomes white, with bold text and makes editing ...
Read more >
Syntax Highlight Guide | Visual Studio Code Extension API
A guide to syntax highlighting. ... Tokens are used for syntax highlighting, but also to classify the source code into areas of comments,...
Read more >
Template literals (Template strings) - JavaScript | MDN
In certain cases, nesting a template is the easiest (and perhaps more readable) way to have configurable strings. Within a backtick-delimited ...
Read more >
Pandoc User's Guide
It is possible to supply a custom User-Agent string or other header when requesting a ... epub.css , templates ) will override pandoc's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found