Code Monkey home page Code Monkey logo

cssobjectify's Introduction

cssobjectify

Source transform for browserify or dcompose which converts CSS into JSON objects which can be used further by libraries like React to assign styles to UI components.

styles.css:

MyComponent {
  font-size: 12px;
  background-color: red;
}

myapp.js:

var React = require('react-tools/build/modules/React');
var Styles = require('./styles.css');

var MyComponent = React.createClass({
  render: function() {
    return (
      <div style={Styles.MyComponent}>
        Hello, world!
      </div>
    )
  }
});

Usage

Use npm to install the package:

% npm install cssobjectify

And use it with browserify:

% browserify -t cssobjectify ./myapp.js

where ./myapp.js or its dependencies can reference *.css files by require(...) calls.

cssobjectify's People

Contributors

andreypopp avatar yocontra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cssobjectify's Issues

pseudo-selectors

Not sure how to solve this problem. pseudo-selectors can't be done inline

Question about your example/module

Hello,

I'm trying to understand this module, but can't wrap my head about how it could be useful based on your example. Instead of using this transform and assigning the styles parsed to style property of the div (inline styles ? really ?), I would have used another transform, cssify that is still require()d in my React component code, but instead inject the styles in the head tag, so I can confidently use the styles in it as classes for the React component. In what circumstances should I prefer cssobjectify over cssify ?

This is not a rant/troll/whatever-bad-attitude. I'm preparing a talk about Browserify for my local user group (http://parisjs.org/) and I'm starting to use it professionally. So basically I'm just evaluating the different possibilities that Browserify and its ecosystem provide.

Thanks in advance.

CSS preprocessors

This is totally not the right place for this, but I think it would be extremely cool to be able to use this with preprocessors. I'm not sure if browserify supports transform chains (for example, a .styl file should go through stylus then cssobjectify) but we could probably make something to enable this behavior.

var Styles = require('./Component.styl');

would be amazing, and you could plug in stuff like nib to take care of vendor prefixes + cross-browser for you

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.