Skip to content

Instantly share code, notes, and snippets.

@dwighthouse
Last active August 29, 2015 14:25
Show Gist options
  • Save dwighthouse/1749d6053f7efebaedba to your computer and use it in GitHub Desktop.
Save dwighthouse/1749d6053f7efebaedba to your computer and use it in GitHub Desktop.
New attempt to add helper function to react-jss.
'use strict';
var _ = require('lodash');
// JSS styling
var jss = require('jss').create();
// Order matters!
// https://github.com/jsstyles/jss-camel-case/issues/1
jss.use(require('jss-extend'));
jss.use(require('jss-nested'));
jss.use(require('jss-camel-case'));
jss.use(require('jss-vendor-prefixer'));
var jssReact = require('react-jss')(jss);
module.exports = function() {
arguments[0].prototype.css = function() {
var classes = _.get(this, 'props.sheet.classes', {});
return _.map(arguments, value => {
if (_.isPlainObject(value))
{
return _.chain(value).pick(_.identity).keys().map(value => (classes[value] || value)).value().join(' ');
}
if (_.isString(value))
{
return classes[value] || value;
}
return '';
}).join(' ');
};
return jssReact(...arguments);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment