Skip to content

Commit

Permalink
[added] componentClass prop to Jumbotron
Browse files Browse the repository at this point in the history
  • Loading branch information
lo1tuma committed Jun 23, 2015
1 parent daa21f2 commit c5797e8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Jumbotron.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ import React from 'react';
import classNames from 'classnames';

const Jumbotron = React.createClass({
propTypes: {
componentClass: React.PropTypes.any.isRequired
},

getDefaultProps() {
return { componentClass: 'div' };
},

render() {
const ComponentClass = this.props.componentClass;

return (
<div {...this.props} className={classNames(this.props.className, 'jumbotron')}>
<ComponentClass {...this.props} className={classNames(this.props.className, 'jumbotron')}>
{this.props.children}
</div>
</ComponentClass>
);
}
});
Expand Down
11 changes: 11 additions & 0 deletions test/JumbotronSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ describe('Jumbotron', function () {
<strong>Content</strong>
</Jumbotron>
);

assert.equal(React.findDOMNode(instance).nodeName, 'DIV');
assert.ok(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'strong'));
});

Expand All @@ -20,4 +22,13 @@ describe('Jumbotron', function () {
);
assert.ok(React.findDOMNode(instance).className.match(/\bjumbotron\b/));
});

it('Should override node class', function () {
let instance = ReactTestUtils.renderIntoDocument(
<Jumbotron componentClass='section'>
<strong>Content</strong>
</Jumbotron>
);
assert.equal(React.findDOMNode(instance).nodeName, 'SECTION');
});
});

0 comments on commit c5797e8

Please sign in to comment.