styled-components / styled-components

Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress 💅
https://styled-components.com
MIT License
40.12k stars 2.48k forks source link

Examples React Native #4263

Open Wanderson77 opened 2 months ago

Wanderson77 commented 2 months ago

Hello devs, is there any example directory ready for React Native, or do we just have documentation to learn how to use this library?

Thanks!!!!

mannoeu commented 3 weeks ago

Hello devs, is there any example directory ready for React Native, or do we just have documentation to learn how to use this library?

Thanks!!!!

It works exactly the same as styled-components for the web. The only difference is when creating styled components:

import styled from "styled-components/native";

export const MyButton = styled.TouchableOpacity`
  background-color: black;
  padding: 20px;
`;

You may need to use some CSS commands that only work for react native, such as margin-horizontal, padding-vertical, elevation etc. If you're using typescript-styled-plugin, add this code in jsconfig or tsconfig to prevent these CSS properties from reporting an error.

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