1.0.53 • Published 2 years ago

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

Weekly downloads
59
License
MIT
Repository
-
Last release
2 years 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

2 years ago

1.0.53

2 years ago

1.0.52

2 years ago

1.0.48

2 years ago

1.0.49

2 years ago

1.0.50

2 years ago

1.0.46

4 years ago

1.0.45

4 years ago

1.0.44

5 years ago

1.0.43

5 years ago

1.0.42

5 years ago

1.0.41

5 years ago

1.0.40

5 years ago

1.0.39

5 years ago

1.0.38

5 years ago

1.0.37

5 years ago

1.0.36

5 years ago

1.0.35

5 years ago

1.0.34

5 years ago

1.0.33

5 years ago

1.0.32

5 years ago

1.0.31

5 years ago

1.0.30

5 years ago

1.0.29

5 years ago

1.0.28

5 years ago

1.0.27

5 years ago

1.0.26

5 years ago

1.0.23

5 years ago

1.0.22

5 years ago

1.0.21

5 years ago

1.0.20

5 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.9

6 years ago

1.0.10

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.2

6 years ago

1.0.3

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago