-
Notifications
You must be signed in to change notification settings - Fork 40
/
index.tsx
46 lines (40 loc) · 1.01 KB
/
index.tsx
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 { __ } from '@wordpress/i18n';
import { RichText } from '@wordpress/block-editor';
import { usePost } from '../../hooks';
interface PostExcerptProps {
/**
* The placeholder to show when no excerpt is set.
*/
placeholder?: string;
/**
* Remaining props to pass to the paragraph element.
*/
[key: string]: unknown;
}
export const PostExcerpt = ({
placeholder = __('Enter excerpt...', 'tenup'),
...rest
}: PostExcerptProps) => {
const { postId, postType, isEditable } = usePost();
const [rawExcerpt = '', setExcerpt, fullExcerpt] = useEntityProp(
'postType',
postType,
'excerpt',
postId as string,
);
if (!isEditable) {
// eslint-disable-next-line react/no-danger
return <p {...rest} dangerouslySetInnerHTML={{ __html: fullExcerpt?.rendered }} />;
}
return (
<RichText
tagName="p"
placeholder={placeholder}
value={rawExcerpt}
onChange={(value: string) => setExcerpt(value)}
allowedFormats={[]}
{...rest}
/>
);
};