-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
56 lines (49 loc) · 1.2 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
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { Icon } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { wordpress } from '@wordpress/icons';
import { store as coreDataStore } from '@wordpress/core-data';
function SiteIcon( { className } ) {
const { isRequestingSite, siteIconUrl } = useSelect( ( select ) => {
const { getEntityRecord, isResolving } = select( coreDataStore );
const siteData =
getEntityRecord( 'root', '__unstableBase', undefined ) || {};
return {
isRequestingSite: isResolving( 'core', 'getEntityRecord', [
'root',
'__unstableBase',
undefined,
] ),
siteIconUrl: siteData.site_icon_url,
};
}, [] );
if ( isRequestingSite && ! siteIconUrl ) {
return null;
}
const icon = siteIconUrl ? (
<img
className="edit-site-site-icon__image"
alt={ __( 'Site Icon' ) }
src={ siteIconUrl }
/>
) : (
<Icon
className="edit-site-site-icon__icon"
size="32px"
icon={ wordpress }
/>
);
return (
<div className={ classnames( className, 'edit-site-site-icon' ) }>
{ icon }
</div>
);
}
export default SiteIcon;