-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export component specifically for rendering html
- Loading branch information
1 parent
d49b2cc
commit a8bfe2e
Showing
3 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
import Component from './JSXComponent'; | ||
import { Config } from 'metal-state'; | ||
|
||
/** | ||
* JSXComponent that renders html passed in. | ||
* @class | ||
*/ | ||
class DangerouslySetHTML extends Component { | ||
/** | ||
* @return {Component} | ||
*/ | ||
render() { | ||
const {content, tag} = this.props; | ||
|
||
IncrementalDOM.elementOpen(tag, null, null); | ||
|
||
const node = IncrementalDOM.elementClose(tag); | ||
|
||
node.innerHTML = content; | ||
|
||
return node; | ||
} | ||
} | ||
|
||
DangerouslySetHTML.PROPS = { | ||
content: Config.string(), | ||
tag: Config.string().value('span'), | ||
}; | ||
|
||
export default DangerouslySetHTML; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
import DangerouslySetHTML from '../src/DangerouslySetHTML'; | ||
|
||
describe('JSXComponent', function() { | ||
var component; | ||
|
||
afterEach(function() { | ||
if (component) { | ||
component.dispose(); | ||
} | ||
}); | ||
|
||
it('should render', function() { | ||
component = new DangerouslySetHTML(); | ||
assert.strictEqual('SPAN', component.element.tagName); | ||
}); | ||
|
||
it('should render with custom tag', function() { | ||
component = new DangerouslySetHTML({tag: 'div'}); | ||
assert.strictEqual('DIV', component.element.tagName); | ||
}); | ||
|
||
it('should render with html content', function() { | ||
var content = '<h2>hello</h2><div><span>world</span></div>'; | ||
|
||
component = new DangerouslySetHTML({content: content}); | ||
assert.strictEqual(content, component.element.innerHTML); | ||
}); | ||
}); |