--
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';
export default class Hello extends React.Component {
/* javascript constructor */
constructor (props) {
super(props);
}
/* css constructor */
@css`
font-size: 16px;
text-align: center;
color: {this.props.color};
font-family: monospace;
`
render () {
return <div>Styled {this.props.color} text!</div>
}
};
// <Hello color='papayawhip'/>
--
Features:
π Supports real css
π₯ use props in css
πΌ Attaches inline styles to the highest element in your component
πΆ Super tiny: only 1.4K gzipped
π Offical library emoji
--
Coming soon
π classes instead of inline styles
π pseudo selectors
π± media queries support
π» vendor prefixes
πͺ nested css
--
-
npm install css-constructor --save
-
Add a
@css
block just before therender
function (important) -
Add
transform-decorators-legacy
as the firstplugin
in 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.
--
You can start using this right away. Even though π is in BETA
, the @css
block will always look the same.
π uses ES7 class method decorators on the render function. I'll probably write a detailed post about it.
Heavily inspired from glamor, styled-components and radium
If you think π is useful for your project, βοΈ this repo for my motivation ππ»