Skip to content

Commit

Permalink
fix wix-incubator#191, allow use of 'class' in custom-elements
Browse files Browse the repository at this point in the history
  • Loading branch information
nippur72 committed Sep 6, 2016
1 parent 66d18d0 commit aeb330e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
17 changes: 13 additions & 4 deletions src/reactTemplates.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ function generateProps(node, context) {
});
_.assign(props, generateTemplateProps(node, context));

// map 'className' back into 'class' for custom elements
if (props[reactSupport.classNameProp] && isCustomElement(node.name)) {
props[classAttr] = props[reactSupport.classNameProp];
delete props[reactSupport.classNameProp];
}

const propStr = _.map(props, (v, k) => `${JSON.stringify(k)} : ${v}`).join(',');
return `{${propStr}}`;
}
Expand Down Expand Up @@ -303,15 +309,18 @@ function convertTagNameToConstructor(tagName, context) {
if (context.options.native) {
const targetSupport = reactNativeSupport[context.options.nativeTargetVersion];
return _.includes(targetSupport.components, tagName) ? `${targetSupport.reactNative.name}.${tagName}` : tagName;
}
let isHtmlTag = _.includes(reactDOMSupport[context.options.targetVersion], tagName);
if (reactSupport.shouldUseCreateElement(context)) {
isHtmlTag = isHtmlTag || tagName.match(/^\w+(-\w+)+$/);
}
const isHtmlTag = _.includes(reactDOMSupport[context.options.targetVersion], tagName) || isCustomElement(tagName);
if (reactSupport.shouldUseCreateElement(context)) {
return isHtmlTag ? `'${tagName}'` : tagName;
}
return isHtmlTag ? 'React.DOM.' + tagName : tagName;
}

function isCustomElement(tagName) {
return tagName.match(/^\w+(-\w+)+$/);
}

/**
* @param {string} html
* @param options
Expand Down
2 changes: 1 addition & 1 deletion test/data/custom-element.rt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div>
<custom-element></custom-element>
<my-custom-element></my-custom-element>
<my-custom-element class="a" className="b" rt-class="{c:1}" rt-props="{d:2}"></my-custom-element>
</div>
2 changes: 1 addition & 1 deletion test/data/custom-element.rt.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div><custom-element></custom-element><my-custom-element></my-custom-element></div>
<div><custom-element></custom-element><my-custom-element class="a b c" d="2"></my-custom-element></div>

0 comments on commit aeb330e

Please sign in to comment.