Skip to content

floatdrop/react-styled

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-styled Build Status

⚠️ Highly experimental tool for applying styles to React components.

TODO:

  • Proper CSS matching
  • Pass props to selector matching
  • Pass state to selector matching
  • Implement className generation in cases when :before is used
  • Implement <style> tag generation for custom classes

Usage

index.css:

button {
	border: 1px solid #eee;
}

button span {
	color: blue;
}

button[pressed="yes"] span {
	color: red;
}

index.jsx:

var React = require('react');
var Styled = require('react-styled');

// Somehow get index.css contents, webpack for example:
var styled = new Styled(require('css-loader!./index.css').toString());

var Button = React.createClass({
	getInitialState: function() {
		return {hovered: 'no'};
	},

	mouseLeave: function () {
		this.setState({hovered: 'no'});
	},

	mouseEnter: function () {
		this.setState({hovered: 'yes'});
	},

	render: styled(function () {
		return (
			<button onMouseEnter={this.mouseEnter} onMouseLeave={this.mouseLeave}>
				<span>
					{this.props.children}
				</span>
			</button>
		);
	})
});

How does it works

Magic.

API

Styled(css)

Returns decorator Function for wrapping render method of React component.

Not so much yet.

License

MIT © Vsevolod Strukchinsky

About

⚠️ Highly experimental tool for applying styles to React components

Resources

Stars

Watchers

Forks

Packages

No packages published