Coder Social home page Coder Social logo

Comments (21)

jonlambert avatar jonlambert commented on July 24, 2024 7

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.

from tailwind-rn.

matepapp avatar matepapp commented on July 24, 2024 6

I have an idea of how to support a typed API, but we have to migrate to TypeScript in that case. From TypeScript 2.9 you can import JSON modules in TS files with full typed support. We can create a tailwind() method where we expose the keys of the JSON and get amazing autocompletion and type-safety ✨

Screenshot 2020-05-19 at 16 39 32

Screenshot 2020-05-19 at 16 39 57

from tailwind-rn.

ecklf avatar ecklf commented on July 24, 2024 6

@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

from tailwind-rn.

ecklf avatar ecklf commented on July 24, 2024 4

There is now a way to achieve this with the official VSCode extension.
https://twitter.com/ecklflorentin/status/1344242188574720000

from tailwind-rn.

tommulkins avatar tommulkins commented on July 24, 2024 1

To make intellisense work in a tailwind-rn project, i.e. style={tailwind('mb-1')} I use the following:

  /* TailwindCSS */
  "tailwindCSS.experimental.classRegex": ["tailwind\\('([^)]*)\\')", "'([^']*)'"]

from tailwind-rn.

matepapp avatar matepapp commented on July 24, 2024

Yes, this was only just a quick example to demonstrate the possibility of type-safety. Your solution is definitely a step ahead, but I think we should support regular string type as well to keep the API backward compatible. Switching based on the type could be a temporary workaround. What do you think?

I might can create a draft pull request next week if it’s okay for you @vadimdemedes

from tailwind-rn.

ecklf avatar ecklf commented on July 24, 2024

Well we could either add an additional function to the core or add readme instructions on how to achieve this with a custom tailwind function (would be neat if useVariables would get exported then). I think the opt-in instruction might be the better choice since it wouldn't force the codebase to TypeScript.

from tailwind-rn.

vadimdemedes avatar vadimdemedes commented on July 24, 2024

@matepapp Yeah, I think something like that would work. Would be still great to preserve support for specifying multiple classes in one string for people that don't care about autocomplete (like me).

The only thing I'm wondering about is how will it work with custom configs?

from tailwind-rn.

tommulkins avatar tommulkins commented on July 24, 2024

@vadimdemedes You may be interested in following this Tailwind Intellisense issue (https://github.com/tailwindcss/intellisense/issues/129) in regards to this.

from tailwind-rn.

vadimdemedes avatar vadimdemedes commented on July 24, 2024

@tommulkins Thanks for linking it here!

from tailwind-rn.

leggomuhgreggo avatar leggomuhgreggo commented on July 24, 2024

I think this might have just become more feasible with the improvements in TS 4.1

https://twitter.com/diegohaz/status/1309489079378219009

from tailwind-rn.

gitstud avatar gitstud commented on July 24, 2024

Is there a PR on the horizon for this?

from tailwind-rn.

ecklf avatar ecklf commented on July 24, 2024

I think we can close this issue πŸ‘πŸ»

from tailwind-rn.

lyzMaster avatar lyzMaster commented on July 24, 2024

I must run npm install tailwindcss to have Tailwind CSS IntelliSense autocomplete feature, can I ignore this step?

from tailwind-rn.

ecklf avatar ecklf commented on July 24, 2024

I must run npm install tailwindcss to have Tailwind CSS IntelliSense autocomplete feature, can I ignore this step?

Afaik you only need a tailwind.config.js in your project root for IntelliSense to work.

from tailwind-rn.

tommulkins avatar tommulkins commented on July 24, 2024

I must run npm install tailwindcss to have Tailwind CSS IntelliSense autocomplete feature, can I ignore this step?

You can run npx tailwindcss init instead to make your tailwind.config.js file.

from tailwind-rn.

lyzMaster avatar lyzMaster commented on July 24, 2024

I must run npm install tailwindcss to have Tailwind CSS IntelliSense autocomplete feature, can I ignore this step?

You can run npx tailwindcss init instead to make your tailwind.config.js file.

Before this, I have run npx tailwindcss init and so I got tailwind.config.js, but IntelliSense still not work and I got this error in the OUTPUT of vscode(I tried restarting vscode):
ζˆͺ屏2021-06-24 上午11 58 26

And I check out doc of Tailwindcss IntelliSense, which says: In order for the extension to activate you must have tailwindcss installed and a Tailwind config file named tailwind.config.js in your workspace.. So I try npm install tailwindcss, and after restarting vscode, autocomplete works. So I guess maybe IntelliSense check package.json -> dependencies, if "tailwindcss" in dependencies, IntelliSense works?

from tailwind-rn.

ecklf avatar ecklf commented on July 24, 2024

Seems you need to have it installed then. Note that the autocomplete will adhere to your tailwind configuration and not to tailwind-rn's compatibility limitations. You can disable core plugins for this.

from tailwind-rn.

harshjadon9 avatar harshjadon9 commented on July 24, 2024

To make intellisense work in a tailwind-rn project, i.e. style={tailwind('mb-1')} I use the following:

  /* TailwindCSS */
  "tailwindCSS.experimental.classRegex": ["tailwind\\('([^)]*)\\')", "'([^']*)'"]

this isn't working for me...

i have pasted the above in setting.json

My tailwind.js

import { create } from 'tailwind-rn';
import styles from '../styles.json';

const { tailwind, getColor } = create(styles);
export { tailwind, getColor };

My home.js

...
import { getColor, tailwind } from '../tailwind';

const home = () =>{
    return(
        <View>
            <Text>hi there</Text>
            <Text style={tailwind('mb-1')}>hi there</Text>
        </View>
    )
}

export default home

@tommulkins , @jonlambert or anyone could please resolve this

from tailwind-rn.

tommulkins avatar tommulkins commented on July 24, 2024

To make intellisense work in a tailwind-rn project, i.e. style={tailwind('mb-1')} I use the following:

  /* TailwindCSS */
  "tailwindCSS.experimental.classRegex": ["tailwind\\('([^)]*)\\')", "'([^']*)'"]

this isn't working for me...

i have pasted the above in setting.json

My tailwind.js

import { create } from 'tailwind-rn';
import styles from '../styles.json';

const { tailwind, getColor } = create(styles);
export { tailwind, getColor };

My home.js

...
import { getColor, tailwind } from '../tailwind';

const home = () =>{
    return(
        <View>
            <Text>hi there</Text>
            <Text style={tailwind('mb-1')}>hi there</Text>
        </View>
    )
}

export default home

@tommulkins , @jonlambert or anyone could please resolve this

I currently use tailwind-react-native-classnames with the following regex settings in my project:

vscode/settings.json

{
  /* TailwindCSS */
  "tailwindCSS.experimental.classRegex": [
    "tw`([^`]*)",
    "`([^`]*)",
    ["tw.style\\(([^)]*)\\)", "'([^']*)'"]
  ]
}

I believe that last value in the array will do the trick, "'([^']*)'"

from tailwind-rn.

karimessouabni avatar karimessouabni commented on July 24, 2024

You need to open the VS Code setting file as a json. It should be under this Path (~/Library/Application Support/Code/User/settings.json)

Then if you're using "import tw from 'twrnc';" and your code looks like style={tw'min-w-full '}

update the section of tailwind on your setting file as follows :

"tailwindCSS.classAttributes": [ "class", "className", "ngClass" ], "tailwindCSS.experimental.classRegex": ["style={tw\\('|\"([^'|\")]*)"], "tailwindCSS.experimental.configFile": null

from tailwind-rn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.