Skip to content

Commit 860d168

Browse files
committed
[fixed] allow totally custom styles via 'bsStyle'
but with validation warning
1 parent ac7ada5 commit 860d168

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

Diff for: src/BootstrapMixin.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@ const BootstrapMixin = {
3434
classes[prefix + bsSize] = true;
3535
}
3636

37-
let bsStyle = this.props.bsStyle && styleMaps.STYLES[this.props.bsStyle];
3837
if (this.props.bsStyle) {
39-
classes[prefix + bsStyle] = true;
38+
let bsStyle = styleMaps.STYLES[this.props.bsStyle];
39+
if (bsStyle) {
40+
classes[prefix + bsStyle] = true;
41+
} else {
42+
classes[this.props.bsStyle] = true;
43+
}
4044
}
4145
}
4246

Diff for: test/BootstrapMixinSpec.js

+23-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import ReactTestUtils from 'react/lib/ReactTestUtils';
33
import BootstrapMixin from '../src/BootstrapMixin';
44
import styleMaps from '../src/styleMaps';
5+
import { shouldWarn } from './helpers';
56

67
let Component;
78

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

200-
it('should return "btn btn-wacky"', function () {
201-
styleMaps.addStyle('wacky');
202-
let instance = ReactTestUtils.renderIntoDocument(
203-
<Component bsClass='button' bsStyle='wacky'>
204-
content
205-
</Component>
206-
);
207-
assert.deepEqual(instance.getBsClassSet(), {'btn': true, 'btn-wacky': true});
201+
describe('Custom styles', function () {
202+
it('should validate OK custom styles added via "addStyle()"', function () {
203+
204+
styleMaps.addStyle('wacky');
205+
206+
let instance = ReactTestUtils.renderIntoDocument(
207+
<Component bsClass='button' bsStyle='wacky'>
208+
content
209+
</Component>
210+
);
211+
assert.deepEqual(instance.getBsClassSet(), {'btn': true, 'btn-wacky': true});
212+
});
213+
214+
it('should allow custom styles as is but with validation warning', function () {
215+
let instance = ReactTestUtils.renderIntoDocument(
216+
<Component bsClass='button' bsStyle='my-custom-class'>
217+
content
218+
</Component>
219+
);
220+
assert.deepEqual(instance.getBsClassSet(), {'btn': true, 'my-custom-class': true});
221+
shouldWarn('Invalid prop `bsStyle` of value `my-custom-class`');
222+
});
208223
});
209224
});
210225
});

0 commit comments

Comments
 (0)