diego-d5000 / Css2React

Style React-Native components with css and built in support for SASS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

react-native-css (and SCSS) Circle CI NPM

React-native-css turns valid CSS/SASS into the Facebook subset of CSS.

Install

Global

npm install react-native-css -g

Command Line Interface

React-native-css comes with a cli and you can watch a file and compile it.

# example 1
react-native-css -i INPUT_CSS_FILE -o OUTPUT_JS_FILE --watch
# example 2
react-native-css -i INPUT_CSS_FILE -o OUTPUT_JS_FILE --watch --pretty
# example 3
react-native-css INPUT_CSS_FILE OUTPUT_JS_FILE -w
react-native-css -i style.css -o style.js -w

Flags

  • "-w" or "--watch" - watch for changes and recompile.
  • "-i" takes a input (optional)
  • "-o" takes an output path (optional)
  • "-p" or "--pretty" - pretty print the resulting compiled output

Screenshot

the workflow

Example

Given the following CSS:

description {
  margin-bottom: 20;
  font-size: 18;
  text-align: center;
  color: #656656;
}

container {
  padding: 30;
  margin-top: 65;
  align-items: center;
}

React-native-css will generate to the following:

// style.js
module.exports = require('react-native').StyleSheet.create(
  {"description":{"marginBottom":20,"fontSize":18,"textAlign":"center","color":"#656656"},"container":{"padding":30,"marginTop":65,"alignItems":"center"}}
  );

Usage

// require the generated style file
var styles = require('./style.js')
 //{"description":{"marginBottom":20,"fontSize":18,"textAlign":"center","color":"#656656"},"container":{"padding":30,"marginTop":65,"alignItems":"center"}}


class SearchPage extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.description}>
        Buy
        </Text>

      </View>
    );
  }
}

About

Style React-Native components with css and built in support for SASS


Languages

Language:JavaScript 96.2%Language:CSS 3.0%Language:Shell 0.9%