Skip to content

Commit

Permalink
[changed] Simplify 'styleMaps.STYLES' to be of Array type
Browse files Browse the repository at this point in the history
no public API changes.
  • Loading branch information
AlexKVal committed Jul 24, 2015
1 parent 860d168 commit 90aece6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/BootstrapMixin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react';
import styleMaps from './styleMaps';
import CustomPropTypes from './utils/CustomPropTypes';

Expand All @@ -12,7 +13,7 @@ const BootstrapMixin = {
* Style variants
* @type {("default"|"primary"|"success"|"info"|"warning"|"danger"|"link")}
*/
bsStyle: CustomPropTypes.keyOf(styleMaps.STYLES),
bsStyle: React.PropTypes.oneOf(styleMaps.STYLES),
/**
* Size variants
* @type {("xsmall"|"small"|"medium"|"large")}
Expand All @@ -35,9 +36,8 @@ const BootstrapMixin = {
}

if (this.props.bsStyle) {
let bsStyle = styleMaps.STYLES[this.props.bsStyle];
if (bsStyle) {
classes[prefix + bsStyle] = true;
if (styleMaps.STYLES.indexOf(this.props.bsStyle) >= 0) {
classes[prefix + this.props.bsStyle] = true;
} else {
classes[this.props.bsStyle] = true;
}
Expand Down
26 changes: 13 additions & 13 deletions src/styleMaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ const styleMaps = {
'row': 'row',
'well': 'well'
},
STYLES: {
'default': 'default',
'primary': 'primary',
'success': 'success',
'info': 'info',
'warning': 'warning',
'danger': 'danger',
'link': 'link',
'inline': 'inline',
'tabs': 'tabs',
'pills': 'pills'
},
STYLES: [
'default',
'primary',
'success',
'info',
'warning',
'danger',
'link',
'inline',
'tabs',
'pills'
],
addStyle(name) {
styleMaps.STYLES[name] = name;
styleMaps.STYLES.push(name);
},
SIZES: {
'large': 'lg',
Expand Down
12 changes: 12 additions & 0 deletions test/BootstrapMixinSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,16 @@ describe('BootstrapMixin', function () {
});
});
});

// todo: fix bad naming
describe('#prefixClass', function () {
it('allows custom sub-classes', function () {
let instance = ReactTestUtils.renderIntoDocument(
<Component bsClass='button'>
content
</Component>
);
assert.equal(instance.prefixClass('title'), 'btn-title');
});
});
});

0 comments on commit 90aece6

Please sign in to comment.