Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Support for React-Native specific properties #58

Closed
pavsidhu opened this issue Jun 10, 2018 · 20 comments
Closed

Support for React-Native specific properties #58

pavsidhu opened this issue Jun 10, 2018 · 20 comments

Comments

@pavsidhu
Copy link

There are several CSS properties that are specific to React-Native that are supported by styled-components/native. For example the following properties are part of React-Native but appear as errors when using this plugin:

const Main = styled.View`
  shadow-color: black;
  shadow-opacity: 0.5;
  shadow-offset: 2px 2px;
`

Would React-Native specific properties be something to consider supporting?

@mjbvz
Copy link
Contributor

mjbvz commented Oct 29, 2018

This is now possible using the css-language-service api: microsoft/vscode-css-languageservice#111

This plugin can automatically contribute a list of valid react-native style properties. PRs welcome. Let me know if you have any questions about implementing this

@alvincrespo
Copy link

More than happy to help here. @mjbvz Is there a guide on how to add these properties?

@mjbvz
Copy link
Contributor

mjbvz commented Nov 7, 2018

Pass a list of validProperties to the language services, here I believe.

@lidonghua
Copy link

lidonghua commented Dec 6, 2018

After inspecting source code of the plugin, I managed to find a working solution.

Edit your tsconfig.json like this:

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-styled-plugin",
        "lint": {
          "validProperties": "shadow-color,shadow-opacity,shadow-offset"
        }
      }
    ]
  }
}

Maybe it helps.

@ScreamZ
Copy link

ScreamZ commented Feb 14, 2019

Any news on this ?

@kallaspriit
Copy link

Workaround provided by @lidonghua kind of works, does anyone have an exhaustive list of react-native specific properties to use until these become supported?

@ScreamZ
Copy link

ScreamZ commented Feb 19, 2019

@kallaspriit You can add tint-color but I guess it's a step by step process once you get an error…

@DriesVS
Copy link

DriesVS commented Mar 11, 2019

@kallaspriit so far I have:
shadow-color,shadow-opacity,shadow-offset,padding-horizontal,padding-vertical,margin-vertical,margin-vertical,tint-color,aspect-ratio,elevation

@sregg
Copy link

sregg commented Apr 23, 2019

This works for me:

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-styled-plugin",
        "lint": {
          "validProperties": [
            "shadow-color",
            "shadow-opacity",
            "shadow-offset",
            "shadow-radius",
            "padding-horizontal",
            "padding-vertical",
            "margin-vertical",
            "margin-horizontal",
            "tint-color",
            "aspect-ratio",
            "elevation"
          ]
        }
      }
    ]
  }
}

notice validProperties is an actual array, not a csv string

@dimaip
Copy link

dimaip commented Oct 4, 2019

Now how do you disallow properties which are not supported by RN, e.g. box-shadow?

@mjbvz
Copy link
Contributor

mjbvz commented Oct 4, 2019

Could someone please submit a PR that documents validProperties

@arnaudambro
Copy link

arnaudambro commented Oct 17, 2019

So I have this warning too in VSCode: Unknown property: 'shadow-radius' ts-styled-plugin(9999)

I set up a tsconfig.json file but actually I don't use TypeScript ! Anyway, this file did not change a thing for me. I also installed stylelint but it didn't change either, still the warning.

Any idea ?

I updated the properties for those in needs

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-styled-plugin",
        "lint": {
          "validProperties": [
            "aspect-ratio",
            "elevation",
            "margin-vertical",
            "margin-horizontal",
            "padding-horizontal",
            "padding-vertical",
            "resize-mode",
            "shadow-color",
            "shadow-opacity",
            "shadow-offset",
            "shadow-radius",
            "text-align-vertical",
            "tint-color"
          ]
        }
      }
    ]
  }
}

@robinmetral
Copy link

robinmetral commented Jan 6, 2020

If your project isn't using TypeScript, create a jsconfig.json instead of a tsconfig.json.

Sample jsconfig.json (at the root of your project):

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-styled-plugin",
        "lint": {
          "validProperties": [
            "aspect-ratio",
            "elevation",
            "margin-vertical",
            "margin-horizontal",
            "padding-horizontal",
            "padding-vertical",
            "resize-mode",
            "shadow-color",
            "shadow-opacity",
            "shadow-offset",
            "shadow-radius",
            "text-align-vertical",
            "tint-color"
          ]
        }
      }
    ]
  }
}

@GollyJer
Copy link

GollyJer commented Jun 30, 2020

Hey all. This issue was super helpful to fix missing react-native properties. Thanks! 👍

My next question...
Is there a way to say "only show these properties" in the auto-complete. From time to time I find myself accidentally using web properties while in a React Native project. I'd love for the auto-complete to only show valid React Native properties.

I can put the list together but not sure if there's a place to put it. 😃
Is this possible? Thanks.

👉 Equivalent StackOverflow Question

@rayonnunes
Copy link

rayonnunes commented Nov 24, 2020

You can also disable the warnings for unknown properties (at your own risk of losing some intellisense) adding in your tsconfig.json:

"compilerOptions": {
    "plugins": [
      {
        "name": "typescript-styled-plugin",
        "lint": {
          "unknownProperties": "ignore" // "ignore" | "warning" | "error"
        }
      }
    ]
}

Referring the official documentation: https://github.com/microsoft/typescript-styled-plugin#unknownproperties

@lcustodio
Copy link

Any updates on this?
Typescript + Styled Components + React Native still not working

@ali-soltanii
Copy link

This is the list I'm using.

      {
        "name": "typescript-styled-plugin",
        "lint": {
          "validProperties": [
            "shadow-color",
            "shadow-opacity",
            "shadow-offset",
            "shadow-radius",
            "padding-horizontal",
            "padding-vertical",
            "margin-vertical",
            "margin-horizontal",
            "tint-color",
            "aspect-ratio",
            "elevation",
            "include-font-padding",
            "text-align-vertical"
          ]
        }
      }
    ]

@pke
Copy link

pke commented Nov 7, 2022

Been 4 years. Are there any plans to add this to the official distribution config?

@karlhorky
Copy link

karlhorky commented Nov 21, 2022

@mjbvz Ok, since I'm also having this problem with vscode-styled-components.

I'm not sure if I'm doing this contribution correctly, but I opened a PR over here, only for the standard aspect-ratio property:

@mjbvz
Copy link
Contributor

mjbvz commented Apr 4, 2023

Closing as this package has been deprecated in favor of the official styled-components/typescript-styled-plugin fork

After updating to that fork, follow up in the styled-components repo if this is still an issue

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.