Skip to content

Commit 25347f4

Browse files
committed
refactor: cleanup
1 parent dad8daa commit 25347f4

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

src/CIcon.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import 'react-app-polyfill/ie11'; // For IE 11 support
2-
import 'react-app-polyfill/stable';
31
import React from 'react';
42
import PropTypes from 'prop-types';
53
import classNames from 'classnames';
6-
import { mapToCssModules } from '@coreui/react';
4+
import { mapToCssModules } from './Shared/helper';
75
import CIconRaw from './CIconRaw';
86
import style from './CIcon.module.css';
97

@@ -34,24 +32,24 @@ const CIcon = props=>{
3432
}
3533
}
3634

37-
if (type=='svg'){
35+
if (type==='svg'){
3836
return (
3937
<CIconRaw {...attributes} name={name} size={size} className={className} />
4038
);
4139
}
4240

4341
const classes = (classNames(
4442
mapToCssModules(className, Object.assign(style, cssModule)),
45-
type=='name' ? name :
46-
type=='class' ? name.className : null,
43+
type==='name' ? name :
44+
type==='class' ? name.className : null,
4745
size ? 'c-icon-'+size : null
4846
));
4947

5048
return (
5149
<Tag {...attributes} className={classes} />
5250
);
5351

54-
}
52+
};
5553

5654
CIcon.propTypes = {
5755
tag: PropTypes.string,

src/CIconRaw.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import 'react-app-polyfill/ie11'; // For IE 11 support
2-
import 'react-app-polyfill/stable';
31
import React from 'react';
42
import PropTypes from 'prop-types';
53
import classNames from 'classnames';
6-
import {mapToCssModules, colog} from '@coreui/react';
4+
import {mapToCssModules, colog} from './Shared/helper';
75
import style from './CIcon.module.css';
86

97
//component - CoreUI / CIconRaw
@@ -29,12 +27,12 @@ const CIconRaw = props=>{
2927
return str.replace(/([-_][a-z0-9])/ig, ($1) => {
3028
return $1.toUpperCase().replace('-', '')
3129
})
32-
}
30+
};
3331

3432
//vars
3533

3634
const iconName = (()=>{
37-
const iconNameIsKebabCase = name && name.includes('-')
35+
const iconNameIsKebabCase = name && name.includes('-');
3836
return iconNameIsKebabCase ? toCamelCase(name) : name
3937
})();
4038
const titleCode = (()=>{
@@ -62,7 +60,7 @@ const CIconRaw = props=>{
6260
return attributes.viewBox || `0 0 ${scale}`
6361
})();
6462
const computedSize = (()=>{
65-
const addCustom = !size && (attributes.width || attributes.height)
63+
const addCustom = !size && (attributes.width || attributes.height);
6664
return size === 'custom' || addCustom ? 'custom-size' : size
6765
})();
6866
//console.log(iconName, computedSize)
@@ -86,7 +84,7 @@ const CIconRaw = props=>{
8684
computedSize ? `c-icon-${computedSize}` : ''
8785
), style);
8886

89-
const classes = customClasses || (class1 + ' ' + class2)
87+
const classes = customClasses || (class1 + ' ' + class2);
9088

9189
//console.log(code, viewBox, classes, titleCode+' - '+iconCode);
9290
//v-html={titleCode+iconCode}
@@ -118,7 +116,7 @@ const CIconRaw = props=>{
118116
</React.Fragment>
119117
);
120118

121-
}
119+
};
122120

123121
CIconRaw.propTypes = {
124122
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),

src/Shared/helper.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// helper functions
2+
3+
let globalCssModule;
4+
5+
const mapToCssModules = (className = '', cssModule = globalCssModule) => {
6+
if (!cssModule) return className;
7+
return className
8+
.split(' ')
9+
.map(c => cssModule[c] || c)
10+
.join(' ');
11+
};
12+
export {mapToCssModules};
13+
14+
export function colog() {
15+
if (process.env.NODE_ENV === 'development')
16+
console.log.apply(this, arguments);
17+
}
18+
19+

0 commit comments

Comments
 (0)