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.

Typed classnames for autocompletion

See original GitHub issue

I like this API the most from the available Tailwind / RN projects but it’s a bit sad to lose the ability for auto-completion.

What about going from this:

tailwind('bg-blue-200 px-3 py-1 rounded-full')

to something like this:

tailwind('bg-blue-200', 'px-3', 'py-1', 'rounded-full')

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:12
  • Comments:20 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
jonlambertcommented, Apr 18, 2021

For those who want a quick copy and paste:

"tailwindCSS.experimental.classRegex": ["tailwind\\('|\"([^'|\")]*)"]

^ add to your VS Code settings.json file. I’ve adjusted the regex to pick up single or double quotes.

6reactions
ecklfcommented, May 19, 2020

@matepapp nice find!

However, I can’t think of a sensible TypeScript solution that would not require the API change I mentioned above. Your current implementation would only allow one className in the tailwind function unless you generate all combinations of className strings.

My proposal would look something like this:

import JSON from "./styles.json";
type Keys = keyof typeof JSON;

const tailwind = (...props: Keys[]) => {
  return props.reduce(
    (styles, curr) => ({
      ...styles,
      ...JSON[curr],
    }),
    {}
  );
}

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

VSCode - Autocomplete/Suggest user-typed CSS class names?
Does anyone know if there is a way to have VSCode autocomplete/suggest CSS class names that the user has typed in the document?...
Read more >
How to Autocomplete CSS class names that include a minus ...
Inside my HTML files I want to autocomplete these class names. But when I type <span class="mAIcon mA|">. and I want to autocomplete...
Read more >
Code Completion for classnames and clsx libraries in React ...
Spend less time typing or explore the possibilities for various CSS class names in React aps.
Read more >
Find & Auto-Complete Class Names Quickly in Code - YouTube
Working with CSS can be time consuming and slow process specially when project gets bigger. When you add more and more classes to...
Read more >
Typeahead class names (auto-completion) - Squiz Help Center
... that wraps highlighted text. Defaults to tt-highlight . Source: https://github.com/twitter/typeahead.js/blob/master/doc/jquery_typeahead.md#class-names ...
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