Skip to content

Commit 35c3df6

Browse files
committed
fix: CBadge: allow inheriting CLink functionality, smaller fixes
1 parent d09a4b8 commit 35c3df6

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

src/CBadge.js

+23-19
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
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'
56

67
//component - CoreUI / CBadge
78

8-
const CBadge = props=>{
9+
const CBadge = props => {
910

1011
let {
1112
tag: Tag,
@@ -16,40 +17,43 @@ const CBadge = props=>{
1617
color,
1718
shape,
1819
...attributes
19-
} = props;
20+
} = props
2021

2122
// render
2223

2324
const classes = mapToCssModules(classNames(
2425
className,
2526
'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+
)
3237
}
3338

3439
return (
35-
<Tag {...attributes} className={classes} ref={innerRef} />
36-
);
40+
<Tag className={classes} {...attributes} ref={innerRef} />
41+
)
3742

3843
}
3944

4045
CBadge.propTypes = {
4146
tag: tagPropType,
42-
children: PropTypes.node,
4347
className: PropTypes.string,
4448
cssModule: PropTypes.object,
4549
//
4650
innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func, PropTypes.string]),
4751
color: PropTypes.string,
48-
shape: PropTypes.string
49-
};
52+
shape: PropTypes.oneOf(['', 'pill'])
53+
}
5054

5155
CBadge.defaultProps = {
5256
tag: 'span'
53-
};
57+
}
5458

55-
export default CBadge;
59+
export default CBadge

0 commit comments

Comments
 (0)