babel-plugin-react-pug-classnames
Advanced tools
Comparing version 0.1.0 to 0.2.0
11
index.js
var DEFAULT_CLASSNAMES_FUNCTION = 'babel-plugin-react-pug-classnames/classnames' | ||
function isTargetAttr (attribute, targetName = 'className') { | ||
return attribute.name.name === targetName | ||
function isTargetAttr (attribute, classAttribute) { | ||
if (!classAttribute) classAttribute = 'className' | ||
return attribute.name.name === classAttribute | ||
} | ||
@@ -36,3 +37,3 @@ | ||
if (!isTargetAttr(JSXAttribute.node, opts.attribute)) return | ||
if (!isTargetAttr(JSXAttribute.node, opts.classAttribute)) return | ||
@@ -116,6 +117,6 @@ if (t.isStringLiteral(JSXAttribute.node.value)) { | ||
visitor: { | ||
JSXElement (JSXElement, { opts }) { | ||
JSXElement (JSXElement, params) { | ||
JSXElement.traverse({ | ||
JSXOpeningElement (JSXOpeningElement) { | ||
processClass(JSXOpeningElement, opts) | ||
processClass(JSXOpeningElement, params.opts) | ||
} | ||
@@ -122,0 +123,0 @@ }) |
{ | ||
"name": "babel-plugin-react-pug-classnames", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "[react-pug] Transform className property using BEM classnames-like function", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -9,5 +9,25 @@ # babel-plugin-react-pug-classnames | ||
## Install | ||
It must be installed into the actual dependencies, NOT the devDependencies. | ||
The reason is that it does classnames processing through a dynamic runtime function which is `require()`'d from the package itself. | ||
```bash | ||
npm i babel-plugin-react-pug-classnames | ||
``` | ||
Add plugin to your babel config right after the `transform-react-pug`: | ||
```json | ||
['transform-react-pug', { | ||
classAttribute: 'styleName' | ||
}], | ||
['react-pug-classnames', { | ||
classAttribute: 'styleName' | ||
}] | ||
``` | ||
## Options | ||
`attribute` -- name of the attribute to use (for example `styleName`). Default: `className` | ||
`classAttribute` -- name of the attribute to use (for example `styleName`). Default: `className` | ||
@@ -14,0 +34,0 @@ `classnamesFunction` -- classnames function to use to transform the className's object/array value. Default: `babel-plugin-react-pug-classnames/classnames` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10307
105
90