Giter VIP home page Giter VIP logo

native-css's Introduction

native-css

Convert pure CSS to javascript literal objects or React Style.

NPM Version Build Status

Before Anything!

This tool believes in this semantic for CSS: HTML semantics and front-end architecture

'Cause of this, all ids and inheritance relationships are converted to classes.

Install

Verify if you have node and npm installed.

As CLI
$ npm install -g native-css
As Node Module
$ npm install native-css

CLI Usage

Params: input (required), output (optional)

$ native-css <input> <output>

Example

Input CSS Example:

.taxi {
	backgroundColor: #F8F8F8;
	color: #999;
}

#car {
	color: blue;
}

Convert CSS to React Format

Using:

$ native-css <input> <output> --react

Generate this as output (JS format):

var styles = StyleSheet.create({
  taxi: {
    color: '#999',
    backgroundColor: '#F8F8F8'
  },
  car {
	color: 'blue';
  }
});

Convert CSS to Literal JS object

Using, but without react flag:

$ native-css <input> <output>

Generate this as output (JS format):

styles: {
  taxi: {
    color: '#999',
    backgroundColor: '#F8F8F8'
  },
  car {
	color: 'blue';
  }
}

Module Usage

var nativeCSS = require('native-css'),
	pathToCssFile = 'somePath/file.css';

// Generate JavaScript Object
var cssObject = nativeCSS.convert(pathToCssFile);

Not supported CSS features

React Style does not support CSS selectors, pseudo-classes and CSS animation. Mostly because we try to avoid implicit behaviour and want the user to make layout decisions inside the render() function.

CSS selectors introduce implicit behaviour by not having a direct link with the elements on which they're applied. Therefore there is no way of knowing what the consequences are, and this easily leads to refactoring issues. Instead you should be using plain JavaScript variables.

Classes with pseudo-classes have a higher precedence then classes with no pseudo-classes, which results in issues if you want to override styling in "higher-level" components. In some cases(:before, after, etc.) a component is easily added, in others (active, focus, hover, etc) plain JavaScript will do the trick. In all, you don't need CSS for this. In some cases though you might want to use pseudo-classes (like styling a scrollbar) - which we do support.

Animations inside CSS also introduce implicit behaviour, as CSS animations are decoupled from logic. By being decoupled, the state of the component is split between the component and the CSS animation. We however believe state should be contained within a component. An example of solving this using JS is React Magician.

Contributing

Don't be shy, send a Pull Request! Here is how:

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -m 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

About

License: MIT ® Raphael Amorim

native-css's People

Contributors

raphamorim avatar

Watchers

James Cloos avatar  avatar

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.