File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import React , { PropTypes } from 'react' ;
2+ import classNames from 'classnames' ;
3+
4+ const propTypes = {
5+ 'aria-label' : PropTypes . string ,
6+ className : PropTypes . string ,
7+ role : PropTypes . string ,
8+ size : PropTypes . string ,
9+ vertical : PropTypes . bool
10+ } ;
11+
12+ const defaultProps = {
13+ role : 'group'
14+ } ;
15+
16+ class ButtonGroup extends React . Component {
17+ constructor ( props ) {
18+ super ( props ) ;
19+ }
20+
21+ render ( ) {
22+ const {
23+ children,
24+ className,
25+ size,
26+ vertical,
27+ ...attributes
28+ } = this . props ;
29+
30+ const classes = classNames (
31+ className ,
32+ 'btn-group' ,
33+ size ? 'btn-' + size : false ,
34+ vertical ? 'btn-group-vertical' : false
35+ ) ;
36+
37+ return (
38+ < div { ...attributes }
39+ className = { classes } >
40+ { children }
41+ </ div >
42+ ) ;
43+ }
44+ }
45+
46+ ButtonGroup . propTypes = propTypes ;
47+ ButtonGroup . defaultProps = defaultProps ;
48+
49+ export default ButtonGroup ;
Original file line number Diff line number Diff line change 1+ import React , { PropTypes } from 'react' ;
2+ import classNames from 'classnames' ;
3+
4+ const propTypes = {
5+ 'aria-label' : PropTypes . string ,
6+ className : PropTypes . string ,
7+ role : PropTypes . string
8+ } ;
9+
10+ const defaultProps = {
11+ role : 'toolbar'
12+ } ;
13+
14+ class ButtonToolbar extends React . Component {
15+ constructor ( props ) {
16+ super ( props ) ;
17+ }
18+
19+ render ( ) {
20+ const {
21+ children,
22+ className,
23+ ...attributes
24+ } = this . props ;
25+
26+ const classes = classNames (
27+ className ,
28+ 'btn-toolbar'
29+ ) ;
30+
31+ return (
32+ < div { ...attributes }
33+ className = { classes } >
34+ { children }
35+ </ div >
36+ ) ;
37+ }
38+ }
39+
40+ ButtonToolbar . propTypes = propTypes ;
41+ ButtonToolbar . defaultProps = defaultProps ;
42+
43+ export default ButtonToolbar ;
Original file line number Diff line number Diff line change 11import Button from './Button' ;
2+ import ButtonGroup from './ButtonGroup' ;
3+ import ButtonToolbar from './ButtonToolbar' ;
24
35export {
4- Button
6+ Button ,
7+ ButtonGroup ,
8+ ButtonToolbar
59} ;
Original file line number Diff line number Diff line change 1+ /* eslint react/no-multi-comp: 0, react/prop-types: 0 */
2+ import React from 'react' ;
3+ import { shallow , mount } from 'enzyme' ;
4+ import { ButtonGroup } from '../lib' ;
5+
6+ describe ( 'ButtonGroup' , ( ) => {
7+ it ( 'should render children' , ( ) => {
8+ const wrapper = shallow ( < ButtonGroup > Ello world</ ButtonGroup > ) ;
9+
10+ expect ( wrapper . text ( ) ) . toBe ( 'Ello world' ) ;
11+ expect ( wrapper . hasClass ( 'btn-group' ) ) . toBe ( true ) ;
12+ } ) ;
13+
14+ it ( 'should render different size classes' , ( ) => {
15+ const small = shallow ( < ButtonGroup size = "sm" > Small Button</ ButtonGroup > ) ;
16+ const large = shallow ( < ButtonGroup size = "lg" > Large Button</ ButtonGroup > ) ;
17+
18+ expect ( small . hasClass ( 'btn-sm' ) ) . toBe ( true ) ;
19+ expect ( large . hasClass ( 'btn-lg' ) ) . toBe ( true ) ;
20+ } ) ;
21+
22+ it ( 'should render vetical class' , ( ) => {
23+ const wrapper = shallow ( < ButtonGroup vertical > Vertical Group</ ButtonGroup > ) ;
24+
25+ expect ( wrapper . hasClass ( 'btn-group-vertical' ) ) . toBe ( true ) ;
26+ } ) ;
27+ } ) ;
Original file line number Diff line number Diff line change 1+ /* eslint react/no-multi-comp: 0, react/prop-types: 0 */
2+ import React from 'react' ;
3+ import { shallow , mount } from 'enzyme' ;
4+ import { ButtonToolbar } from '../lib' ;
5+
6+ describe ( 'ButtonToolbar' , ( ) => {
7+ it ( 'should render children' , ( ) => {
8+ const wrapper = shallow ( < ButtonToolbar > Ello world</ ButtonToolbar > ) ;
9+
10+ expect ( wrapper . text ( ) ) . toBe ( 'Ello world' ) ;
11+ expect ( wrapper . hasClass ( 'btn-toolbar' ) ) . toBe ( true ) ;
12+ } ) ;
13+ } ) ;
You can’t perform that action at this time.
0 commit comments