1.0.53 • Published 6 months ago

babel-plugin-transform-jsx-to-hy-stylesheet v1.0.53

Weekly downloads
59
License
MIT
Repository
-
Last release
6 months ago

babel-plugin-transform-jsx-hy-stylesheet

Transform StyleSheet selector to style in JSX Elements for hycss.

Installation

npm install --save-dev babel-plugin-transform-jsx-to-hy-stylesheet

Usage

Via .babelrc

.babelrc

{
  "plugins": ["transform-jsx-to-hy-stylesheet"]
}

Example

Your component.js that contains this code:

import { Component } from 'React';
import './app.hycss';
class App extends Component {
  render() {
    return <div className="header" />
  }
}

Will be transpiled into something like this:

import { Component } from 'React';
import appStyleSheet from './app.hycss';

class App extends Component {
  render() {
    return <div style={styleSheet.header} />;
  }
}

const styleSheet = appStyleSheet;

Can write multiple classNames like this:

import { Component } from 'React';
import './app.hycss';

class App extends Component {
  render() {
    return <div className="header1 header2" />;
  }
}

Will be transpiled into something like this:

import {  Component } from 'React';
import appStyleSheet from './app.hycss';

class App extends Component {
  render() {
    return <div style={[styleSheet.header1, styleSheet.header2]} />;
  }
}

const styleSheet = appStyleSheet;

Also support array, object and expressions like this:

import { Component } from 'React';
import './app.hycss';

class App extends Component {
  render() {
    return (
      <div className={'header'}>
        <div className={{ active: this.props.isActive }} />
        <div className={['header1 header2', 'header3', { active: this.props.isActive }]} />
        <div className={this.props.visible ? 'show' : 'hide'} />
        <div className={getClassName()} />
      </div>
    );
  }
}

Will be transpiled into something like this:

import { Component } from 'React';
import appStyleSheet from './app.hycss';

class App extends Component {
  render() {
    return (
      <div style={styleSheet.header}>
        <div style={_getStyle({ active: this.props.isActive })} />
        <div style={_getStyle(['header1 header2', 'header3', { active: this.props.isActive }])} />
        <div style={_getStyle(this.props.visible ? 'show' : 'hide')} />
        <div style={_getStyle(getClassName())} />
      </div>
    );
  }
}

const styleSheet = appStyleSheet;
function _getClassName() { /* codes */ }
function _getStyle(className) {
  return styleSheet[_getClassName(className)]; // not real code
}

And can also import multiple hycss file:

import { Component } from 'React';
import 'app1.hycss';
import 'app2.hycss';

class App extends Component {
  render() {
    return <div className="header1 header2" />;
  }
}

Will be transpiled into something like this:

import { Component } from 'React';
import app1StyleSheet from 'app1.hycss'
import app2StyleSheet from 'app2.hycss'

function _mergeStyles(a, b) { /* codes */ }

const styleSheet = _mergeStyles(app1StyleSheet, app2StyleSheet);

class App extends Component {
  render() {
    return <div style={[styleSheet.header1, styleSheet.header2]} />;
  }
}
1.0.51

6 months ago

1.0.53

6 months ago

1.0.52

6 months ago

1.0.48

1 year ago

1.0.49

1 year ago

1.0.50

1 year ago

1.0.46

3 years ago

1.0.45

3 years ago

1.0.44

4 years ago

1.0.43

4 years ago

1.0.42

4 years ago

1.0.41

4 years ago

1.0.40

4 years ago

1.0.39

4 years ago

1.0.38

4 years ago

1.0.37

4 years ago

1.0.36

4 years ago

1.0.35

4 years ago

1.0.34

4 years ago

1.0.33

4 years ago

1.0.32

4 years ago

1.0.31

4 years ago

1.0.30

4 years ago

1.0.29

4 years ago

1.0.28

4 years ago

1.0.27

4 years ago

1.0.26

4 years ago

1.0.23

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.9

4 years ago

1.0.10

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago