forked from 10up/block-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (39 loc) · 1.04 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
import { useEntityProp } from '@wordpress/core-data';
import { RichText, store as blockEditorStore } from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
import PropTypes from 'prop-types';
import { usePost } from '../../hooks';
export const PostTitle = (props) => {
const { tagName: TagName = 'h1', ...rest } = props;
const { postId, postType, isEditable } = usePost();
const [rawTitle = '', setTitle, fullTitle] = useEntityProp(
'postType',
postType,
'title',
postId,
);
const titlePlaceholder = useSelect(
(select) => select(blockEditorStore).getSettings().titlePlaceholder,
[],
);
if (!isEditable) {
// eslint-disable-next-line react/no-danger
return <TagName {...rest} dangerouslySetInnerHTML={{ __html: fullTitle?.rendered }} />;
}
return (
<RichText
tagName={TagName}
placeholder={titlePlaceholder}
value={rawTitle}
onChange={setTitle}
allowedFormats={[]}
{...rest}
/>
);
};
PostTitle.propTypes = {
tagName: PropTypes.string,
};
PostTitle.defaultProps = {
tagName: 'h1',
};