1+ import isobject from 'lodash.isobject' ;
12import React , { PropTypes } from 'react' ;
23import classNames from 'classnames' ;
34import { mapToCssModules } from './utils' ;
45
5- const colSizes = [ 'xs' , 'sm' , 'md' , 'lg' , 'xl' ] ;
6+ const colWidths = [ 'xs' , 'sm' , 'md' , 'lg' , 'xl' ] ;
67const stringOrNumberProp = PropTypes . oneOfType ( [ PropTypes . number , PropTypes . string ] ) ;
78
89const columnProps = PropTypes . oneOfType ( [
910 PropTypes . bool ,
1011 PropTypes . number ,
1112 PropTypes . string ,
1213 PropTypes . shape ( {
13- size : stringOrNumberProp ,
14+ size : PropTypes . oneOfType ( [ PropTypes . bool , PropTypes . number , PropTypes . string ] ) ,
1415 push : stringOrNumberProp ,
1516 pull : stringOrNumberProp ,
1617 offset : stringOrNumberProp
@@ -28,7 +29,17 @@ const propTypes = {
2829} ;
2930
3031const defaultProps = {
31- xs : 12
32+ xs : true
33+ } ;
34+
35+ const getColumnSizeClass = ( isXs , colWidth , colSize ) => {
36+ if ( colSize === true || colSize === '' ) {
37+ return isXs ? 'col' : `col-${ colWidth } ` ;
38+ } else if ( colSize === 'auto' ) {
39+ return isXs ? 'col-auto' : `col-${ colWidth } -auto` ;
40+ }
41+
42+ return isXs ? `col-${ colSize } ` : `col-${ colWidth } -${ colSize } ` ;
3243} ;
3344
3445const Col = ( props ) => {
@@ -39,33 +50,30 @@ const Col = (props) => {
3950 } = props ;
4051 const colClasses = [ ] ;
4152
42- colSizes . forEach ( colSize => {
43- const columnProp = props [ colSize ] ;
44- delete attributes [ colSize ] ;
45- let colClass ;
53+ colWidths . forEach ( colWidth => {
54+ const columnProp = props [ colWidth ] ;
4655
4756 if ( ! columnProp ) {
4857 return ;
49- } else if ( columnProp . size ) {
50- if ( columnProp . size === 'auto' ) {
51- colClass = `col-${ colSize } ` ;
52- } else {
53- colClass = `col-${ colSize } -${ columnProp . size } ` ;
54- }
58+ }
59+
60+ const isXs = colWidth === 'xs' ;
61+ let colClass ;
62+
63+ delete attributes [ colWidth ] ;
64+
65+ if ( isobject ( columnProp ) ) {
66+ const colSizeInterfix = isXs ? '-' : `-${ colWidth } -` ;
67+ colClass = getColumnSizeClass ( isXs , colWidth , columnProp . size ) ;
5568
5669 colClasses . push ( mapToCssModules ( classNames ( {
57- [ colClass ] : columnProp . size ,
58- [ `push- ${ colSize } - ${ columnProp . push } ` ] : columnProp . push ,
59- [ `pull- ${ colSize } - ${ columnProp . pull } ` ] : columnProp . pull ,
60- [ `offset- ${ colSize } - ${ columnProp . offset } ` ] : columnProp . offset
70+ [ colClass ] : columnProp . size || columnProp . size === '' ,
71+ [ `push${ colSizeInterfix } ${ columnProp . push } ` ] : columnProp . push ,
72+ [ `pull${ colSizeInterfix } ${ columnProp . pull } ` ] : columnProp . pull ,
73+ [ `offset${ colSizeInterfix } ${ columnProp . offset } ` ] : columnProp . offset
6174 } ) ) , cssModule ) ;
6275 } else {
63- if ( columnProp === 'auto' || columnProp === true ) {
64- colClass = `col-${ colSize } ` ;
65- } else {
66- colClass = `col-${ colSize } -${ columnProp } ` ;
67- }
68-
76+ colClass = getColumnSizeClass ( isXs , colWidth , columnProp ) ;
6977 colClasses . push ( colClass ) ;
7078 }
7179 } ) ;
0 commit comments