Skip to content

Commit

Permalink
feat(buttons): Buttons can now be full width
Browse files Browse the repository at this point in the history
[Finishes #144221815]

Signed-off-by: Elana Koren <ekoren@pivotal.io>
  • Loading branch information
Jonathan Berney authored and pivotal committed May 16, 2017
1 parent e17ebb6 commit 1200e62
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ describe('UIButton', () => {
});
});

describe('when full width is true', () => {
it('adds the full width class', () => {
subject = renderComponent({fullWidth: true});
const button = ReactTestUtils.findRenderedDOMComponentWithTag(subject, 'button');

expect(button).toHaveClass('btn-full');
});
});

describe('when small is true', () => {
it('adds the small button class', () => {
subject = renderComponent({small: true});
Expand Down
8 changes: 5 additions & 3 deletions library/src/pivotal-ui-react/buttons/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ export class UIButton extends React.Component {
kind: PropTypes.oneOf(['default', 'danger', 'primary', 'brand']),
large: PropTypes.bool,
small: PropTypes.bool,
fullWidth: PropTypes.bool,
iconPosition: PropTypes.oneOf(['left', 'right'])
}

static defaultProps = {
kind: 'default',
iconPosition: 'left'
}
};

render() {
const {alt, flat, icon, iconPosition, iconOnly, large, small, kind, children, ...others} = this.props;
const {alt, flat, icon, iconPosition, iconOnly, large, small, kind, children, fullWidth, ...others} = this.props;


const buttonClasses = {
Expand All @@ -35,7 +36,8 @@ export class UIButton extends React.Component {
'btn-lg': large,
'btn-sm': small,
'btn-icon': iconOnly,
'btn-icon-right': !!icon && iconPosition === 'right'
'btn-icon-right': !!icon && iconPosition === 'right',
'btn-full': fullWidth
}
]
};
Expand Down
3 changes: 3 additions & 0 deletions library/src/pivotal-ui/components/buttons/buttons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
}
}

.btn-full {
width: 100%;
}

.btn-lg {
height: $base-unit*5;
Expand Down
7 changes: 7 additions & 0 deletions styleguide/docs/react/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ iconOnly | no | Boolean | false | If specified, will render as an ic
iconPosition | no | String | | If specified, places the icon to the left or the right of the text and or children
large | no | Boolean | false | Whether to render the button large
small | no | Boolean | false | Whether to render the button small
fullWidth | no | Boolean | false | Whether to render the button full width
## Basic usage
Expand Down Expand Up @@ -90,6 +91,8 @@ parent: button_react
---
To make a button large, set the `large` property to true, to make it small, set `small` to true.
To make a button full width, set `fullWidth` to true.
```react_example_table
<DefaultButton large>
Big Button
Expand All @@ -102,6 +105,10 @@ Default
<DefaultButton small>
Small Button
</DefaultButton>
<DefaultButton fullWidth>
Full Width Button
</DefaultButton>
```
*/
Expand Down

0 comments on commit 1200e62

Please sign in to comment.