Code Monkey home page Code Monkey logo

integratedcss's Introduction

IntegratedStyle

After integrating HTML into JavaScript by React.js, a logical next step is to do the same for CSS.

Build with help of the awesome recast library.

Example

var IntegratedStyle = require('IntegratedStyle');
var vars = require('./vars');
var mixins = require('./mixins');

var Button = React.createClass({

  normal: IntegratedStyle(function() {
    return Object.assign({
      backgroundColor: vars.black
    }, mixins.transparent);
  }),

  hover: IntegratedStyle(function() {
    return {
      backgroundColor: 'white'
    };
  }),

  getInitialState: function() {
    return {
      hover: false
    };
  },

  render: function() {
    var style = this.state.hover ? this.normalStyle() : this.hoverStyle();
    return <div style={style}>Example</div>;
  },

  onMouseOver: function() {
    this.setState({hover: true});
  }

});

Turns into:

css
---
.a {
  background-color: 'black';
  opacity: 0.1;
}
.b  {
  background-color: 'white';
}

js
--
var Button = React.createClass({

  normal: function() {
    return "a";
  },

  hover: function() {
    return "b";
  },

  getInitialState: function() {
    return {
      hover: false
    };
  },

  render: function() {
    var style = this.state.hover ? this.normalStyle() : this.hoverStyle();
    return <div style={style}>Example</div>;
  },

  onMouseOver: function() {
    this.setState({hover: true});
  }

});

Motivation

CSS is problematic to maintain and components give all the borders you actually need.

What does it actually do?

  • It takes out the css function and transform it into plain CSS
  • The css function is executed on its own, it has no reference to 'this'
  • connect the (something.)css().something blocks to CSS
  • create CSS with annoyingly small CSS className selectors (3 characters max - up to 140608 classes)
  • CSS is coupled to the component and can be passed to another component via props (aProp={this.css().something})
  • isn't smart about actual references to the CSS function

Usage

integrated-css --input=example/**/*.js --output=build/ --css=build/styling/lala.css

Other options

Biggest difference here is that IntegratedStyle is a CSS + JS preprocessor solution instead of a runtime solution.

Also there is (from the React.js team):

LICENSE

MIT

integratedcss's People

Contributors

andreypopp avatar sanderspies avatar

Watchers

 avatar  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.