Skip to content

siddharthkp/css-constructor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CSS constructor πŸ’„ for React components

beta

--

Every React component gets a 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: #5AF78E;
        font-family: monospace;
    `

    render () {
        return <div>Styled text!</div>
    }
};

--

Features:

πŸŽ€ Supports real css

πŸ”₯ use props in css

πŸ”Ό Attaches inline styles to the highest element in your component

πŸ’„ Offical library emoji

--

Coming soon

πŸ™‹ classes instead of inline styles

πŸŒ€ pseudo selectors

πŸ“± media queries support

πŸ‘ͺ nested css

--

Usage

  1. npm install css-constructor --save

  2. Add a @css block just before the render function (important)

  3. Add transform-decorators-legacy as the first plugin in your .babelrc. It is already downloaded with πŸ’„; If you are not familiar with babel plugins you can follow the detailed instructions here.

You can start using this right away. Even though πŸ’„ is in BETA, the @css block will always look the same.

How does it work?

πŸ’„ uses ES7 class function decorators on the render function. I'll probably write a detailed post about it.

Inspiration

Heavily inspired from glamor, styled-components and radium

Support

If you think πŸ’„ is useful for your project, ⭐️ this repo for my motivation πŸ™‡πŸ»