Load Stylus files to react native style objects.
This transformer can be used together with React Native CSS modules.
yarn add --dev react-native-stylus-transformer stylus
Add this to your rn-cli.config.js
(make one if you don't have one already):
module.exports = {
getTransformModulePath() {
return require.resolve("react-native-stylus-transformer");
},
getSourceExts() {
return ["js", "jsx", "styl"];
}
};
...or if you are using Expo, in app.json
:
{
"expo": {
"packagerOpts": {
"sourceExts": ["js", "jsx", "styl"],
"transformer": "node_modules/react-native-stylus-transformer/index.js"
}
}
}
Your App.styl
file might look like this:
.myClass {
color: blue;
}
.myOtherClass {
color: red;
}
.my-dashed-class {
color: green;
}
When you import your stylesheet:
import styles from "./App.styl";
Your imported styles will look like this:
var styles = {
myClass: {
color: "blue"
},
myOtherClass: {
color: "red"
},
"my-dashed-class" {
color: "green"
}
};
You can then use that style object with an element:
<MyElement style={styles.myClass} />
<MyElement style={styles["my-dashed-class"]} />