-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
35 lines (29 loc) · 839 Bytes
/
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
import React, { ReactNode, useCallback } from 'react';
import { RichText } from '@wordpress/block-editor';
import { useDispatch, useSelect } from '@wordpress/data';
const REGEXP_NEWLINES = /[\r\n]+/g;
/**
* A rich-text input element that allows editing of the post title within a block.
*
* @param {object} props - Component props.
* @returns {ReactNode} Component.
*/
export default function PostTitleControl( props ) {
const { editPost } = useDispatch( 'core/editor' );
const value = useSelect(
( select ) => select( 'core/editor' ).getEditedPostAttribute( 'title' ),
[]
);
const onChange = useCallback(
( title ) => editPost( { title: title.replace( REGEXP_NEWLINES, ' ' ) } ),
[ editPost ]
);
return (
<RichText
{ ...props }
allowedFormats={ [] }
value={ value }
onChange={ onChange }
/>
);
}