From befed8367a98363cbcb8797103633a47e3668998 Mon Sep 17 00:00:00 2001 From: Matthew Smith Date: Tue, 10 Mar 2015 08:07:35 -0600 Subject: [PATCH] [fixed] All panel-* classes dynamic based on bsStyle prop This is some initial work to solve a problem identified in #404. While that issue is directly related to Modals the problem is evident throughout the library. This is the first of many steps to remidy the issue. --- src/BootstrapMixin.js | 6 +++++- src/Panel.jsx | 23 +++++++++++++---------- test/BootstrapMixinSpec.jsx | 9 +++++++++ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/BootstrapMixin.js b/src/BootstrapMixin.js index a0cdfed663..132dc6a86d 100644 --- a/src/BootstrapMixin.js +++ b/src/BootstrapMixin.js @@ -29,7 +29,11 @@ var BootstrapMixin = { } return classes; + }, + + prefixClass: function(subClass) { + return constants.CLASSES[this.props.bsClass] + '-' + subClass; } }; -module.exports = BootstrapMixin; \ No newline at end of file +module.exports = BootstrapMixin; diff --git a/src/Panel.jsx b/src/Panel.jsx index 36ed087612..90058cb2d4 100644 --- a/src/Panel.jsx +++ b/src/Panel.jsx @@ -56,10 +56,10 @@ var Panel = React.createClass({ render: function () { var classes = this.getBsClassSet(); - classes['panel'] = true; return ( -
{this.renderHeading()} {this.props.collapsable ? this.renderCollapsableBody() : this.renderBody()} @@ -69,11 +69,13 @@ var Panel = React.createClass({ }, renderCollapsableBody: function () { + var collapseClass = this.prefixClass('collapse'); + return (
{this.renderBody()}
@@ -84,6 +86,7 @@ var Panel = React.createClass({ var allChildren = this.props.children; var bodyElements = []; var panelBodyChildren = []; + var bodyClass = this.prefixClass('body'); function getProps() { return {key: bodyElements.length}; @@ -95,7 +98,7 @@ var Panel = React.createClass({ function addPanelBody (children) { bodyElements.push( -
+
{children}
); @@ -152,17 +155,17 @@ var Panel = React.createClass({ this.renderCollapsableTitle(header) : header; } else if (this.props.collapsable) { header = cloneWithProps(header, { - className: 'panel-title', + className: this.prefixClass('title'), children: this.renderAnchor(header.props.children) }); } else { header = cloneWithProps(header, { - className: 'panel-title' + className: this.prefixClass('title') }); } return ( -
+
{header}
); @@ -182,7 +185,7 @@ var Panel = React.createClass({ renderCollapsableTitle: function (header) { return ( -

+

{this.renderAnchor(header)}

); @@ -194,7 +197,7 @@ var Panel = React.createClass({ } return ( -
+
{this.props.footer}
); diff --git a/test/BootstrapMixinSpec.jsx b/test/BootstrapMixinSpec.jsx index a80545c519..eb3fb69096 100644 --- a/test/BootstrapMixinSpec.jsx +++ b/test/BootstrapMixinSpec.jsx @@ -188,5 +188,14 @@ describe('BootstrapMixin', function () { ); assert.deepEqual(instance.getBsClassSet(), {'btn': true, 'btn-xs': true}); }); + + it('should return "btn-title"', function () { + var instance = ReactTestUtils.renderIntoDocument( + + content + + ); + assert.equal(instance.prefixClass('title'), 'btn-title'); + }); }); });