siddharthkp / css-constructor

💄 CSS constructor for React components

Home Page:https://codesandbox.io/s/jl5jp0y5nw

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Alternative syntax (without decorators/babel transform)

siddharthkp opened this issue · comments

Alternate syntax

✅ No decorators = no extra babel transforms
✅ CSS constructor looks like other class methods
✅ Position independent (don't have to place it right above render)
⚠️ Code is more verbose
⚠️ Adds a wrapper

import React from 'react';
import css from 'css-constructor';

class Hello extends React.Component {

    /* javascript constructor */
    constructor (props) {
        super(props);
    }

    /* css constructor */
    css (props) {
        return `
            font-size: 16px;
            text-align: center;
            color: {this.props.color};
            font-family: monospace;
        `;
    }

    render () {
        return <div>Styled {this.props.color} text!</div>
    }
};

export default css(Hello);