Skip to content

Commit

Permalink
[added] Now accepting a block property on the ButtonGroup component.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu M-Gosselin committed May 27, 2015
1 parent 353b4f0 commit 935171f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
8 changes: 8 additions & 0 deletions docs/examples/ButtonGroupBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const buttonGroupInstance = (
<ButtonGroup vertical block>
<Button>Full width button</Button>
<Button>Full width button</Button>
</ButtonGroup>
);

React.render(buttonGroupInstance, mountNode);
3 changes: 3 additions & 0 deletions docs/src/ComponentsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ const ComponentsPage = React.createClass({
className='text-danger'>Split button dropdowns are not supported here.</strong></p>
<p>Just add <code>vertical</code> to the <code>{'<ButtonGroup />'}</code>.</p>
<ReactPlayground codeText={Samples.ButtonGroupVertical} />
<br />
<p>Moreover, you can have buttons be block level elements so they take the full width of their container, just add <code>block</code> to the <code>{'<ButtonGroup />'}</code>, in addition to the <code>vertical</code> you just added.</p>
<ReactPlayground codeText={Samples.ButtonGroupBlock} />

<h3 id='btn-groups-justified'>Justified button groups</h3>
<p>Make a group of buttons stretch at equal sizes to span the entire width of its parent. Also works with button dropdowns within the button group.</p>
Expand Down
1 change: 1 addition & 0 deletions docs/src/Samples.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default {
ButtonGroupNested: require('fs').readFileSync(__dirname + '/../examples/ButtonGroupNested.js', 'utf8'),
ButtonGroupVertical: require('fs').readFileSync(__dirname + '/../examples/ButtonGroupVertical.js', 'utf8'),
ButtonGroupJustified: require('fs').readFileSync(__dirname + '/../examples/ButtonGroupJustified.js', 'utf8'),
ButtonGroupBlock: require('fs').readFileSync(__dirname + '/../examples/ButtonGroupBlock.js', 'utf8'),
DropdownButtonBasic: require('fs').readFileSync(__dirname + '/../examples/DropdownButtonBasic.js', 'utf8'),
SplitButtonBasic: require('fs').readFileSync(__dirname + '/../examples/SplitButtonBasic.js', 'utf8'),
DropdownButtonSizes: require('fs').readFileSync(__dirname + '/../examples/DropdownButtonSizes.js', 'utf8'),
Expand Down
12 changes: 11 additions & 1 deletion src/ButtonGroup.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import React from 'react';
import classNames from 'classnames';
import BootstrapMixin from './BootstrapMixin';
import CustomPropTypes from './utils/CustomPropTypes';

const ButtonGroup = React.createClass({
mixins: [BootstrapMixin],

propTypes: {
vertical: React.PropTypes.bool,
justified: React.PropTypes.bool
justified: React.PropTypes.bool,
block: CustomPropTypes.all([
React.PropTypes.bool,
function(props, propName, componentName) {
if (props.block && !props.vertical) {
return new Error('The block property requires the vertical property to be set to have any effect');
}
}
])
},

getDefaultProps() {
Expand All @@ -21,6 +30,7 @@ const ButtonGroup = React.createClass({
classes['btn-group'] = !this.props.vertical;
classes['btn-group-vertical'] = this.props.vertical;
classes['btn-group-justified'] = this.props.justified;
classes['btn-block'] = this.props.block;

return (
<div
Expand Down
23 changes: 23 additions & 0 deletions test/ButtonGroupSpec.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 ButtonGroup from '../src/ButtonGroup';
import Button from '../src/Button';
import { shouldWarn } from './helpers';

describe('ButtonGroup', function () {
it('Should output a button group', function () {
Expand Down Expand Up @@ -38,6 +39,28 @@ describe('ButtonGroup', function () {
assert.equal(instance.getDOMNode().className.trim(), 'btn-group-vertical');
});

it('Should add block variation', function () {
let instance = ReactTestUtils.renderIntoDocument(
<ButtonGroup vertical block>
<Button>
Title
</Button>
</ButtonGroup>
);
assert.ok(instance.getDOMNode().className.match(/\bbtn-block\b/));
});

it('Should warn about block without vertical', function () {
ReactTestUtils.renderIntoDocument(
<ButtonGroup block>
<Button>
Title
</Button>
</ButtonGroup>
);
shouldWarn('The block property requires the vertical property to be set to have any effect');
});

it('Should add justified variation', function () {
let instance = ReactTestUtils.renderIntoDocument(
<ButtonGroup justified>
Expand Down

0 comments on commit 935171f

Please sign in to comment.