-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
index.js
111 lines (98 loc) · 2.44 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* External dependencies
*/
import { get } from 'lodash';
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import {
Button,
Icon,
__unstableMotion as motion,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { addQueryArgs } from '@wordpress/url';
import { wordpress } from '@wordpress/icons';
import { store as editorStore } from '@wordpress/editor';
import { store as coreStore } from '@wordpress/core-data';
import { useReducedMotion } from '@wordpress/compose';
/**
* Internal dependencies
*/
import { store as editPostStore } from '../../../store';
function FullscreenModeClose( { showTooltip, icon, href } ) {
const { isActive, isRequestingSiteIcon, postType, siteIconUrl } = useSelect(
( select ) => {
const { getCurrentPostType } = select( editorStore );
const { isFeatureActive } = select( editPostStore );
const { getEntityRecord, getPostType, isResolving } = select(
coreStore
);
const siteData =
getEntityRecord( 'root', '__unstableBase', undefined ) || {};
return {
isActive: isFeatureActive( 'fullscreenMode' ),
isRequestingSiteIcon: isResolving( 'getEntityRecord', [
'root',
'__unstableBase',
undefined,
] ),
postType: getPostType( getCurrentPostType() ),
siteIconUrl: siteData.site_icon_url,
};
},
[]
);
const disableMotion = useReducedMotion();
if ( ! isActive || ! postType ) {
return null;
}
let buttonIcon = <Icon size="36px" icon={ wordpress } />;
const effect = {
expand: {
scale: 1.7,
borderRadius: 0,
transition: { type: 'tween', duration: '0.2' },
},
};
if ( siteIconUrl ) {
buttonIcon = (
<motion.img
variants={ ! disableMotion && effect }
alt={ __( 'Site Icon' ) }
className="edit-post-fullscreen-mode-close_site-icon"
src={ siteIconUrl }
/>
);
}
if ( isRequestingSiteIcon ) {
buttonIcon = null;
}
// Override default icon if custom icon is provided via props.
if ( icon ) {
buttonIcon = <Icon size="36px" icon={ icon } />;
}
return (
<motion.div whileHover="expand">
<Button
className="edit-post-fullscreen-mode-close has-icon"
href={
href ??
addQueryArgs( 'edit.php', {
post_type: postType.slug,
} )
}
label={ get(
postType,
[ 'labels', 'view_items' ],
__( 'Back' )
) }
showTooltip={ showTooltip }
>
{ buttonIcon }
</Button>
</motion.div>
);
}
export default FullscreenModeClose;