1
- import React from 'react' ;
2
- import PropTypes from 'prop-types' ;
3
- import classNames from 'classnames' ;
4
- import { tagPropType , mapToCssModules } from './Shared/helper.js' ;
1
+ import React from 'react'
2
+ import PropTypes from 'prop-types'
3
+ import classNames from 'classnames'
4
+ import { tagPropType , mapToCssModules } from './Shared/helper.js'
5
+ import CLink from './CLink'
5
6
6
7
//component - CoreUI / CBadge
7
8
8
- const CBadge = props => {
9
+ const CBadge = props => {
9
10
10
11
let {
11
12
tag : Tag ,
@@ -16,40 +17,43 @@ const CBadge = props=>{
16
17
color,
17
18
shape,
18
19
...attributes
19
- } = props ;
20
+ } = props
20
21
21
22
// render
22
23
23
24
const classes = mapToCssModules ( classNames (
24
25
className ,
25
26
'badge' ,
26
- 'badge-' + color ,
27
- shape ? 'badge-' + shape : false
28
- ) , cssModule ) ;
29
-
30
- if ( attributes . href && Tag === 'span' ) {
31
- Tag = 'a' ;
27
+ {
28
+ [ `badge-${ color } ` ] : color ,
29
+ [ `badge-${ shape } ` ] : shape
30
+ }
31
+ ) , cssModule )
32
+
33
+ if ( attributes . to || attributes . href ) {
34
+ return (
35
+ < CLink { ...attributes } className = { classes } ref = { innerRef } />
36
+ )
32
37
}
33
38
34
39
return (
35
- < Tag { ...attributes } className = { classes } ref = { innerRef } />
36
- ) ;
40
+ < Tag className = { classes } { ...attributes } ref = { innerRef } />
41
+ )
37
42
38
43
}
39
44
40
45
CBadge . propTypes = {
41
46
tag : tagPropType ,
42
- children : PropTypes . node ,
43
47
className : PropTypes . string ,
44
48
cssModule : PropTypes . object ,
45
49
//
46
50
innerRef : PropTypes . oneOfType ( [ PropTypes . object , PropTypes . func , PropTypes . string ] ) ,
47
51
color : PropTypes . string ,
48
- shape : PropTypes . string
49
- } ;
52
+ shape : PropTypes . oneOf ( [ '' , 'pill' ] )
53
+ }
50
54
51
55
CBadge . defaultProps = {
52
56
tag : 'span'
53
- } ;
57
+ }
54
58
55
- export default CBadge ;
59
+ export default CBadge
0 commit comments