Skip to content

Commit

Permalink
[fixed] allow totally custom styles via 'bsStyle'
Browse files Browse the repository at this point in the history
but with validation warning
  • Loading branch information
AlexKVal committed Jul 24, 2015
1 parent ac7ada5 commit 860d168
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
8 changes: 6 additions & 2 deletions src/BootstrapMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ const BootstrapMixin = {
classes[prefix + bsSize] = true;
}

let bsStyle = this.props.bsStyle && styleMaps.STYLES[this.props.bsStyle];
if (this.props.bsStyle) {
classes[prefix + bsStyle] = true;
let bsStyle = styleMaps.STYLES[this.props.bsStyle];
if (bsStyle) {
classes[prefix + bsStyle] = true;
} else {
classes[this.props.bsStyle] = true;
}
}
}

Expand Down
31 changes: 23 additions & 8 deletions test/BootstrapMixinSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import ReactTestUtils from 'react/lib/ReactTestUtils';
import BootstrapMixin from '../src/BootstrapMixin';
import styleMaps from '../src/styleMaps';
import { shouldWarn } from './helpers';

let Component;

Expand Down Expand Up @@ -197,14 +198,28 @@ describe('BootstrapMixin', function () {
assert.equal(instance.prefixClass('title'), 'btn-title');
});

it('should return "btn btn-wacky"', function () {
styleMaps.addStyle('wacky');
let instance = ReactTestUtils.renderIntoDocument(
<Component bsClass='button' bsStyle='wacky'>
content
</Component>
);
assert.deepEqual(instance.getBsClassSet(), {'btn': true, 'btn-wacky': true});
describe('Custom styles', function () {
it('should validate OK custom styles added via "addStyle()"', function () {

styleMaps.addStyle('wacky');

let instance = ReactTestUtils.renderIntoDocument(
<Component bsClass='button' bsStyle='wacky'>
content
</Component>
);
assert.deepEqual(instance.getBsClassSet(), {'btn': true, 'btn-wacky': true});
});

it('should allow custom styles as is but with validation warning', function () {
let instance = ReactTestUtils.renderIntoDocument(
<Component bsClass='button' bsStyle='my-custom-class'>
content
</Component>
);
assert.deepEqual(instance.getBsClassSet(), {'btn': true, 'my-custom-class': true});
shouldWarn('Invalid prop `bsStyle` of value `my-custom-class`');
});
});
});
});

0 comments on commit 860d168

Please sign in to comment.