-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
index.js
52 lines (41 loc) · 1.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* WordPress dependencies
*/
import { cloneElement, createElement, Component, isValidElement } from '@wordpress/element';
/**
* Internal dependencies
*/
import { Dashicon, SVG } from '../';
function Icon( { icon = null, size, className } ) {
let iconSize;
if ( 'string' === typeof icon ) {
// Dashicons should be 20x20 by default
iconSize = size || 20;
return <Dashicon icon={ icon } size={ iconSize } className={ className } />;
}
// Any other icons should be 24x24 by default
iconSize = size || 24;
if ( 'function' === typeof icon ) {
if ( icon.prototype instanceof Component ) {
return createElement( icon, { className, size: iconSize } );
}
return icon();
}
if ( icon && ( icon.type === 'svg' || icon.type === SVG ) ) {
const appliedProps = {
className,
width: iconSize,
height: iconSize,
...icon.props,
};
return <SVG { ...appliedProps } />;
}
if ( isValidElement( icon ) ) {
return cloneElement( icon, {
className,
size: iconSize,
} );
}
return icon;
}
export default Icon;