-
Notifications
You must be signed in to change notification settings - Fork 64
/
index.js
43 lines (38 loc) · 1.17 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
'use strict';
/**
* WordPress dependencies
*/
import { registerPlugin } from '@wordpress/plugins';
import { PluginDocumentSettingPanel } from '@wordpress/edit-post';
import { useEffect } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import SubtitleEditor from './SubtitleEditor';
import { appendSubtitleToTitleDOMElement, connectWithSelect } from './utils';
/**
* Component to be used as a panel in the Document tab of the Editor.
*
* https://developer.wordpress.org/block-editor/developers/slotfills/plugin-document-setting-panel/
*/
const NewspackSubtitlePanel = ( { subtitle } ) => {
// Update the DOM when subtitle value changes
useEffect( () => {
appendSubtitleToTitleDOMElement( subtitle );
}, [ subtitle ] );
return (
<PluginDocumentSettingPanel
name="newspack-subtitle"
title={ __( 'Article Subtitle', 'newspack' ) }
className="newspack-subtitle"
>
{ __( 'Set a Subtitle for the Article', 'newspack' ) }
<SubtitleEditor />
</PluginDocumentSettingPanel>
);
};
registerPlugin( 'plugin-document-setting-panel-newspack-subtitle', {
render: connectWithSelect( NewspackSubtitlePanel ),
icon: null,
} );