css-constructor v0.1.7

Ā
Every React component gets an inbuilt javascript constructor for functional logic.
Introducing the css constructor for styling!
Ā Ā
import React from 'react';
import css from 'css-constructor'; // š¶ Super tiny: only 1.2K gzipped!
export default class Hello extends React.Component {
/* javascript constructor */
constructor (props) {
super(props);
}
/* css constructor */
@css` // š Isolated and co-located
font-size: 16px;
text-align: center; // š Supports the entirety of CSS
color: {this.props.color}; // š„ Use props in css
display: flex; // š» Built in vendor prefixing
&:hover { // š Pseudo selectors
color: #FFF;
}
img { // šŖ Nested css
border-radius: 50%;
}
#handle {
margin-top: 20px;
}
@media (max-width: 600px) { // š± Media queries support
& {font-size: 18px;}
}
`
render () {
return (<div> // š¼ Attaches class to the highest element
<img src="https://github.com/siddharthkp.png"/>
<div id="handle">@siddharthkp</div>
</div>)
}
};
// <Hello color='papayawhip'/>--
Other features
š Uses classes instead of inline styles
š§ Editable in developer tools
š¶ Super tiny: only 1.2K gzipped!
š Official library emoji
Coming soon
š server side rendering
--
Usage
npm install css-constructor --saveimport css from 'css-constructor'Add a
@cssblock just before therenderfunction (important)Add
transform-decorators-legacyas the firstpluginin your.babelrc(already downloaded with š).
If you are not familiar with babel plugins you can follow the detailed instructions here.
Or, if you would prefer using š without adding the babel transform for decorators, up-vote this issue.
--
How does it work?
š uses ES7 class method decorators on the render function. Detailed post coming soon.
Inspiration
Heavily inspired from glamor, styled-components and radium
Special thanks to thysultan. stylis is the bomb!
Support
āļø this repo!