0.0.3 • Published 5 years ago

babel-plugin-transform-jsx-classname-components v0.0.3

Weekly downloads
2,586
License
MIT
Repository
github
Last release
5 years ago

babel-plugin-transform-jsx-classname-components

:sunglasses: Long name, right...

npm version CI Status Greenkeeper badge

What

It takes your first class name (if it starts with up-case) and use it as property for component.

<Component className="Inner" />

Will be transformed into this:

<Component.Inner />

Why

You don't need this plugin unless you use Pug with react. Pug consider everything after dot as class names, so it converts code like:

pug`Component.Inner Hello`

Into this:

<Component className="Inner">Hello</Component>

This plugin was created to change the result to this one:

<Component.Inner>Hello</Component.Inner>

How

yarn add --dev babel-plugin-transform-jsx-classname-components

In .babelrc:

{
  "plugins": [
    "transform-jsx-classname-components"
  ]
}

Note: It should be placed after transforming Pug into Jsx.

Options

NameTypeDefaultDescription
objectsArray<string>nullIt specifies what objects should be processed
attributeStringclassNameIt specifies attribute name which should be processed

objects

If you set it to ['Icons'] it will handle only <Icons ... />:

<Component className="Inner" />
<Icons className="Inner" />

Will be transformed into:

<Component className="Inner" />
<Icons.Inner  />

attribute

If you set it to styleName it will process styleName attribute instead of default one:

<Component styleName="Inner" />
<Icons className="JustClass" styleName="Inner" />

Will be transformed into:

<Component.Inner />
<Icons.Inner className="JustClass"  />