1
- import React from 'react' ;
2
- import PropTypes from 'prop-types' ;
3
- import classNames from 'classnames' ;
4
- import { tagPropType } from '../utils/helper.js' ;
1
+ import React from 'react'
2
+ import PropTypes from 'prop-types'
3
+ import classNames from 'classnames'
4
+ import { tagPropType } from '../utils/helper.js'
5
5
6
- const colWidths = [ 'xs' , 'sm' , 'md' , 'lg' , 'xl' ] ;
7
- const stringOrNumberProp = PropTypes . oneOfType ( [ PropTypes . number , PropTypes . string ] ) ;
6
+
7
+ const stringOrNumberProp = PropTypes . oneOfType ( [ PropTypes . number , PropTypes . string ] )
8
8
const columnProps = PropTypes . oneOfType ( [
9
9
PropTypes . bool ,
10
10
PropTypes . number ,
@@ -14,19 +14,19 @@ const columnProps = PropTypes.oneOfType([
14
14
order : stringOrNumberProp ,
15
15
offset : stringOrNumberProp
16
16
} )
17
- ] ) ;
17
+ ] )
18
+
18
19
const getColumnSizeClass = ( isXs , colWidth , colSize ) => {
19
20
if ( colSize === true || colSize === '' ) {
20
- return isXs ? 'col' : `col-${ colWidth } ` ;
21
+ return isXs ? 'col' : `col-${ colWidth } `
21
22
} else if ( colSize === 'auto' ) {
22
- return isXs ? 'col-auto' : `col-${ colWidth } -auto` ;
23
+ return isXs ? 'col-auto' : `col-${ colWidth } -auto`
23
24
}
24
- return isXs ? `col-${ colSize } ` : `col-${ colWidth } -${ colSize } ` ;
25
+ return isXs ? `col-${ colSize } ` : `col-${ colWidth } -${ colSize } `
25
26
} ;
26
27
27
28
//component - CoreUI / CCol
28
-
29
- const CCol = props => {
29
+ const CCol = props => {
30
30
31
31
const {
32
32
tag : Tag ,
@@ -35,46 +35,45 @@ const CCol = props=>{
35
35
innerRef,
36
36
widths,
37
37
...attributes
38
- } = props ;
38
+ } = props
39
39
40
40
//render
41
41
42
- const colClasses = [ ] ;
43
-
42
+ const colClasses = [ ]
44
43
widths . forEach ( ( colWidth , i ) => {
45
- let columnProp = props [ colWidth ] ;
46
- delete attributes [ colWidth ] ;
44
+ let columnProp = props [ colWidth ]
45
+ delete attributes [ colWidth ]
47
46
if ( ! columnProp && columnProp !== '' ) {
48
- return ;
47
+ return
49
48
}
50
- const isXs = ! i ;
49
+ const isXs = ! i
51
50
if ( typeof columnProp === 'object' ) {
52
- const colSizeInterfix = isXs ? '-' : `-${ colWidth } -` ;
53
- const colClass = getColumnSizeClass ( isXs , colWidth , columnProp . size ) ;
51
+ const colSizeInterfix = isXs ? '-' : `-${ colWidth } -`
52
+ const colClass = getColumnSizeClass ( isXs , colWidth , columnProp . size )
54
53
55
54
colClasses . push ( classNames ( {
56
55
[ colClass ] : columnProp . size || columnProp . size === '' ,
57
56
[ `order${ colSizeInterfix } ${ columnProp . order } ` ] : columnProp . order || columnProp . order === 0 ,
58
57
[ `offset${ colSizeInterfix } ${ columnProp . offset } ` ] : columnProp . offset || columnProp . offset === 0
59
- } ) ) ;
58
+ } ) )
60
59
} else {
61
- const colClass = getColumnSizeClass ( isXs , colWidth , columnProp ) ;
62
- colClasses . push ( colClass ) ;
60
+ const colClass = getColumnSizeClass ( isXs , colWidth , columnProp )
61
+ colClasses . push ( colClass )
63
62
}
64
- } ) ;
63
+ } )
65
64
66
65
if ( ! colClasses . length ) {
67
- colClasses . push ( 'col' ) ;
66
+ colClasses . push ( 'col' )
68
67
}
69
68
70
69
const classes = classNames (
71
70
className ,
72
71
colClasses
73
- ) ;
72
+ )
74
73
75
74
return (
76
75
< Tag { ...attributes } className = { classes } ref = { innerRef } />
77
- ) ;
76
+ )
78
77
79
78
}
80
79
@@ -88,12 +87,13 @@ CCol.propTypes = {
88
87
md : columnProps ,
89
88
lg : columnProps ,
90
89
xl : columnProps ,
90
+ xxl : columnProps ,
91
91
widths : PropTypes . array
92
- } ;
92
+ }
93
93
94
94
CCol . defaultProps = {
95
95
tag : 'div' ,
96
- widths : colWidths ,
97
- } ;
96
+ widths : [ 'xs' , 'sm' , 'md' , 'lg' , 'xl' , 'xxl' ]
97
+ }
98
98
99
- export default CCol ;
99
+ export default CCol
0 commit comments