-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
index.js
86 lines (78 loc) · 2.24 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
/**
* WordPress dependencies
*/
import { __, isRTL } from '@wordpress/i18n';
import { useSelect, useDispatch } from '@wordpress/data';
import { BlockIcon, store as blockEditorStore } from '@wordpress/block-editor';
import {
Button,
VisuallyHidden,
__experimentalHStack as HStack,
__experimentalText as Text,
} from '@wordpress/components';
import { layout, chevronLeftSmall, chevronRightSmall } from '@wordpress/icons';
import { store as commandsStore } from '@wordpress/commands';
import { displayShortcut } from '@wordpress/keycodes';
/**
* Internal dependencies
*/
import { store as editPostStore } from '../../../store';
function DocumentTitle() {
const { template, isEditing } = useSelect( ( select ) => {
const { isEditingTemplate, getEditedPostTemplate } =
select( editPostStore );
const _isEditing = isEditingTemplate();
return {
template: _isEditing ? getEditedPostTemplate() : null,
isEditing: _isEditing,
};
}, [] );
const { clearSelectedBlock } = useDispatch( blockEditorStore );
const { setIsEditingTemplate } = useDispatch( editPostStore );
const { open: openCommandCenter } = useDispatch( commandsStore );
if ( ! isEditing || ! template ) {
return null;
}
let templateTitle = __( 'Default' );
if ( template?.title ) {
templateTitle = template.title;
} else if ( !! template ) {
templateTitle = template.slug;
}
return (
<div className="edit-post-document-title">
<span className="edit-post-document-title__left">
<Button
onClick={ () => {
clearSelectedBlock();
setIsEditingTemplate( false );
} }
icon={ isRTL() ? chevronRightSmall : chevronLeftSmall }
>
{ __( 'Back' ) }
</Button>
</span>
<Button
className="edit-post-document-title__title"
onClick={ () => openCommandCenter() }
>
<HStack spacing={ 1 } justify="center">
<BlockIcon icon={ layout } />
<Text size="body" as="h1">
<VisuallyHidden as="span">
{ __( 'Editing template: ' ) }
</VisuallyHidden>
{ templateTitle }
</Text>
</HStack>
</Button>
<Button
className="edit-post-document-title__shortcut"
onClick={ () => openCommandCenter() }
>
{ displayShortcut.primary( 'k' ) }
</Button>
</div>
);
}
export default DocumentTitle;