-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
72 lines (61 loc) · 1.3 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* WordPress dependencies
*/
import {
cloneElement,
createElement,
Component,
isValidElement,
} from '@wordpress/element';
import { SVG } from '@wordpress/primitives';
/**
* Internal dependencies
*/
import Dashicon from '../dashicon';
function Icon( { icon = null, size, ...additionalProps } ) {
// Dashicons should be 20x20 by default.
const dashiconSize = size || 20;
if ( 'string' === typeof icon ) {
return (
<Dashicon
icon={ icon }
size={ dashiconSize }
{ ...additionalProps }
/>
);
}
if ( icon && Dashicon === icon.type ) {
return cloneElement( icon, {
size: dashiconSize,
...additionalProps,
} );
}
// Icons should be 24x24 by default.
const iconSize = size || 24;
if ( 'function' === typeof icon ) {
if ( icon.prototype instanceof Component ) {
return createElement( icon, {
size: iconSize,
...additionalProps,
} );
}
return icon( { size: iconSize, ...additionalProps } );
}
if ( icon && ( icon.type === 'svg' || icon.type === SVG ) ) {
const appliedProps = {
width: iconSize,
height: iconSize,
...icon.props,
...additionalProps,
};
return <SVG { ...appliedProps } />;
}
if ( isValidElement( icon ) ) {
return cloneElement( icon, {
size: iconSize,
...additionalProps,
} );
}
return icon;
}
export default Icon;