-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
header.native.js
66 lines (60 loc) · 1.61 KB
/
header.native.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
/**
* WordPress dependencies
*/
import { memo } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { withDispatch, withSelect } from '@wordpress/data';
import { compose, withPreferredColorScheme } from '@wordpress/compose';
import { PostTitle } from '@wordpress/editor';
import { ReadableContentView } from '@wordpress/components';
import { store as blockEditorStore } from '@wordpress/block-editor';
/**
* Internal dependencies
*/
import styles from './style.scss';
const Header = memo(
function EditorHeader( {
editTitle,
setTitleRef,
title,
getStylesFromColorScheme,
} ) {
const blockHolderFocusedStyle = getStylesFromColorScheme(
styles.blockHolderFocused,
styles.blockHolderFocusedDark
);
return (
<ReadableContentView>
<PostTitle
innerRef={ setTitleRef }
title={ title }
onUpdate={ editTitle }
placeholder={ __( 'Add title' ) }
borderStyle={ styles.blockHolderFullBordered }
focusedBorderColor={ blockHolderFocusedStyle.borderColor }
accessibilityLabel="post-title"
/>
</ReadableContentView>
);
},
( prevProps, nextProps ) => prevProps.title === nextProps.title
);
export default compose( [
withSelect( ( select ) => {
const { getEditedPostAttribute } = select( 'core/editor' );
return {
title: getEditedPostAttribute( 'title' ),
};
} ),
withDispatch( ( dispatch ) => {
const { editPost } = dispatch( 'core/editor' );
const { clearSelectedBlock } = dispatch( blockEditorStore );
return {
clearSelectedBlock,
editTitle( title ) {
editPost( { title } );
},
};
} ),
withPreferredColorScheme,
] )( Header );